fix: Move "public document sharing" to "Permissions" (#2496)
* Convert to functional component * Move public sharing to permissions * Add collections.permission_changed event * Account for null * Update server/events.js Co-authored-by: Tom Moor <tom.moor@gmail.com> * Add collections.permission_changed event * Remove name Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
@ -559,7 +559,8 @@ router.post("collections.update", auth(), async (ctx) => {
|
||||
});
|
||||
}
|
||||
|
||||
const permissionChanged = permission !== collection.permission;
|
||||
let privacyChanged = false;
|
||||
let sharingChanged = false;
|
||||
|
||||
if (name !== undefined) {
|
||||
collection.name = name;
|
||||
@ -574,9 +575,17 @@ router.post("collections.update", auth(), async (ctx) => {
|
||||
collection.color = color;
|
||||
}
|
||||
if (permission !== undefined) {
|
||||
// frontend sends empty string
|
||||
ctx.assertIn(
|
||||
permission,
|
||||
["read_write", "read", "", null],
|
||||
"Invalid permission"
|
||||
);
|
||||
privacyChanged = permission !== collection.permission;
|
||||
collection.permission = permission ? permission : null;
|
||||
}
|
||||
if (sharing !== undefined) {
|
||||
sharingChanged = sharing !== collection.sharing;
|
||||
collection.sharing = sharing;
|
||||
}
|
||||
if (sort !== undefined) {
|
||||
@ -594,9 +603,20 @@ router.post("collections.update", auth(), async (ctx) => {
|
||||
ip: ctx.request.ip,
|
||||
});
|
||||
|
||||
if (privacyChanged || sharingChanged) {
|
||||
await Event.create({
|
||||
name: "collections.permission_changed",
|
||||
collectionId: collection.id,
|
||||
teamId: collection.teamId,
|
||||
actorId: user.id,
|
||||
data: { privacyChanged, sharingChanged },
|
||||
ip: ctx.request.ip,
|
||||
});
|
||||
}
|
||||
|
||||
// must reload to update collection membership for correct policy calculation
|
||||
// if the privacy level has changed. Otherwise skip this query for speed.
|
||||
if (permissionChanged) {
|
||||
if (privacyChanged || sharingChanged) {
|
||||
await collection.reload();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user