Skip to content

Commit

Permalink
Added branding handlers (#86)
Browse files Browse the repository at this point in the history
* Added branding handlers

* Changed getColorPalette connection to replica

* Moved json validator

* Revert "Moved json validator"

This reverts commit 805c60d.

* Added branding migration with branding not null

* Code review fixes

---------

Co-authored-by: Stanislav Kiselev <“[email protected]”>
  • Loading branch information
stankis and Stanislav Kiselev authored Mar 7, 2024
1 parent a2528f9 commit d7dc73d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/components/validation-schema-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
MAX_META_OBJECT_SYMBOLS,
MAX_UNVERSIONED_DATA_OBJECT_SYMBOLS,
MAX_PRESET_DATA_OBJECT_SYMBOLS,
MAX_BRANDING_OBJECT_SYMBOLS,
} from '../const';
import US_ERRORS from '../const/us-error-constants';
import {AppError} from '@gravity-ui/nodekit';
Expand Down Expand Up @@ -115,6 +116,30 @@ ajv.addKeyword('restrictMetaSize', {
errors: true,
});

ajv.addKeyword('restrictBrandingSize', {
validate: function validate(schema: object | string | boolean, data: any) {
if (data === null) {
return true;
} else {
const dataStringified = JSON.stringify(data);

// @ts-ignore
validate.errors = [
{
format: 'string',
message: `branding jsonb object can contain not greater ${MAX_BRANDING_OBJECT_SYMBOLS} symbols`,
params: {
keyword: 'restrictBrandingSize',
},
},
];

return dataStringified.length <= MAX_BRANDING_OBJECT_SYMBOLS;
}
},
errors: true,
});

ajv.addKeyword('restrictUnversionedDataSize', {
validate: function validate(schema: object | string | boolean, data: any) {
if (data === null) {
Expand Down
1 change: 1 addition & 0 deletions src/const/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export const CODING_BASE = '0123456789abcdefghijklmnopqrstuvwxyz'.split('');
export const MAX_META_OBJECT_SYMBOLS = 2000;
export const MAX_UNVERSIONED_DATA_OBJECT_SYMBOLS = 5000;
export const MAX_PRESET_DATA_OBJECT_SYMBOLS = 15000;
export const MAX_BRANDING_OBJECT_SYMBOLS = 15000;

export const AJV_PATTERN_KEYS_NOT_OBJECT = {
'.*': {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type {Knex} from 'knex';

exports.up = function (knex: Knex): Promise<unknown> {
return knex.raw(`
ALTER TABLE tenants ALTER COLUMN branding SET NOT NULL;
`);
};

exports.down = function (knex: Knex): Promise<unknown> {
return knex.raw(`
ALTER TABLE tenants ALTER COLUMN branding DROP NOT NULL;
`);
};
1 change: 1 addition & 0 deletions src/db/models/new/entry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const EntryColumn = {
UnversionedData: 'unversionedData',
WorkbookId: 'workbookId',
Mirrored: 'mirrored',
Branding: 'branding',
} as const;

export class Entry extends Model {
Expand Down
2 changes: 2 additions & 0 deletions src/db/models/new/tenant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const TenantColumn = {
BillingAccountId: 'billingAccountId',
BillingInstanceServiceId: 'billingInstanceServiceId',
BillingStartedAt: 'billingStartedAt',
Branding: 'branding',
} as const;

export class Tenant extends Model {
Expand All @@ -39,6 +40,7 @@ export class Tenant extends Model {
[TenantColumn.BillingAccountId]!: Nullable<string>;
[TenantColumn.BillingInstanceServiceId]!: Nullable<string>;
[TenantColumn.BillingStartedAt]!: Nullable<string>;
[TenantColumn.Branding]!: Record<string, unknown>;
}

export {BillingRate};
2 changes: 2 additions & 0 deletions src/db/presentations/joined-migration-tenant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const selectedTenantColumns = [
TenantColumn.BillingAccountId,
TenantColumn.BillingInstanceServiceId,
TenantColumn.BillingStartedAt,
TenantColumn.Branding,
] as const;

const selectedMigrationTenantColumns = [
Expand Down Expand Up @@ -44,6 +45,7 @@ export const JoinedMigrationTenantColumn = {
ToId: MigrationTenantColumn.ToId,
Migrating: MigrationTenantColumn.Migrating,
MigrationMeta: MigrationTenantColumn.MigrationMeta,
Branding: TenantColumn.Branding,
} as const;

export const selectedJoinedMigrationTenantColumns = [
Expand Down
2 changes: 1 addition & 1 deletion src/services/color-palettes/get-color-palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const getColorPalette = async (
colorPaletteId,
});

const colorPalette = await ColorPaletteModel.query(ColorPaletteModel.primary)
const colorPalette = await ColorPaletteModel.query(ColorPaletteModel.replica)
.select()
.where({
[ColorPaletteModelColumn.ColorPaletteId]: colorPaletteId,
Expand Down

0 comments on commit d7dc73d

Please sign in to comment.