Skip to content

Commit

Permalink
chore: minor cleanup for memberships
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Fontanier committed Apr 5, 2024
1 parent 9ddfac0 commit 891dd1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
30 changes: 9 additions & 21 deletions front/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,28 +129,16 @@ export class Authenticator {

if (user && workspace) {
[role, subscription, flags] = await Promise.all([
(async (): Promise<RoleType> => {
const membership =
await MembershipResource.getActiveMembershipOfUserInWorkspace({
user: renderUserType(user),
workspace: renderLightWorkspaceType({ workspace }),
});
return membership &&
// TODO(@fontanierh): get rid of the check ?
["admin", "builder", "user"].includes(membership.role)
? (membership.role as RoleType)
: "none";
})(),
MembershipResource.getActiveMembershipOfUserInWorkspace({
user: renderUserType(user),
workspace: renderLightWorkspaceType({ workspace }),
}).then((m) => m?.role ?? "none"),
subscriptionForWorkspace(workspace.sId),
(async () => {
return (
await FeatureFlag.findAll({
where: {
workspaceId: workspace.id,
},
})
).map((flag) => flag.name);
})(),
FeatureFlag.findAll({
where: {
workspaceId: workspace.id,
},
}).then((flags) => flags.map((flag) => flag.name)),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion front/lib/resources/membership_resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export class MembershipResource extends BaseResource<MembershipModel> {
}

// If the membership is not terminated, we update the role in place.
// TODO(@fontanierh): check if we want to terminate + create a new membership with new role instead ?
// We do not historicize the roles.
if (!membership.endAt) {
if (membership.role === newRole) {
return new Err({ type: "already_on_role" });
Expand Down

0 comments on commit 891dd1f

Please sign in to comment.