Policies refactor, guest roles (#6732)

This commit is contained in:
Tom Moor
2024-03-31 18:28:35 -06:00
committed by GitHub
parent ceb7ae1514
commit c27cd945a7
46 changed files with 901 additions and 1032 deletions

View File

@@ -59,6 +59,13 @@ import Length from "./validators/Length";
}),
as: "collection",
},
{
association: "memberships",
where: {
userId,
},
required: false,
},
],
},
{

View File

@@ -238,18 +238,41 @@ class User extends ParanoidModel<
return !!this.suspendedAt || !!this.team?.isSuspended;
}
/**
* Whether the user has been invited but not yet signed in.
*/
get isInvited() {
return !this.lastActiveAt;
}
/**
* Whether the user is an admin.
*/
get isAdmin() {
return this.role === UserRole.Admin;
}
/**
* Whether the user is a member (editor).
*/
get isMember() {
return this.role === UserRole.Member;
}
/**
* Whether the user is a viewer.
*/
get isViewer() {
return this.role === UserRole.Viewer;
}
/**
* Whether the user is a guest.
*/
get isGuest() {
return this.role === UserRole.Guest;
}
get color() {
return stringToColor(this.id);
}
@@ -404,9 +427,10 @@ class User extends ParanoidModel<
return collectionStubs
.filter(
(c) =>
Object.values(CollectionPermission).includes(
(Object.values(CollectionPermission).includes(
c.permission as CollectionPermission
) ||
) &&
!this.isGuest) ||
c.memberships.length > 0 ||
c.collectionGroupMemberships.length > 0
)

View File

@@ -8,6 +8,15 @@ class ParanoidModel<
> extends IdModel<TModelAttributes, TCreationAttributes> {
@DeletedAt
deletedAt: Date | null;
/**
* Whether the model has been deleted.
*
* @returns True if the model has been deleted
*/
get isDeleted() {
return !!this.deletedAt;
}
}
export default ParanoidModel;