mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-06 01:15:28 +02:00
Deleting project does not delete entry group_role table (#1896)
* Add constraint for project * Add constraint for project * Add constraint for project * Add constraint for project * Add constraint for project * Revert eslint * Fix eslint * Fix tests
This commit is contained in:
parent
84a932043e
commit
59b8a06968
20
src/migrations/20220808110415-add-projects-foreign-key.js
Normal file
20
src/migrations/20220808110415-add-projects-foreign-key.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
exports.up = function (db, cb) {
|
||||||
|
db.runSql(
|
||||||
|
`
|
||||||
|
delete from group_role where project not in (select id from projects);
|
||||||
|
ALTER TABLE group_role
|
||||||
|
ADD CONSTRAINT fk_group_role_project
|
||||||
|
FOREIGN KEY(project)
|
||||||
|
REFERENCES projects(id) ON DELETE CASCADE; `,
|
||||||
|
cb,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.down = function (db, cb) {
|
||||||
|
db.runSql(
|
||||||
|
`
|
||||||
|
ALTER TABLE group_role DROP CONSTRAINT fk_group_role_project;
|
||||||
|
`,
|
||||||
|
cb,
|
||||||
|
);
|
||||||
|
};
|
@ -170,7 +170,7 @@ const hasCommonProjectAccess = async (user, projectName, condition) => {
|
|||||||
).toBe(condition);
|
).toBe(condition);
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasFullProjectAccess = async (user, projectName, condition) => {
|
const hasFullProjectAccess = async (user, projectName: string, condition) => {
|
||||||
const { DELETE_PROJECT, UPDATE_PROJECT, MOVE_FEATURE_TOGGLE } = permissions;
|
const { DELETE_PROJECT, UPDATE_PROJECT, MOVE_FEATURE_TOGGLE } = permissions;
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@ -862,13 +862,19 @@ test('Should not be allowed to delete a project role', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Should be allowed move feature toggle to project when given access through group', async () => {
|
test('Should be allowed move feature toggle to project when given access through group', async () => {
|
||||||
const project = 'yet-another-project';
|
const project = {
|
||||||
|
id: 'yet-another-project1',
|
||||||
|
name: 'yet-another-project1',
|
||||||
|
};
|
||||||
|
|
||||||
const groupStore = stores.groupStore;
|
const groupStore = stores.groupStore;
|
||||||
const viewerUser = await createUserViewerAccess(
|
const viewerUser = await createUserViewerAccess(
|
||||||
'Victoria Viewer',
|
'Victoria Viewer',
|
||||||
'vickyv@getunleash.io',
|
'vickyv@getunleash.io',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await projectService.createProject(project, editorUser);
|
||||||
|
|
||||||
const groupWithProjectAccess = await groupStore.create({
|
const groupWithProjectAccess = await groupStore.create({
|
||||||
name: 'Project Editors',
|
name: 'Project Editors',
|
||||||
description: '',
|
description: '',
|
||||||
@ -882,24 +888,29 @@ test('Should be allowed move feature toggle to project when given access through
|
|||||||
|
|
||||||
const projectRole = await accessService.getRoleByName(RoleName.MEMBER);
|
const projectRole = await accessService.getRoleByName(RoleName.MEMBER);
|
||||||
|
|
||||||
await hasCommonProjectAccess(viewerUser, project, false);
|
await hasCommonProjectAccess(viewerUser, project.id, false);
|
||||||
|
|
||||||
await accessService.addGroupToRole(
|
await accessService.addGroupToRole(
|
||||||
groupWithProjectAccess.id,
|
groupWithProjectAccess.id,
|
||||||
projectRole.id,
|
projectRole.id,
|
||||||
'SomeAdminUser',
|
'SomeAdminUser',
|
||||||
project,
|
project.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
await hasCommonProjectAccess(viewerUser, project, true);
|
await hasCommonProjectAccess(viewerUser, project.id, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Should not lose user role access when given permissions from a group', async () => {
|
test('Should not lose user role access when given permissions from a group', async () => {
|
||||||
const project = 'yet-another-project';
|
const project = {
|
||||||
|
id: 'yet-another-project-lose',
|
||||||
|
name: 'yet-another-project-lose',
|
||||||
|
};
|
||||||
const user = editorUser;
|
const user = editorUser;
|
||||||
const groupStore = stores.groupStore;
|
const groupStore = stores.groupStore;
|
||||||
|
|
||||||
await accessService.createDefaultProjectRoles(user, project);
|
await projectService.createProject(project, user);
|
||||||
|
|
||||||
|
// await accessService.createDefaultProjectRoles(user, project.id);
|
||||||
|
|
||||||
const groupWithNoAccess = await groupStore.create({
|
const groupWithNoAccess = await groupStore.create({
|
||||||
name: 'ViewersOnly',
|
name: 'ViewersOnly',
|
||||||
@ -908,7 +919,7 @@ test('Should not lose user role access when given permissions from a group', asy
|
|||||||
|
|
||||||
await groupStore.addNewUsersToGroup(
|
await groupStore.addNewUsersToGroup(
|
||||||
groupWithNoAccess.id,
|
groupWithNoAccess.id,
|
||||||
[{ user: editorUser, role: 'Owner' }],
|
[{ user: user, role: 'Owner' }],
|
||||||
'Admin',
|
'Admin',
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -918,23 +929,33 @@ test('Should not lose user role access when given permissions from a group', asy
|
|||||||
groupWithNoAccess.id,
|
groupWithNoAccess.id,
|
||||||
viewerRole.id,
|
viewerRole.id,
|
||||||
'SomeAdminUser',
|
'SomeAdminUser',
|
||||||
project,
|
project.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
await hasFullProjectAccess(editorUser, project, true);
|
await hasFullProjectAccess(user, project.id, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Should allow user to take multiple group roles and have expected permissions on each project', async () => {
|
test('Should allow user to take multiple group roles and have expected permissions on each project', async () => {
|
||||||
const projectForCreate =
|
const projectForCreate = {
|
||||||
'project-that-should-have-create-toggle-permission';
|
id: 'project-that-should-have-create-toggle-permission',
|
||||||
const projectForDelete =
|
name: 'project-that-should-have-create-toggle-permission',
|
||||||
'project-that-should-have-delete-toggle-permission';
|
description: 'Blah',
|
||||||
|
};
|
||||||
|
const projectForDelete = {
|
||||||
|
id: 'project-that-should-have-delete-toggle-permission',
|
||||||
|
name: 'project-that-should-have-delete-toggle-permission',
|
||||||
|
description: 'Blah',
|
||||||
|
};
|
||||||
|
|
||||||
const groupStore = stores.groupStore;
|
const groupStore = stores.groupStore;
|
||||||
const viewerUser = await createUserViewerAccess(
|
const viewerUser = await createUserViewerAccess(
|
||||||
'Victor Viewer',
|
'Victor Viewer',
|
||||||
'victore@getunleash.io',
|
'victore@getunleash.io',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await projectService.createProject(projectForCreate, editorUser);
|
||||||
|
await projectService.createProject(projectForDelete, editorUser);
|
||||||
|
|
||||||
const groupWithCreateAccess = await groupStore.create({
|
const groupWithCreateAccess = await groupStore.create({
|
||||||
name: 'ViewersOnly',
|
name: 'ViewersOnly',
|
||||||
description: '',
|
description: '',
|
||||||
@ -989,28 +1010,28 @@ test('Should allow user to take multiple group roles and have expected permissio
|
|||||||
groupWithCreateAccess.id,
|
groupWithCreateAccess.id,
|
||||||
deleteFeatureRole.id,
|
deleteFeatureRole.id,
|
||||||
'SomeAdminUser',
|
'SomeAdminUser',
|
||||||
projectForDelete,
|
projectForDelete.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
await accessService.addGroupToRole(
|
await accessService.addGroupToRole(
|
||||||
groupWithDeleteAccess.id,
|
groupWithDeleteAccess.id,
|
||||||
createFeatureRole.id,
|
createFeatureRole.id,
|
||||||
'SomeAdminUser',
|
'SomeAdminUser',
|
||||||
projectForCreate,
|
projectForCreate.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await accessService.hasPermission(
|
await accessService.hasPermission(
|
||||||
viewerUser,
|
viewerUser,
|
||||||
permissions.CREATE_FEATURE,
|
permissions.CREATE_FEATURE,
|
||||||
projectForCreate,
|
projectForCreate.id,
|
||||||
),
|
),
|
||||||
).toBe(true);
|
).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
await accessService.hasPermission(
|
await accessService.hasPermission(
|
||||||
viewerUser,
|
viewerUser,
|
||||||
permissions.DELETE_FEATURE,
|
permissions.DELETE_FEATURE,
|
||||||
projectForCreate,
|
projectForCreate.id,
|
||||||
),
|
),
|
||||||
).toBe(false);
|
).toBe(false);
|
||||||
|
|
||||||
@ -1018,14 +1039,14 @@ test('Should allow user to take multiple group roles and have expected permissio
|
|||||||
await accessService.hasPermission(
|
await accessService.hasPermission(
|
||||||
viewerUser,
|
viewerUser,
|
||||||
permissions.CREATE_FEATURE,
|
permissions.CREATE_FEATURE,
|
||||||
projectForDelete,
|
projectForDelete.id,
|
||||||
),
|
),
|
||||||
).toBe(false);
|
).toBe(false);
|
||||||
expect(
|
expect(
|
||||||
await accessService.hasPermission(
|
await accessService.hasPermission(
|
||||||
viewerUser,
|
viewerUser,
|
||||||
permissions.DELETE_FEATURE,
|
permissions.DELETE_FEATURE,
|
||||||
projectForDelete,
|
projectForDelete.id,
|
||||||
),
|
),
|
||||||
).toBe(true);
|
).toBe(true);
|
||||||
});
|
});
|
||||||
|
@ -834,7 +834,11 @@ test('should not update role for user on project when she is the owner', async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Should allow bulk update of group permissions', async () => {
|
test('Should allow bulk update of group permissions', async () => {
|
||||||
const project = 'bulk-update-project';
|
const project = {
|
||||||
|
id: 'bulk-update-project',
|
||||||
|
name: 'bulk-update-project',
|
||||||
|
};
|
||||||
|
await projectService.createProject(project, user.id);
|
||||||
const groupStore = stores.groupStore;
|
const groupStore = stores.groupStore;
|
||||||
|
|
||||||
const user1 = await stores.userStore.insert({
|
const user1 = await stores.userStore.insert({
|
||||||
@ -862,7 +866,7 @@ test('Should allow bulk update of group permissions', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await projectService.addAccess(
|
await projectService.addAccess(
|
||||||
project,
|
project.id,
|
||||||
createFeatureRole.id,
|
createFeatureRole.id,
|
||||||
{
|
{
|
||||||
users: [{ id: user1.id }],
|
users: [{ id: user1.id }],
|
||||||
@ -906,9 +910,14 @@ test('Should bulk update of only users', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Should allow bulk update of only groups', async () => {
|
test('Should allow bulk update of only groups', async () => {
|
||||||
const project = 'bulk-update-project';
|
const project = {
|
||||||
|
id: 'bulk-update-project-only',
|
||||||
|
name: 'bulk-update-project-only',
|
||||||
|
};
|
||||||
const groupStore = stores.groupStore;
|
const groupStore = stores.groupStore;
|
||||||
|
|
||||||
|
await projectService.createProject(project, user.id);
|
||||||
|
|
||||||
const group1 = await groupStore.create({
|
const group1 = await groupStore.create({
|
||||||
name: 'ViewersOnly',
|
name: 'ViewersOnly',
|
||||||
description: '',
|
description: '',
|
||||||
@ -929,7 +938,7 @@ test('Should allow bulk update of only groups', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await projectService.addAccess(
|
await projectService.addAccess(
|
||||||
project,
|
project.id,
|
||||||
createFeatureRole.id,
|
createFeatureRole.id,
|
||||||
{
|
{
|
||||||
users: [],
|
users: [],
|
||||||
|
Loading…
Reference in New Issue
Block a user