Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fetching user root roles include custom ones #4068

Merged
merged 4 commits into from
Jun 22, 2023

Conversation

gastonfournier
Copy link
Contributor

About the changes

getUserRootRoles should also consider custom root roles

This introduces test cases that unveiled a dependency between stores (this happens actually at the DB layer having access-service access tables from two different stores but skipping the store layer).

https://linear.app/unleash/issue/2-1161/a-user-with-custom-root-role-and-permission-to-create-client-api

@vercel
Copy link

vercel bot commented Jun 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Jun 22, 2023 2:32pm
unleash-monorepo-frontend ⬜️ Ignored (Inspect) Jun 22, 2023 2:32pm

@@ -45,7 +45,7 @@ export const createFakeAccessService = (
const accountStore = new FakeAccountStore();
const roleStore = new FakeRoleStore();
const environmentStore = new FakeEnvironmentStore();
const accessStore = new FakeAccessStore();
const accessStore = new FakeAccessStore(roleStore);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kwasniew I'm reusing your createAccessService method which simplifies the test setup, but note I'm explicitly adding this dependency because access-store directly queries roles table:

ROLES: 'roles',

To simulate this DB coupling I'm adding this dependency.

I couldn't find a better way which is why I'm tagging you in case you have some ideas

@@ -275,7 +275,9 @@ export class AccessService {

async getUserRootRoles(userId: number): Promise<IRoleWithProject[]> {
const userRoles = await this.store.getRolesForUserId(userId);
return userRoles.filter((r) => r.type === RoleType.ROOT);
return userRoles.filter(
(r) => r.type === RoleType.ROOT || r.type === RoleType.ROOT_CUSTOM,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe consider ({type}) => ROOT_ROLE_TYPES.includes(type) in case it's cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 9956e9e

name: string;
/**
* Extends IRole making description mandatory
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still like to drop ICustomRole and only have IRole. Description is already required in the frontend interface frontend/src/interfaces/role.ts and AFAIK there's always a description.

Could be out of scope for this PR and maybe belong in a separate one though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 but I thought chasing down why the description was optional required a deeper investigation and analyze potential backward incompatibility problems as I see that some project role in our sandbox instance were created without a description

Copy link
Member

@nunogois nunogois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but added a few comments.

gastonfournier and others added 2 commits June 22, 2023 16:24
Co-authored-by: Nuno Góis <github@nunogois.com>
@gastonfournier gastonfournier enabled auto-merge (squash) June 22, 2023 14:33
@gastonfournier gastonfournier merged commit 4cedb00 into main Jun 22, 2023
10 checks passed
@gastonfournier gastonfournier deleted the fix-root-role-include-custom-root-roles branch June 22, 2023 14:42
@nunogois
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants