fix: Disallow adding self to collection (#4299)
* api * ui * update collection permissions
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user