UserPermission and GroupPermission models (#5860)

* fix: rename to group_permissions

* fix: delete null collectionId records before setting non null constraint

* fix: use scope with collectionId not null

* fix: update model with documentId

* fix: rename to GroupPermission

* fix: rename collection_users to user_permissions

* fix: teamPermanentDeleter test

* fix: use scope with collectionId not null

* fix: update model with documentId

* fix: rename to UserPermission

* fix: create views upon table rename for zero downtime

* fix: remove comments
This commit is contained in:
Apoorv Mishra
2023-09-25 10:51:29 +05:30
committed by GitHub
parent 43bdb97639
commit 7145f7ef51
22 changed files with 558 additions and 123 deletions

View File

@@ -7,7 +7,7 @@ import {
Collection,
FileOperation,
Group,
CollectionGroup,
GroupPermission,
GroupUser,
Pin,
Star,
@@ -435,7 +435,9 @@ export default class WebsocketsProcessor {
case "groups.add_user": {
// do an add user for every collection that the group is a part of
const collectionGroupMemberships = await CollectionGroup.findAll({
const collectionGroupMemberships = await GroupPermission.scope(
"withCollection"
).findAll({
where: {
groupId: event.modelId,
},
@@ -468,7 +470,9 @@ export default class WebsocketsProcessor {
}
case "groups.remove_user": {
const collectionGroupMemberships = await CollectionGroup.findAll({
const collectionGroupMemberships = await GroupPermission.scope(
"withCollection"
).findAll({
where: {
groupId: event.modelId,
},
@@ -477,9 +481,11 @@ export default class WebsocketsProcessor {
for (const collectionGroup of collectionGroupMemberships) {
// if the user has any memberships remaining on the collection
// we need to emit add instead of remove
const collection = await Collection.scope({
method: ["withMembership", event.userId],
}).findByPk(collectionGroup.collectionId);
const collection = collectionGroup.collectionId
? await Collection.scope({
method: ["withMembership", event.userId],
}).findByPk(collectionGroup.collectionId)
: null;
if (!collection) {
continue;
@@ -535,7 +541,9 @@ export default class WebsocketsProcessor {
},
},
});
const collectionGroupMemberships = await CollectionGroup.findAll({
const collectionGroupMemberships = await GroupPermission.scope(
"withCollection"
).findAll({
paranoid: false,
where: {
groupId: event.modelId,
@@ -546,9 +554,9 @@ export default class WebsocketsProcessor {
});
for (const collectionGroup of collectionGroupMemberships) {
const membershipUserIds = await Collection.membershipUserIds(
collectionGroup.collectionId
);
const membershipUserIds = collectionGroup.collectionId
? await Collection.membershipUserIds(collectionGroup.collectionId)
: [];
for (const groupUser of groupUsers) {
if (membershipUserIds.includes(groupUser.userId)) {