fix: Disallow adding self to collection (#4299)

* api

* ui

* update collection permissions
This commit is contained in:
Tom Moor
2022-10-15 22:11:09 -04:00
committed by GitHub
parent 97a50b20da
commit 1915a453db
6 changed files with 89 additions and 4 deletions

View File

@@ -33,6 +33,7 @@ import env from "@server/env";
import { ValidationError } from "../errors";
import ApiKey from "./ApiKey";
import Collection from "./Collection";
import CollectionUser from "./CollectionUser";
import NotificationSetting from "./NotificationSetting";
import Star from "./Star";
import Team from "./Team";
@@ -487,7 +488,7 @@ class User extends ParanoidModel {
if (res.count >= 1) {
if (to === "member") {
return this.update(
await this.update(
{
isAdmin: false,
isViewer: false,
@@ -495,13 +496,24 @@ class User extends ParanoidModel {
options
);
} else if (to === "viewer") {
return this.update(
await this.update(
{
isAdmin: false,
isViewer: true,
},
options
);
await CollectionUser.update(
{
permission: CollectionPermission.Read,
},
{
...options,
where: {
userId: this.id,
},
}
);
}
return undefined;