1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-05-12 01:17:04 +02:00

skip change request (#2598)

This commit is contained in:
Mateusz Kwasniewski 2022-12-05 15:38:17 +01:00 committed by GitHub
parent fd32c80201
commit e059b755c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 11 deletions

View File

@ -35,3 +35,4 @@ export const UPDATE_SEGMENT = 'UPDATE_SEGMENT';
export const DELETE_SEGMENT = 'DELETE_SEGMENT'; export const DELETE_SEGMENT = 'DELETE_SEGMENT';
export const APPLY_CHANGE_REQUEST = 'APPLY_CHANGE_REQUEST'; export const APPLY_CHANGE_REQUEST = 'APPLY_CHANGE_REQUEST';
export const APPROVE_CHANGE_REQUEST = 'APPROVE_CHANGE_REQUEST'; export const APPROVE_CHANGE_REQUEST = 'APPROVE_CHANGE_REQUEST';
export const SKIP_CHANGE_REQUEST = 'SKIP_CHANGE_REQUEST';

View File

@ -273,6 +273,7 @@ class FeatureController extends Controller {
environment: DEFAULT_ENV, environment: DEFAULT_ENV,
}, },
userName, userName,
req.user,
), ),
), ),
); );
@ -319,6 +320,7 @@ class FeatureController extends Controller {
s, s,
{ projectId, featureName, environment: DEFAULT_ENV }, { projectId, featureName, environment: DEFAULT_ENV },
userName, userName,
req.user,
), ),
), ),
); );

View File

@ -618,6 +618,7 @@ export default class ProjectFeaturesController extends Controller {
strategyConfig, strategyConfig,
{ environment, projectId, featureName }, { environment, projectId, featureName },
userName, userName,
req.user,
); );
const updatedStrategy = await this.featureService.getStrategy( const updatedStrategy = await this.featureService.getStrategy(
@ -674,6 +675,7 @@ export default class ProjectFeaturesController extends Controller {
req.body, req.body,
{ environment, projectId, featureName }, { environment, projectId, featureName },
userName, userName,
req.user,
); );
res.status(200).json(updatedStrategy); res.status(200).json(updatedStrategy);
} }
@ -692,6 +694,7 @@ export default class ProjectFeaturesController extends Controller {
newDocument, newDocument,
{ environment, projectId, featureName }, { environment, projectId, featureName },
userName, userName,
req.user,
); );
res.status(200).json(updatedStrategy); res.status(200).json(updatedStrategy);
} }
@ -720,6 +723,7 @@ export default class ProjectFeaturesController extends Controller {
strategyId, strategyId,
{ environment, projectId, featureName }, { environment, projectId, featureName },
userName, userName,
req.user,
); );
res.status(200).json(strategy); res.status(200).json(strategy);
} }

View File

@ -76,7 +76,10 @@ import { SetStrategySortOrderSchema } from 'lib/openapi/spec/set-strategy-sort-o
import { getDefaultStrategy } from '../util/feature-evaluator/helpers'; import { getDefaultStrategy } from '../util/feature-evaluator/helpers';
import { AccessService } from './access-service'; import { AccessService } from './access-service';
import { User } from '../server-impl'; import { User } from '../server-impl';
import { CREATE_FEATURE_STRATEGY } from '../types/permissions'; import {
CREATE_FEATURE_STRATEGY,
SKIP_CHANGE_REQUEST,
} from '../types/permissions';
import NoAccessError from '../error/no-access-error'; import NoAccessError from '../error/no-access-error';
import { IFeatureProjectUserParams } from '../routes/admin-api/project/features'; import { IFeatureProjectUserParams } from '../routes/admin-api/project/features';
@ -321,10 +324,12 @@ class FeatureToggleService {
strategyConfig: Unsaved<IStrategyConfig>, strategyConfig: Unsaved<IStrategyConfig>,
context: IFeatureStrategyContext, context: IFeatureStrategyContext,
createdBy: string, createdBy: string,
user?: User,
): Promise<Saved<IStrategyConfig>> { ): Promise<Saved<IStrategyConfig>> {
await this.stopWhenChangeRequestsEnabled( await this.stopWhenChangeRequestsEnabled(
context.projectId, context.projectId,
context.environment, context.environment,
user,
); );
return this.unprotectedCreateStrategy( return this.unprotectedCreateStrategy(
strategyConfig, strategyConfig,
@ -413,10 +418,12 @@ class FeatureToggleService {
updates: Partial<IFeatureStrategy>, updates: Partial<IFeatureStrategy>,
context: IFeatureStrategyContext, context: IFeatureStrategyContext,
userName: string, userName: string,
user?: User,
): Promise<Saved<IStrategyConfig>> { ): Promise<Saved<IStrategyConfig>> {
await this.stopWhenChangeRequestsEnabled( await this.stopWhenChangeRequestsEnabled(
context.projectId, context.projectId,
context.environment, context.environment,
user,
); );
return this.unprotectedUpdateStrategy(id, updates, context, userName); return this.unprotectedUpdateStrategy(id, updates, context, userName);
} }
@ -533,10 +540,12 @@ class FeatureToggleService {
id: string, id: string,
context: IFeatureStrategyContext, context: IFeatureStrategyContext,
createdBy: string, createdBy: string,
user?: User,
): Promise<void> { ): Promise<void> {
await this.stopWhenChangeRequestsEnabled( await this.stopWhenChangeRequestsEnabled(
context.projectId, context.projectId,
context.environment, context.environment,
user,
); );
return this.unprotectedDeleteStrategy(id, context, createdBy); return this.unprotectedDeleteStrategy(id, context, createdBy);
} }
@ -1014,7 +1023,7 @@ class FeatureToggleService {
createdBy: string, createdBy: string,
user?: User, user?: User,
): Promise<FeatureToggle> { ): Promise<FeatureToggle> {
await this.stopWhenChangeRequestsEnabled(project, environment); await this.stopWhenChangeRequestsEnabled(project, environment, user);
if (enabled) { if (enabled) {
await this.stopWhenCannotCreateStrategies( await this.stopWhenCannotCreateStrategies(
project, project,
@ -1375,16 +1384,21 @@ class FeatureToggleService {
private async stopWhenChangeRequestsEnabled( private async stopWhenChangeRequestsEnabled(
project: string, project: string,
environment: string, environment: string,
user?: User,
) { ) {
if ( const [canSkipChangeRequest, changeRequestEnabled] = await Promise.all([
await this.accessService.isChangeRequestsEnabled( user
? this.accessService.hasPermission(
user,
SKIP_CHANGE_REQUEST,
project, project,
environment, environment,
) )
) { : Promise.resolve(false),
throw new Error( this.accessService.isChangeRequestsEnabled(project, environment),
`Change requests are enabled in project "${project}" for environment "${environment}"`, ]);
); if (changeRequestEnabled && !canSkipChangeRequest) {
throw new NoAccessError(SKIP_CHANGE_REQUEST);
} }
} }

View File

@ -41,3 +41,4 @@ export const UPDATE_SEGMENT = 'UPDATE_SEGMENT';
export const DELETE_SEGMENT = 'DELETE_SEGMENT'; export const DELETE_SEGMENT = 'DELETE_SEGMENT';
export const APPROVE_CHANGE_REQUEST = 'APPROVE_CHANGE_REQUEST'; export const APPROVE_CHANGE_REQUEST = 'APPROVE_CHANGE_REQUEST';
export const APPLY_CHANGE_REQUEST = 'APPLY_CHANGE_REQUEST'; export const APPLY_CHANGE_REQUEST = 'APPLY_CHANGE_REQUEST';
export const SKIP_CHANGE_REQUEST = 'SKIP_CHANGE_REQUEST';

View File

@ -0,0 +1,17 @@
exports.up = function (db, cb) {
db.runSql(
`
INSERT INTO permissions (permission, display_name, type) VALUES ('SKIP_CHANGE_REQUEST', 'Skip change request process', 'environment');
`,
cb,
);
};
exports.down = function (db, cb) {
db.runSql(
`
DELETE FROM permissions WHERE permission = 'SKIP_CHANGE_REQUEST';
`,
cb,
);
};