Skip to content

Commit

Permalink
fix: Add in missing create/delete tag permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
sighphyre committed Jan 12, 2022
1 parent 9e085d0 commit debfb07
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/lib/services/feature-toggle-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,28 @@ class FeatureToggleService {
return this.getFeatureToggles({}, true);
}

async changeProject(
featureName: string,
newProject: string,
createdBy: string,
): Promise<void> {
const feature = await this.featureToggleStore.get(featureName);
const oldProject = feature.project;
feature.project = newProject;
await this.featureToggleStore.update(newProject, feature);

const tags = await this.tagStore.getAllTagsForFeature(featureName);
await this.eventStore.store(
new FeatureChangeProjectEvent({
createdBy,
oldProject,
newProject,
featureName,
tags,
}),
);
}

// TODO: add project id.
async deleteFeature(featureName: string, createdBy: string): Promise<void> {
const toggle = await this.featureToggleStore.get(featureName);
Expand Down
2 changes: 2 additions & 0 deletions src/lib/types/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ 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 CREATE_TAG = 'CREATE_TAG';
export const DELETE_TAG = 'DELETE_TAG';
export const UPDATE_FEATURE_VARIANTS = 'UPDATE_FEATURE_VARIANTS';
export const MOVE_FEATURE_TOGGLE = 'MOVE_FEATURE_TOGGLE';
33 changes: 33 additions & 0 deletions src/migrations/20220112071201-add-tag-permissions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
exports.up = function (db, cb) {
db.runSql(
`
INSERT INTO permissions (permission, display_name, type) VALUES ('CREATE_TAG', 'Add tags to toggles', 'project');
INSERT INTO permissions (permission, display_name, type) VALUES ('DELETE_TAG', 'Remove tags from toggles', 'project');
INSERT INTO role_permission (role_id, permission_id, environment)
SELECT
(SELECT id as role_id from roles WHERE name = 'Editor' LIMIT 1),
p.id as permission_id,
'' as environment
FROM permissions p
WHERE p.permission IN
('CREATE_TAG',
'DELETE_TAG');
INSERT INTO role_permission (role_id, permission_id, environment)
SELECT
(SELECT id as role_id from roles WHERE name = 'Owner' LIMIT 1),
p.id as permission_id,
'' as environment
FROM permissions p
WHERE p.permission IN
('CREATE_TAG',
'DELETE_TAG');
`,
cb,
);
};

exports.down = function (db, cb) {
cb();
};

0 comments on commit debfb07

Please sign in to comment.