1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

fix: use projectId from param (#3372)

This commit is contained in:
Jaanus Sellin 2023-03-23 10:12:38 +02:00 committed by GitHub
parent f3f1eb7eb3
commit 407b2524b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View File

@ -332,3 +332,36 @@ test('DELETE_TAG_TYPE does not need projectId', async () => {
undefined,
);
});
test('should not expect featureName for UPDATE_FEATURE when projectId specified', async () => {
const projectId = 'some-project-33';
const accessService = {
hasPermission: jest.fn(),
};
const func = rbacMiddleware(config, { featureToggleStore }, accessService);
const cb = jest.fn();
const req: any = {
user: new User({
username: 'user',
id: 1,
}),
params: {},
body: {
project: projectId,
},
};
func(req, undefined, cb);
await req.checkRbac(perms.UPDATE_FEATURE);
expect(accessService.hasPermission).toHaveBeenCalledWith(
req.user,
perms.UPDATE_FEATURE,
projectId,
undefined,
);
});

View File

@ -63,7 +63,10 @@ const rbacMiddleware = (
// Temporary workaround to figure out projectId for feature toggle updates.
// will be removed in Unleash v5.0
if ([DELETE_FEATURE, UPDATE_FEATURE].includes(permission)) {
if (
!projectId &&
[DELETE_FEATURE, UPDATE_FEATURE].includes(permission)
) {
const { featureName } = params;
projectId = await featureToggleStore.getProjectId(featureName);
} else if (