Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dev/env/opensource/development.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ ZITADEL_COOKIE_SECRET=!@OUVOF$@E@%F^&@$*ER!F

SERVICE_CLIENT_ID=charts
SERVICE_CLIENT_SECRET=uvdZDsiZJslDj8bKbTlKR43oMHqEiNGppxhMjCQWqQXkHUmGpW2iuLYNJ5tdmmlL

US_MASTER_TOKEN=us-master-token
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export const getWizardChartBuilder = async (
const defaultColorPaletteId = getDefaultColorPaletteId({
ctx: app.nodekit.ctx,
tenantSettings,
palettes,
});

// Nothing happens here - just for compatibility with the editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {createFeatureConfig} from '../utils';
export default createFeatureConfig({
name: Feature.EnableTenantSettingPalettes,
state: {
development: false,
production: false,
development: true,
production: true,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {createFeatureConfig} from '../utils';
export default createFeatureConfig({
name: Feature.NewDefaultPalette,
state: {
development: false,
production: false,
development: true,
production: true,
},
});
13 changes: 12 additions & 1 deletion src/server/components/layout/opensource-layout-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import type {RenderParams} from '@gravity-ui/app-layout';

import type {AppEnvironment, AppInstallation, DLGlobalData, DLUser} from '../../../shared';
import type {
AppEnvironment,
AppInstallation,
DLGlobalData,
DLUser,
TenantSettings,
} from '../../../shared';
import {FALLBACK_LANGUAGES, Feature, Language, USER_SETTINGS_KEY} from '../../../shared';
import type {AppLayoutSettings, GetLayoutConfig} from '../../types/app-layout';
import {addTranslationsScript} from '../../utils/language';
Expand Down Expand Up @@ -71,6 +77,10 @@ export const getOpensourceLayoutConfig: GetLayoutConfig = async (args) => {
// applying new favicon from rebranding
const faviconUrl = isRebrandingEnabled ? '/os-favicon.ico' : config.faviconUrl;

const tenantSettings: TenantSettings = {
defaultColorPaletteId: res.locals.tenantDefaultColorPaletteId,
};

const DL: DLGlobalData = {
user,
userSettings,
Expand All @@ -96,6 +106,7 @@ export const getOpensourceLayoutConfig: GetLayoutConfig = async (args) => {
docsUrl: config.docsUrl,
orderedAuthRoles: config.orderedAuthRoles,
authSignupDisabled: req.ctx.config.authSignupDisabled,
tenantSettings,
...appLayoutSettings.DL,
};
const renderConfig: RenderParams<{DL: DLGlobalData}> = {
Expand Down
44 changes: 44 additions & 0 deletions src/server/middlewares/tenant-settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type {NextFunction, Request, Response} from '@gravity-ui/expresskit';
import {REQUEST_ID_PARAM_NAME} from '@gravity-ui/nodekit';

import {onFail} from '../callbacks';
import {registry} from '../registry';
import type {DatalensGatewaySchemas} from '../types/gateway';

export function getTenantSettingsMiddleware() {
async function resolveTenantSettings(req: Request, res: Response, next: NextFunction) {
const {ctx} = req;

const requestId = req.ctx.get(REQUEST_ID_PARAM_NAME);
const currentTenantId = 'common';

const {gatewayApi} = registry.getGatewayApi<DatalensGatewaySchemas>();
const {getAuthArgsUSPrivate} = registry.common.auth.getAll();
const authArgsUSPrivate = getAuthArgsUSPrivate(req, res);

const tenantDetailsResponce = await gatewayApi.usPrivate._getTenantDetails({
ctx,
headers: req.headers,
requestId: requestId ?? '',
authArgs: authArgsUSPrivate,
args: {tenantId: currentTenantId},
});
const resolvedTenant = tenantDetailsResponce.responseData;
res.locals.tenantDefaultColorPaletteId = resolvedTenant.settings?.defaultColorPaletteId;

next();
}

return function resolveTenantSettingsMiddleware(
req: Request,
res: Response,
next: NextFunction,
) {
resolveTenantSettings(req, res, next)
.catch((error) => {
req.ctx.logError('TENANT_RESOLVED_FAILED', error);
onFail(req, res);
})
.catch((error) => next(error));
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const getChartColorsConfig = ({
const fallbackColors = selectServerPalette({
palette: colorsConfig.palette,
availablePalettes,
customColorPalettes: loadedColorPalettes,
defaultColorPaletteId,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function prepareD3Pie(args: PrepareFunctionArgs) {
return {
...item,
value: item.y,
color: String(item.color),
color: item.color,
formattedValue: getFormattedValue(String(item.y), {
...measure,
data_type: idToDataType[measure.guid],
Expand Down
2 changes: 2 additions & 0 deletions src/server/modes/opensource/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {getZitadelRoutes} from '../../components/zitadel/routes';
import {ping} from '../../controllers/ping';
import {workbooksTransferController} from '../../controllers/workbook-transfer';
import {getConnectorIconsMiddleware} from '../../middlewares';
import {getTenantSettingsMiddleware} from '../../middlewares/tenant-settings';
import type {ExtendedAppRouteDescription} from '../../types/controllers';
import {getConfiguredRoute} from '../../utils/routes';
import {applyPluginRoutes} from '../charts/init-charts-engine';
Expand Down Expand Up @@ -119,6 +120,7 @@ function getDataLensRoutes({
authArgs: getAuthArgs(req, res),
}),
}),
getTenantSettingsMiddleware(),
],
ui: true,
};
Expand Down
2 changes: 2 additions & 0 deletions src/shared/schema/us-private/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {entriesActions} from './entries';
import {tenantActions} from './tenant';

export const actions = {
...entriesActions,
...tenantActions,
};
14 changes: 14 additions & 0 deletions src/shared/schema/us-private/actions/tenant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {createAction} from '../../gateway-utils';
import type {GetTenantDetailsArgs, GetTenantDetailsResponse} from '../../us/types';

const PRIVATE_PATH_PREFIX = '/private';

export const tenantActions = {
_getTenantDetails: createAction<GetTenantDetailsResponse, GetTenantDetailsArgs>({
method: 'GET',
path: ({tenantId}) => `${PRIVATE_PATH_PREFIX}/tenants/${tenantId}/details`,
params: (_, headers) => ({
headers,
}),
}),
};
8 changes: 5 additions & 3 deletions src/shared/schema/us/types/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,14 @@ export interface EntryRelationFields {
isLocked: boolean;
}

export interface TenantSettings {
defaultColorPaletteId?: string;
}

export interface TenantFields {
tenantId: string;
createdAt: string;
enabled: boolean;
deleting: boolean;
settings: {
defaultColorPaletteId?: string;
};
settings: TenantSettings;
}
15 changes: 14 additions & 1 deletion src/shared/schema/us/types/tenant.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import type {TenantFields} from './fields';
import type {TenantFields, TenantSettings} from './fields';

export type SetDefaultColorPaletteArgs = {
defaultColorPaletteId: string;
};

export type SetDefaultColorPaletteResponse = TenantFields;

export type GetTenantDetailsArgs = {
tenantId: string;
};

export type GetTenantDetailsResponse = TenantFields;

export type ChangeTenantSettingArgs = {
key: keyof TenantSettings;
value: TenantSettings[keyof TenantSettings];
};

export type ChangeTenantSettingResponse = TenantFields;
4 changes: 3 additions & 1 deletion tests/docker-compose.e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ services:
BI_COMPENG_PG_ON: 1
BI_COMPENG_PG_URL: postgresql://pg-user:postgres@postgres:5432/pg-compeng-db
US_HOST: http://us:8080
US_MASTER_TOKEN: ${US_MASTER_TOKEN:-us-master-token}
US_MASTER_TOKEN: us-master-token
AUTH__TYPE: ${AUTH_TYPE:-NATIVE}
AUTH__JWT_ALGORITHM: 'PS256'
AUTH__JWT_KEY: -----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA+HICDZMfimMIiGdd0dPr\n2N3zxHOJqiVXuvUj/aBBS7c8760rJUh4344sP/0Gid558yH/v1MtzZ0R9w09v6gb\nSNrSiNwIUNGPhbnm9Jf+kMezsI/rkcIdoVm3KJ8CFUYy6MRPzW7iJmIVRHBb82v1\nmAYCCQFU6IRtFIa9hQ8wedWwxqXZekSNS+6NB37dmmQB9kz2E3MY+KRLigOh4i3p\nCZ1ti3HVvMa9Rlgk9FmoWExzub5ECChqwm+vn8yFXjYW7kUSClcV2xx4nbQWqjrR\nyyLk6W2BNOuCFVvz0j+5XkpLAt7tljtVZc+572HBEKpF2mAdmAip5NzeDhKqucJ+\nZQIDAQAB\n-----END PUBLIC KEY-----
Expand Down Expand Up @@ -114,6 +114,7 @@ services:
environment:
APP_MODE: full
APP_ENV: production
US_MASTER_TOKEN: us-master-token
APP_INSTALLATION: opensource
AUTH_POLICY: disabled
US_ENDPOINT: http://us:8080
Expand All @@ -140,6 +141,7 @@ services:
environment:
APP_MODE: full
APP_ENV: production
US_MASTER_TOKEN: us-master-token
APP_INSTALLATION: opensource
AUTH_POLICY: disabled
US_ENDPOINT: http://us:8080
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ datalensTest.describe('Wizard', () => {

// set color by fake title
await wizardPage.colorDialog.open();
await wizardPage.colorDialog.selectColor('#FF7E00');
await wizardPage.colorDialog.selectColor('#FF8C00');
await wizardPage.colorDialog.apply();

await expect(previewLoader).not.toBeVisible();
Expand Down
Loading