Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-3703 save product configuration from ui #2334

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -992,11 +992,10 @@
sessionExpireTime,
appConfig);
validateConfiguration(configurationProperties);
writeRuntimeConfig(configurationProperties);
writeRuntimeConfig(getRuntimeAppConfigFile(), configurationProperties);
}

private void writeRuntimeConfig(Map<String, Object> configurationProperties) throws DBException {
File runtimeConfigFile = getRuntimeAppConfigFile();
private void writeRuntimeConfig(File runtimeConfigFile, Map<String, Object> configurationProperties) throws DBException {
if (runtimeConfigFile.exists()) {
ContentUtils.makeFileBackup(runtimeConfigFile.toPath());
}
Expand Down Expand Up @@ -1024,33 +1023,7 @@
var serverConfigProperties = new LinkedHashMap<String, Object>();
var originServerConfig = getServerConfigProps(this.originalConfigurationProperties); // get server properties from original configuration file
rootConfig.put("server", serverConfigProperties);
if (!CommonUtils.isEmpty(newServerName)) {
copyConfigValue(originServerConfig,
serverConfigProperties,
CBConstants.PARAM_SERVER_NAME,
newServerName);
}
if (!CommonUtils.isEmpty(newServerURL)) {
copyConfigValue(
originServerConfig, serverConfigProperties, CBConstants.PARAM_SERVER_URL, newServerURL);
}
if (sessionExpireTime > 0) {
copyConfigValue(
originServerConfig,
serverConfigProperties,
CBConstants.PARAM_SESSION_EXPIRE_PERIOD,
sessionExpireTime);
}
var databaseConfigProperties = new LinkedHashMap<String, Object>();
Map<String, Object> oldRuntimeDBConfig = JSONUtils.getObject(originServerConfig,
CBConstants.PARAM_DB_CONFIGURATION);
if (!CommonUtils.isEmpty(databaseConfiguration) && !isDistributed()) {
for (Map.Entry<String, Object> mp : databaseConfiguration.entrySet()) {
copyConfigValue(oldRuntimeDBConfig, databaseConfigProperties, mp.getKey(), mp.getValue());
}
serverConfigProperties.put(CBConstants.PARAM_DB_CONFIGURATION, databaseConfigProperties);
}
savePasswordPolicyConfig(originServerConfig, serverConfigProperties);
collectServerConfigProperties(newServerName, newServerURL, sessionExpireTime, originServerConfig, serverConfigProperties);
}
{
var appConfigProperties = new LinkedHashMap<String, Object>();
Expand Down Expand Up @@ -1160,7 +1133,43 @@
return rootConfig;
}

private void savePasswordPolicyConfig(Map<String, Object> originServerConfig, LinkedHashMap<String, Object> serverConfigProperties) {
protected void collectServerConfigProperties(
String newServerName,
String newServerURL,
long sessionExpireTime,
Map<String, Object> originServerConfig,
Map<String, Object> serverConfigProperties
) {
if (!CommonUtils.isEmpty(newServerName)) {
copyConfigValue(originServerConfig,
serverConfigProperties,
CBConstants.PARAM_SERVER_NAME,
newServerName);
}
if (!CommonUtils.isEmpty(newServerURL)) {
copyConfigValue(
originServerConfig, serverConfigProperties, CBConstants.PARAM_SERVER_URL, newServerURL);
}
if (sessionExpireTime > 0) {
copyConfigValue(
originServerConfig,
serverConfigProperties,
CBConstants.PARAM_SESSION_EXPIRE_PERIOD,
sessionExpireTime);
}
var databaseConfigProperties = new LinkedHashMap<String, Object>();
Map<String, Object> oldRuntimeDBConfig = JSONUtils.getObject(originServerConfig,
CBConstants.PARAM_DB_CONFIGURATION);
if (!CommonUtils.isEmpty(databaseConfiguration) && !isDistributed()) {
for (Map.Entry<String, Object> mp : databaseConfiguration.entrySet()) {
copyConfigValue(oldRuntimeDBConfig, databaseConfigProperties, mp.getKey(), mp.getValue());
}
serverConfigProperties.put(CBConstants.PARAM_DB_CONFIGURATION, databaseConfigProperties);
}
savePasswordPolicyConfig(originServerConfig, serverConfigProperties);
}

private void savePasswordPolicyConfig(Map<String, Object> originServerConfig, Map<String, Object> serverConfigProperties) {
// save password policy configuration
var passwordPolicyProperties = new LinkedHashMap<String, Object>();

Expand Down Expand Up @@ -1297,4 +1306,10 @@
public Class<? extends DBPPlatformUI> getPlatformUIClass() {
return CBPlatformUI.class;
}

public void saveProductConfiguration(SMCredentialsProvider credentialsProvider, Map<String, Object> productConfiguration) throws DBException {

Check warning on line 1310 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java#L1310

Line is longer than 140 characters (found 146).

Check warning on line 1310 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java#L1310

Missing a Javadoc comment.
Map<String, Object> mergedConfig = WebAppUtils.mergeConfigurations(this.productConfiguration, productConfiguration);
writeRuntimeConfig(getRuntimeProductConfigFilePath().toFile(), mergedConfig);
this.productConfiguration.putAll(mergedConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,8 @@ extend type Query {
setDefaultNavigatorSettings( settings: NavigatorSettingsInput!): Boolean!

}

extend type Mutation {
# Updates product configuration
adminUpdateProductConfiguration(configuration: Object!): Boolean! @since(version: "23.3.4")
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@
@WebAction(requirePermissions = DBWConstants.PERMISSION_ADMIN)
boolean setDefaultNavigatorSettings(WebSession webSession, DBNBrowseSettings settings) throws DBWebException;

@WebAction(requirePermissions = DBWConstants.PERMISSION_ADMIN)

Check warning on line 141 in server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/DBWServiceAdmin.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/DBWServiceAdmin.java#L141

Missing a Javadoc comment.
boolean updateProductConfiguration(WebSession webSession, Map<String, Object> productConfiguration) throws DBWebException;

////////////////////////////////////////////////////////////////////
// Permissions

Expand Down Expand Up @@ -179,6 +182,7 @@
DBWebException;

////////////////////////////////////////////////////////////////////

// User meta parameters

@WebAction(requirePermissions = DBWConstants.PERMISSION_ADMIN)
Expand All @@ -187,11 +191,11 @@

@WebAction(requirePermissions = DBWConstants.PERMISSION_ADMIN)
Boolean deleteUserMetaParameter(WebSession webSession, String id) throws DBWebException;

@WebAction(requirePermissions = DBWConstants.PERMISSION_ADMIN)
Boolean setUserMetaParameterValues(WebSession webSession, String userId, Map<String, String> parameters) throws DBWebException;
@WebAction(requirePermissions = DBWConstants.PERMISSION_ADMIN)
Boolean setTeamMetaParameterValues(WebSession webSession, String teamId, Map<String, String> parameters) throws DBWebException;

@WebAction(requirePermissions = DBWConstants.PERMISSION_ADMIN)
Boolean enableUser(WebSession webSession, String userId, Boolean enabled) throws DBWebException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ public void bindWiring(DBWBindingContext model) throws DBWebException {
.dataFetcher("setDefaultNavigatorSettings",
env -> getService(env).setDefaultNavigatorSettings(getWebSession(env), WebServiceUtils.parseNavigatorSettings(env.getArgument("settings"))))
;
model.getMutationType()
.dataFetcher("adminUpdateProductConfiguration",
env -> getService(env).updateProductConfiguration(getWebSession(env), env.getArgument("configuration")));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,17 @@ public boolean setDefaultNavigatorSettings(WebSession webSession, DBNBrowseSetti
return true;
}


@Override
public boolean updateProductConfiguration(WebSession webSession, Map<String, Object> productConfiguration) throws DBWebException {
try {
CBApplication.getInstance().saveProductConfiguration(webSession, productConfiguration);
return true;
} catch (DBException e) {
throw new DBWebException("Error updating product configuration", e);
}
}

////////////////////////////////////////////////////////////////////
// Access management

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { NotificationService } from '@cloudbeaver/core-events';
import { Executor, IExecutor } from '@cloudbeaver/core-executor';
import { EAdminPermission, PermissionsService, ServerConfigResource, SessionPermissionsResource } from '@cloudbeaver/core-root';
import { RouterState, ScreenService } from '@cloudbeaver/core-routing';
import { LocalStorageSaveService } from '@cloudbeaver/core-settings';
import { SettingsService } from '@cloudbeaver/core-settings';
import { GlobalConstants } from '@cloudbeaver/core-utils';

import { AdministrationItemService } from '../AdministrationItem/AdministrationItemService';
Expand Down Expand Up @@ -69,7 +69,7 @@ export class AdministrationScreenService {
private readonly permissionsService: PermissionsService,
private readonly screenService: ScreenService,
private readonly administrationItemService: AdministrationItemService,
private readonly autoSaveService: LocalStorageSaveService,
private readonly settingsService: SettingsService,
private readonly serverConfigResource: ServerConfigResource,
private readonly notificationService: NotificationService,
) {
Expand All @@ -84,8 +84,8 @@ export class AdministrationScreenService {
activeScreen: computed,
});

this.autoSaveService.withAutoSave(ADMINISTRATION_ITEMS_STATE, this.itemState, () => new Map());
this.autoSaveService.withAutoSave(ADMINISTRATION_INFO, this.info, getDefaultAdministrationScreenInfo);
this.settingsService.registerSettings(ADMINISTRATION_ITEMS_STATE, this.itemState, () => new Map());
this.settingsService.registerSettings(ADMINISTRATION_INFO, this.info, getDefaultAdministrationScreenInfo);
this.permissionsResource.onDataUpdate.addPostHandler(() => {
this.checkPermissions(this.screenService.routerService.state);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
*/
import { injectable } from '@cloudbeaver/core-di';
import { PluginManagerService, PluginSettings } from '@cloudbeaver/core-plugin';
import { schema } from '@cloudbeaver/core-utils';

const defaultSettings = {
baseFeatures: [] as string[],
};
const settingsSchema = schema.object({
baseFeatures: schema.array(schema.string()).default([]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use array of enums? so it is more typescript friendly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

features is extendable entity, so we can't declare all possible values

});

export type AdministrationSettings = typeof defaultSettings;
export type AdministrationSettings = schema.infer<typeof settingsSchema>;

@injectable()
export class AdministrationSettingsService {
readonly settings: PluginSettings<AdministrationSettings>;
readonly settings: PluginSettings<typeof settingsSchema>;

constructor(private readonly pluginManagerService: PluginManagerService) {
this.settings = this.pluginManagerService.createSettings('administration', 'core', defaultSettings);
this.settings = this.pluginManagerService.createSettings('administration', 'core', settingsSchema);
}

isBase(feature: string): boolean {
Expand Down
40 changes: 20 additions & 20 deletions webapp/packages/core-administration/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"tsBuildInfoFile": "dist/tsconfig.tsbuildinfo"
},
"references": [
{
"path": "../core-browser/tsconfig.json"
},
{
"path": "../core-data-context/tsconfig.json"
},
Expand All @@ -16,58 +19,55 @@
"path": "../core-events/tsconfig.json"
},
{
"path": "../core-executor/tsconfig.json"
},
{
"path": "../core-localization/tsconfig.json"
"path": "../core-events/tsconfig.json"
},
{
"path": "../core-plugin/tsconfig.json"
"path": "../core-executor/tsconfig.json"
},
{
"path": "../core-resource/tsconfig.json"
"path": "../core-localization/tsconfig.json"
},
{
"path": "../core-root/tsconfig.json"
"path": "../core-localization/tsconfig.json"
},
{
"path": "../core-routing/tsconfig.json"
"path": "../core-plugin/tsconfig.json"
},
{
"path": "../core-sdk/tsconfig.json"
"path": "../core-plugin/tsconfig.json"
},
{
"path": "../core-settings/tsconfig.json"
"path": "../core-product/tsconfig.json"
},
{
"path": "../core-theming/tsconfig.json"
"path": "../core-resource/tsconfig.json"
},
{
"path": "../core-utils/tsconfig.json"
"path": "../core-root/tsconfig.json"
},
{
"path": "../core-browser/tsconfig.json"
"path": "../core-root/tsconfig.json"
},
{
"path": "../core-events/tsconfig.json"
"path": "../core-routing/tsconfig.json"
},
{
"path": "../core-localization/tsconfig.json"
"path": "../core-sdk/tsconfig.json"
},
{
"path": "../core-plugin/tsconfig.json"
"path": "../core-sdk/tsconfig.json"
},
{
"path": "../core-product/tsconfig.json"
"path": "../core-settings/tsconfig.json"
},
{
"path": "../core-root/tsconfig.json"
"path": "../core-settings/tsconfig.json"
},
{
"path": "../core-sdk/tsconfig.json"
"path": "../core-theming/tsconfig.json"
},
{
"path": "../core-settings/tsconfig.json"
"path": "../core-utils/tsconfig.json"
},
{
"path": "../tests-runner/tsconfig.json"
Expand Down
5 changes: 2 additions & 3 deletions webapp/packages/core-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@
"@cloudbeaver/core-executor": "~0.1.0",
"@cloudbeaver/core-localization": "~0.1.0",
"@cloudbeaver/core-notifications": "~0.1.0",
"@cloudbeaver/core-plugin": "~0.1.0",
"@cloudbeaver/core-projects": "~0.1.0",
"@cloudbeaver/core-resource": "~0.1.0",
"@cloudbeaver/core-root": "~0.1.0",
"@cloudbeaver/core-routing": "~0.1.0",
"@cloudbeaver/core-theming": "~0.1.0",
"@cloudbeaver/core-ui": "~0.1.0",
"@cloudbeaver/core-utils": "~0.1.0",
"@cloudbeaver/core-version": "~0.1.0",
"mobx-react-lite": "^4.0.5",
"react": "^18.2.0",
"@cloudbeaver/core-utils": "~0.1.0"
"react": "^18.2.0"
},
"peerDependencies": {},
"devDependencies": {
Expand Down
33 changes: 0 additions & 33 deletions webapp/packages/core-app/src/CoreSettingsService.ts

This file was deleted.

1 change: 0 additions & 1 deletion webapp/packages/core-app/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Services
export * from './CoreSettingsService';
export * from './AppScreen/AppScreenService';
export * from './AppScreen/AppScreenBootstrap';

Expand Down
3 changes: 1 addition & 2 deletions webapp/packages/core-app/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import type { PluginManifest } from '@cloudbeaver/core-di';
import { AppLocaleService } from './AppLocaleService';
import { AppScreenBootstrap } from './AppScreen/AppScreenBootstrap';
import { AppScreenService } from './AppScreen/AppScreenService';
import { CoreSettingsService } from './CoreSettingsService';

export const coreAppManifest: PluginManifest = {
info: {
name: 'Core App',
},

providers: [AppScreenService, AppScreenBootstrap, CoreSettingsService, AppLocaleService],
providers: [AppScreenService, AppScreenBootstrap, AppLocaleService],
};
Loading
Loading