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

@@ -16,8 +16,8 @@ import { transaction } from "@server/middlewares/transaction";
import validate from "@server/middlewares/validate";
import {
Collection,
CollectionUser,
CollectionGroup,
UserPermission,
GroupPermission,
Team,
Event,
User,
@@ -220,7 +220,7 @@ router.post(
const group = await Group.findByPk(groupId);
authorize(user, "read", group);
let membership = await CollectionGroup.findOne({
let membership = await GroupPermission.findOne({
where: {
collectionId: id,
groupId,
@@ -228,7 +228,7 @@ router.post(
});
if (!membership) {
membership = await CollectionGroup.create({
membership = await GroupPermission.create({
collectionId: id,
groupId,
permission,
@@ -310,7 +310,7 @@ router.post(
}).findByPk(id);
authorize(user, "read", collection);
let where: WhereOptions<CollectionGroup> = {
let where: WhereOptions<GroupPermission> = {
collectionId: id,
};
let groupWhere;
@@ -340,8 +340,8 @@ router.post(
};
const [total, memberships] = await Promise.all([
CollectionGroup.count(options),
CollectionGroup.findAll({
GroupPermission.count(options),
GroupPermission.findAll({
...options,
order: [["createdAt", "DESC"]],
offset: ctx.state.pagination.offset,
@@ -379,7 +379,7 @@ router.post(
const user = await User.findByPk(userId);
authorize(actor, "read", user);
let membership = await CollectionUser.findOne({
let membership = await UserPermission.findOne({
where: {
collectionId: id,
userId,
@@ -389,7 +389,7 @@ router.post(
});
if (!membership) {
membership = await CollectionUser.create(
membership = await UserPermission.create(
{
collectionId: id,
userId,
@@ -485,7 +485,7 @@ router.post(
}).findByPk(id);
authorize(user, "read", collection);
let where: WhereOptions<CollectionUser> = {
let where: WhereOptions<UserPermission> = {
collectionId: id,
};
let userWhere;
@@ -515,8 +515,8 @@ router.post(
};
const [total, memberships] = await Promise.all([
CollectionUser.count(options),
CollectionUser.findAll({
UserPermission.count(options),
UserPermission.findAll({
...options,
order: [["createdAt", "DESC"]],
offset: ctx.state.pagination.offset,
@@ -627,7 +627,7 @@ router.post(
permission !== CollectionPermission.ReadWrite &&
collection.permission === CollectionPermission.ReadWrite
) {
await CollectionUser.findOrCreate({
await UserPermission.findOrCreate({
where: {
collectionId: collection.id,
userId: user.id,