Policies refactor, guest roles (#6732)
This commit is contained in:
@@ -59,6 +59,13 @@ import Length from "./validators/Length";
|
||||
}),
|
||||
as: "collection",
|
||||
},
|
||||
{
|
||||
association: "memberships",
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user