Skip to content

Commit

Permalink
Merge pull request #7396 from ever-co/stage
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
evereq authored Dec 27, 2023
2 parents 6475429 + d2978a3 commit 2c5fd3d
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 80 deletions.
14 changes: 7 additions & 7 deletions apps/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,11 @@ eventErrorManager.onShowError(async (message) => {
})

const runSetup = async () => {
if (setupWindow) {
setupWindow.show();
splashScreen.close();
return;
// Set default configuration
LocalStore.setDefaultServerConfig();
if (!setupWindow) {
setupWindow = await createSetupWindow(setupWindow, false, pathWindow.ui);
}
setupWindow = await createSetupWindow(setupWindow, false, pathWindow.ui);
setupWindow.show();
splashScreen.close();
};
Expand Down Expand Up @@ -682,7 +681,7 @@ ipcMain.on('minimize_on_startup', (event, arg) => {
launchAtStartup(arg.autoLaunch, arg.hidden);
});

ipcMain.on('auto_start_on_startup', (event, arg) => {
ipcMain.on('update_server_config', (event, arg) => {
serverConfig.setting = arg;
});

Expand Down Expand Up @@ -717,7 +716,8 @@ function launchAtStartup(autoLaunch: boolean, hidden: boolean): void {

ipcMain.on('save_encrypted_file', (event, value) => {
try {
const { secureProxy = { enable: false, ssl: { key: '', cert: '' } } } = serverConfig.setting || {};
const { secureProxy = { enable: false, secure: true, ssl: { key: '', cert: '' } } } =
serverConfig.setting || {};
const dialog = new DialogOpenFile(settingsWindow, 'ssl');
const filePath = dialog.save();
if (filePath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,33 @@ export class CloudinaryProvider extends Provider<CloudinaryProvider> {
...this.config
};

// Check if there is a current request
const request = RequestContext.currentRequest();

if (request) {
// Retrieve tenant settings from the request, defaulting to an empty object
const settings = request['tenantSettings'] || {};

// Check if there are non-empty tenant settings
if (isNotEmpty(settings)) {
// Update the configuration with trimmed and valid values from tenant settings
this.config = {
...this.config,
cloud_name: trimAndGetValue(settings.cloudinary_cloud_name),
api_key: trimAndGetValue(settings.cloudinary_api_key),
api_secret: trimAndGetValue(settings.cloudinary_api_secret),
secure: settings.cloudinary_api_secure,
...(isNotEmpty(settings.cloudinary_delivery_url)
? {
baseUrl: new URL(settings.cloudinary_delivery_url).toString()
}
: {})
};
try {
const request = RequestContext.currentRequest();

if (request) {
const settings = request['tenantSettings'];

if (settings) {
if (trimAndGetValue(settings.cloudinary_cloud_name))
this.config.cloud_name = trimAndGetValue(settings.cloudinary_cloud_name);

if (trimAndGetValue(settings.cloudinary_api_key))
this.config.api_key = trimAndGetValue(settings.cloudinary_api_key);

if (trimAndGetValue(settings.cloudinary_api_secret))
this.config.api_secret = trimAndGetValue(settings.cloudinary_api_secret);

if (isNotEmpty(settings.cloudinary_api_secure)) {
if (settings.cloudinary_api_secure == 'true') this.config.secure = true;
else if (settings.cloudinary_api_secure == 'false') this.config.secure = false;
}

if (isNotEmpty(settings.cloudinary_delivery_url))
this.config.baseUrl = new URL(settings.cloudinary_delivery_url).toString();
}
}
} catch (error) {
console.error('Error while setting Wasabi configuration. Default configuration will be used', error);
}
}

Expand Down
39 changes: 22 additions & 17 deletions packages/core/src/core/file-storage/providers/s3.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { FileStorageOption, FileStorageProviderEnum, UploadedFile } from '@gauzy
import { isNotEmpty, trimAndGetValue } from '@gauzy/common';
import { Provider } from './provider';
import { RequestContext } from '../../context';
import { th } from 'date-fns/locale';

/**
* Configuration interface for AWS S3 storage.
Expand Down Expand Up @@ -80,24 +81,28 @@ export class S3Provider extends Provider<S3Provider> {
...this.defaultConfig
};

// Check if there is a current request
const request = RequestContext.currentRequest();

if (request) {
// Retrieve tenant settings from the request, defaulting to an empty object
const settings = request['tenantSettings'] || {};

// Check if there are non-empty tenant settings
if (isNotEmpty(settings)) {
// Update the configuration with trimmed and valid values from tenant settings
this.config = {
...this.defaultConfig,
aws_access_key_id: trimAndGetValue(settings.aws_access_key_id),
aws_secret_access_key: trimAndGetValue(settings.aws_secret_access_key),
aws_default_region: trimAndGetValue(settings.aws_default_region),
aws_bucket: trimAndGetValue(settings.aws_bucket)
};
try {
const request = RequestContext.currentRequest();

if (request) {
const settings = request['tenantSettings'];

if (settings) {
if (trimAndGetValue(settings.aws_access_key_id))
this.config.aws_access_key_id = trimAndGetValue(settings.aws_access_key_id);

if (trimAndGetValue(settings.aws_secret_access_key))
this.config.aws_secret_access_key = trimAndGetValue(settings.aws_secret_access_key);

if (trimAndGetValue(settings.aws_default_region))
this.config.aws_default_region = trimAndGetValue(settings.aws_default_region);

if (trimAndGetValue(settings.aws_bucket))
this.config.aws_bucket = trimAndGetValue(settings.aws_bucket);
}
}
} catch (error) {
console.error('Error while setting S3 configuration. Default configuration will be used', error);
}
}

Expand Down
77 changes: 58 additions & 19 deletions packages/core/src/core/file-storage/providers/wasabi-s3.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,33 +131,72 @@ export class WasabiS3Provider extends Provider<WasabiS3Provider> {
}

/**
* Set Wasabi details based on the current request's tenantSettings
* Set Wasabi details based on the current request's tenantSettings.
* If such settings does not have any Wasabi details, use the default configuration.
* If they have Wasabi details, use them to override the default configuration.
*/
private setWasabiConfiguration() {
// Use the default configuration as a starting point
this.config = {
...this.defaultConfig
};

// Check if there is a current request
const request = RequestContext.currentRequest();

if (request) {
// Retrieve tenant settings from the request, defaulting to an empty object
const settings = request['tenantSettings'] || {};

// Check if there are non-empty tenant settings
if (isNotEmpty(settings)) {
// Update the configuration with trimmed and valid values from tenant settings
this.config = {
...this.defaultConfig,
wasabi_aws_access_key_id: trimAndGetValue(settings.wasabi_aws_access_key_id),
wasabi_aws_secret_access_key: trimAndGetValue(settings.wasabi_aws_secret_access_key),
wasabi_aws_service_url: addHttpsPrefix(trimAndGetValue(settings.wasabi_aws_service_url)),
wasabi_aws_default_region: trimAndGetValue(settings.wasabi_aws_default_region),
wasabi_aws_bucket: trimAndGetValue(settings.wasabi_aws_bucket)
};
console.log(`setWasabiConfiguration this.config value: ${JSON.stringify(this.config)}`);

try {
const request = RequestContext.currentRequest();

if (request) {
const settings = request['tenantSettings'];

console.log(`setWasabiConfiguration Tenant Settings value: ${JSON.stringify(settings)}`);

if (settings) {
if (trimAndGetValue(settings.wasabi_aws_access_key_id)) {
this.config.wasabi_aws_access_key_id = trimAndGetValue(settings.wasabi_aws_access_key_id);
console.log(
`setWasabiConfiguration this.config.wasabi_aws_access_key_id value: ${this.config.wasabi_aws_access_key_id}`
);
}

if (trimAndGetValue(settings.wasabi_aws_secret_access_key)) {
this.config.wasabi_aws_secret_access_key = trimAndGetValue(
settings.wasabi_aws_secret_access_key
);
console.log(
`setWasabiConfiguration this.config.wasabi_aws_secret_access_key value: ${this.config.wasabi_aws_secret_access_key}`
);
}

if (trimAndGetValue(settings.wasabi_aws_service_url)) {
this.config.wasabi_aws_service_url = addHttpsPrefix(
trimAndGetValue(settings.wasabi_aws_service_url)
);
console.log(
'setWasabiConfiguration this.config.wasabi_aws_service_url value: ',
this.config.wasabi_aws_service_url
);
}

if (trimAndGetValue(settings.wasabi_aws_default_region)) {
this.config.wasabi_aws_default_region = trimAndGetValue(settings.wasabi_aws_default_region);
console.log(
'setWasabiConfiguration this.config.wasabi_aws_default_region value: ',
this.config.wasabi_aws_default_region
);
}

if (trimAndGetValue(settings.wasabi_aws_bucket)) {
this.config.wasabi_aws_bucket = trimAndGetValue(settings.wasabi_aws_bucket);
console.log(
'setWasabiConfiguration this.config.wasabi_aws_bucket value: ',
this.config.wasabi_aws_bucket
);
}
}
}
} catch (error) {
console.error('Error while setting Wasabi configuration. Default configuration will be used', error);
}
}

Expand Down
16 changes: 15 additions & 1 deletion packages/desktop-libs/src/lib/desktop-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export const LocalStore = {
prerelease: false,
preferredLanguage: 'en',
zone: 'local',
autoStart: false,
alwaysOn: true,
enforced: false
};
Expand Down Expand Up @@ -208,5 +207,20 @@ export const LocalStore = {
store.set({
filePath: filePath
});
},

setDefaultServerConfig: () => {
const configs = {
autoStart: true,
secureProxy: {
secure: true,
enable: false,
ssl: {
key: '',
cert: ''
}
}
};
store.set({ configs });
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class ServerDashboardComponent implements OnInit, AfterViewInit {
'dashboard_ready',
(event, arg) => {
this._ngZone.run(() => {
if (!!arg.setting?.autoStart) {
if (!!arg.setting?.autoStart ?? true) {
this.runServer();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1301,16 +1301,16 @@ <h4>
</div>
<div *ngIf="isServer" class="col-6">
<nb-toggle
[(ngModel)]="autoStart"
[(ngModel)]="config.autoStart"
(ngModelChange)="
toggleAutoStartOnStartup(
$event
)
"
status="basic"
>{{
'TIMER_TRACKER.SETTINGS.AUTO_START_STARTUP'
| translate
>{{
'TIMER_TRACKER.SETTINGS.AUTO_START_STARTUP'
| translate
}}
</nb-toggle>
</div>
Expand Down
24 changes: 15 additions & 9 deletions packages/desktop-ui-lib/src/lib/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,10 @@ export class SettingsComponent implements OnInit, AfterViewInit {
key: '',
cert: ''
},
secure: false,
secure: true,
enable: false
}
},
autoStart: true
};
version = '0.0.0';
message = {
Expand All @@ -400,7 +401,6 @@ export class SettingsComponent implements OnInit, AfterViewInit {
progressDownload = 0;
showProgressBar = false;
autoLaunch = null;
autoStart = false;
minimizeOnStartup = null;
authSetting = null;
currentUser$: BehaviorSubject<any> = new BehaviorSubject(null);
Expand Down Expand Up @@ -560,7 +560,6 @@ export class SettingsComponent implements OnInit, AfterViewInit {
this.screenshotNotification = setting?.screenshotNotification;
this.muted = setting?.mutedNotification;
this.autoLaunch = setting?.autoLaunch;
this.autoStart = setting?.autoStart;
this.minimizeOnStartup = setting?.minimizeOnStartup;
this._automaticUpdate$.next(setting?.automaticUpdate);
this._automaticUpdateDelay$.next(setting?.automaticUpdateDelay);
Expand Down Expand Up @@ -862,10 +861,7 @@ export class SettingsComponent implements OnInit, AfterViewInit {
}

toggleAutoStartOnStartup(value: boolean) {
this.updateSetting(value, 'autoStart');
this.electronService.ipcRenderer.send('auto_start_on_startup', {
autoStart: value,
});
this.updateServerConfig(value, 'autoStart');
}

toggleAutomaticUpdate(value) {
Expand Down Expand Up @@ -1309,6 +1305,16 @@ export class SettingsComponent implements OnInit, AfterViewInit {
}

public updateSslSetting(value) {
this.updateSetting(value, 'secureProxy');
this.updateServerConfig(value, 'secureProxy');
}

public updateServerConfig(value, type: string, showNotification = true) {
this.config[type] = value;
this.electronService.ipcRenderer.send('update_server_config', this.config);
if (showNotification) {
this._notifier.success(
'Update ' + type.replace(/([a-z])([A-Z])/g, '$1 $2').toLowerCase() + ' setting successfully'
);
}
}
}

0 comments on commit 2c5fd3d

Please sign in to comment.