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:
Saumya Pandey
2021-08-30 11:43:42 +05:30
committed by GitHub
parent 08a8fea69a
commit 4929fbaccb
6 changed files with 161 additions and 127 deletions

View File

@@ -58,6 +58,7 @@ Event.ACTIVITY_EVENTS = [
"collections.create",
"collections.delete",
"collections.move",
"collections.permission_changed",
"documents.publish",
"documents.archive",
"documents.unarchive",
@@ -77,6 +78,7 @@ Event.AUDIT_EVENTS = [
"authenticationProviders.update",
"collections.create",
"collections.update",
"collections.permission_changed",
"collections.move",
"collections.add_user",
"collections.remove_user",

View File

@@ -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();
}

View File

@@ -174,6 +174,17 @@ export type CollectionEvent =
actorId: string,
data: { index: string },
ip: string,
}
| {
name: "collections.permission_changed",
collectionId: string,
teamId: string,
actorId: string,
data: {
privacyChanged: boolean,
sharingChanged: boolean,
},
ip: string,
};
export type GroupEvent =