Skip to content

Commit

Permalink
few constant use instead of plainstring
Browse files Browse the repository at this point in the history
  • Loading branch information
Tcharl committed Aug 28, 2024
1 parent 0d764fc commit 2e5d5f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 8 additions & 4 deletions generators/bootstrap-application-base/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
prepareRelationship,
stringifyApplicationData,
} from '../base-application/support/index.js';
import { applicationTypes, authenticationTypes, databaseTypes } from '../../jdl/jhipster/index.js';
import { JAVA_DOCKER_DIR } from '../generator-constants.js';
import { GENERATOR_BOOTSTRAP, GENERATOR_COMMON, GENERATOR_PROJECT_NAME } from '../generator-list.js';
import { packageJson } from '../../lib/index.js';
Expand All @@ -41,6 +42,9 @@ import { loadAppConfig, loadDerivedAppConfig, loadStoredAppOptions } from '../ap
import { createAuthorityEntity, createUserEntity, createUserManagementEntity } from './utils.js';
import { exportJDLTransform, importJDLTransform } from './support/index.js';

const { OAUTH2 } = authenticationTypes;
const { GATEWAY } = applicationTypes;
const { NO: NO_DATABASE, CASSANDRA } = databaseTypes;
const isWin32 = os.platform() === 'win32';

export default class BootstrapApplicationBase extends BaseApplicationGenerator {
Expand Down Expand Up @@ -178,21 +182,21 @@ export default class BootstrapApplicationBase extends BaseApplicationGenerator {
syncUserWithIdp({ application, applicationDefaults }) {
if (!application.backendTypeSpringBoot) return;

if (application.syncUserWithIdp === undefined && application.authenticationType === 'oauth2') {
if (application.syncUserWithIdp === undefined && application.authenticationType === OAUTH2) {
applicationDefaults({
__override__: false,
syncUserWithIdp: data =>
data.databaseType !== 'no' && (data.applicationType === 'gateway' || data.anyEntityHasRelationshipWithUser),
data.databaseType !== NO_DATABASE && (data.applicationType === GATEWAY || data.anyEntityHasRelationshipWithUser),
});
} else if (application.syncUserWithIdp && application.authenticationType !== 'oauth2') {
} else if (application.syncUserWithIdp && application.authenticationType !== OAUTH2) {
throw new Error('syncUserWithIdp is only supported with oauth2 authenticationType');
}
},
userManagement({ applicationDefaults }) {
applicationDefaults({
generateBuiltInUserEntity: ({ generateUserManagement, syncUserWithIdp }) => generateUserManagement || syncUserWithIdp,
generateBuiltInAuthorityEntity: ({ generateBuiltInUserEntity, databaseType }) =>
generateBuiltInUserEntity && databaseType !== 'cassandra',
generateBuiltInUserEntity && databaseType !== CASSANDRA,
});
},
});
Expand Down
6 changes: 4 additions & 2 deletions generators/bootstrap-application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import assert from 'assert';

import BaseApplicationGenerator from '../base-application/index.js';
import { validations } from '../../jdl/jhipster/index.js';
import { authenticationTypes, databaseTypes, validations } from '../../jdl/jhipster/index.js';
import {
derivedPrimaryKeyProperties,
preparePostEntitiesCommonDerivedProperties,
Expand All @@ -31,6 +31,8 @@ import { preparePostEntityServerDerivedProperties } from '../server/support/inde
import { loadStoredAppOptions } from '../app/support/index.js';
import { JHIPSTER_DOCUMENTATION_ARCHIVE_PATH, JHIPSTER_DOCUMENTATION_URL } from '../generator-constants.js';

const { OAUTH2 } = authenticationTypes;
const { NO: NO_DATABASE } = databaseTypes;
const {
Validations: { MAX, MIN, MAXLENGTH, MINLENGTH, MAXBYTES, MINBYTES, PATTERN },
SUPPORTED_VALIDATION_RULES,
Expand Down Expand Up @@ -61,7 +63,7 @@ export default class BootstrapApplicationGenerator extends BaseApplicationGenera
get preparing() {
return this.asPreparingTaskGroup({
preparing({ application, applicationDefaults }) {
if (application.authenticationType === 'oauth2' || application.databaseType === 'no') {
if (application.authenticationType === OAUTH2 || application.databaseType === NO_DATABASE) {
(application as any).skipUserManagement = true;
}

Expand Down

0 comments on commit 2e5d5f1

Please sign in to comment.