mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-21 13:47:39 +02:00
fix: setup permission for variant
This commit is contained in:
parent
95b50acdd8
commit
ef8041d315
@ -5,7 +5,10 @@ import { IUnleashConfig } from '../../../types/option';
|
||||
import { IUnleashServices } from '../../../types';
|
||||
import { Request, Response } from 'express';
|
||||
import { Operation } from 'fast-json-patch';
|
||||
import { UPDATE_FEATURE } from '../../../types/permissions';
|
||||
import {
|
||||
UPDATE_FEATURE,
|
||||
UPDATE_FEATURE_VARIANTS,
|
||||
} from '../../../types/permissions';
|
||||
import { IVariant } from '../../../types/model';
|
||||
import { extractUsername } from '../../../util/extract-user';
|
||||
import { IAuthRequest } from '../../unleash-types';
|
||||
@ -35,8 +38,8 @@ export default class VariantsController extends Controller {
|
||||
this.logger = config.getLogger('admin-api/project/variants.ts');
|
||||
this.featureService = featureToggleService;
|
||||
this.get(PREFIX, this.getVariants);
|
||||
this.patch(PREFIX, this.patchVariants, UPDATE_FEATURE);
|
||||
this.put(PREFIX, this.overwriteVariants, UPDATE_FEATURE);
|
||||
this.patch(PREFIX, this.patchVariants, UPDATE_FEATURE_VARIANTS);
|
||||
this.put(PREFIX, this.overwriteVariants, UPDATE_FEATURE_VARIANTS);
|
||||
}
|
||||
|
||||
async getVariants(
|
||||
|
@ -30,3 +30,4 @@ export const CREATE_API_TOKEN = 'CREATE_API_TOKEN';
|
||||
export const DELETE_API_TOKEN = 'DELETE_API_TOKEN';
|
||||
export const UPDATE_TAG_TYPE = 'UPDATE_TAG_TYPE';
|
||||
export const DELETE_TAG_TYPE = 'DELETE_TAG_TYPE';
|
||||
export const UPDATE_FEATURE_VARIANTS = 'UPDATE_FEATURE_VARIANTS';
|
||||
|
@ -38,6 +38,7 @@ exports.up = function (db, cb) {
|
||||
INSERT INTO permissions (permission, display_name, type) VALUES ('UPDATE_FEATURE_STRATEGY', 'Update Feature Strategies', 'environment');
|
||||
INSERT INTO permissions (permission, display_name, type) VALUES ('DELETE_FEATURE_STRATEGY', 'Delete Feature Strategies', 'environment');
|
||||
INSERT INTO permissions (permission, display_name, type) VALUES ('UPDATE_FEATURE_ENVIRONMENT', 'Enable/disable Toggles in Environment', 'environment');
|
||||
INSERT INTO permissions (permission, display_name, type) VALUES ('UPDATE_FEATURE_VARIANTS', 'Create/Edit variants', 'project');
|
||||
|
||||
ALTER TABLE role_user ADD COLUMN
|
||||
project VARCHAR(255);
|
||||
@ -135,7 +136,8 @@ exports.up = function (db, cb) {
|
||||
'UPDATE_FEATURE',
|
||||
'DELETE_FEATURE',
|
||||
'UPDATE_TAG_TYPE',
|
||||
'DELETE_TAG_TYPE');
|
||||
'DELETE_TAG_TYPE',
|
||||
'UPDATE_FEATURE_VARIANTS');
|
||||
|
||||
INSERT INTO role_permission (role_id, permission_id, environment)
|
||||
SELECT
|
||||
@ -148,7 +150,8 @@ exports.up = function (db, cb) {
|
||||
'DELETE_PROJECT',
|
||||
'CREATE_FEATURE',
|
||||
'UPDATE_FEATURE',
|
||||
'DELETE_FEATURE');
|
||||
'DELETE_FEATURE',
|
||||
'UPDATE_FEATURE_VARIANTS');
|
||||
|
||||
INSERT INTO role_permission (role_id, permission_id, environment)
|
||||
SELECT
|
||||
@ -159,7 +162,8 @@ exports.up = function (db, cb) {
|
||||
WHERE p.permission IN
|
||||
('CREATE_FEATURE',
|
||||
'UPDATE_FEATURE',
|
||||
'DELETE_FEATURE');
|
||||
'DELETE_FEATURE',
|
||||
'UPDATE_FEATURE_VARIANTS');
|
||||
|
||||
INSERT INTO role_permission (role_id, permission_id, environment)
|
||||
SELECT
|
||||
|
@ -52,6 +52,7 @@ const hasCommonProjectAccess = async (user, projectName, condition) => {
|
||||
UPDATE_FEATURE_STRATEGY,
|
||||
DELETE_FEATURE_STRATEGY,
|
||||
UPDATE_FEATURE_ENVIRONMENT,
|
||||
UPDATE_FEATURE_VARIANTS,
|
||||
} = permissions;
|
||||
expect(
|
||||
await accessService.hasPermission(user, CREATE_FEATURE, projectName),
|
||||
@ -62,6 +63,13 @@ const hasCommonProjectAccess = async (user, projectName, condition) => {
|
||||
expect(
|
||||
await accessService.hasPermission(user, DELETE_FEATURE, projectName),
|
||||
).toBe(condition);
|
||||
expect(
|
||||
await accessService.hasPermission(
|
||||
user,
|
||||
UPDATE_FEATURE_VARIANTS,
|
||||
projectName,
|
||||
),
|
||||
).toBe(condition);
|
||||
expect(
|
||||
await accessService.hasPermission(
|
||||
user,
|
||||
|
Loading…
Reference in New Issue
Block a user