From 4c99d079e0796906dbc3c3248aeca172c89dc829 Mon Sep 17 00:00:00 2001 From: Paul Makles <paulmakles@gmail.com> Date: Tue, 9 Feb 2021 15:51:35 +0000 Subject: [PATCH] Remove ViewAll; check for mutual DMs. --- src/database/entities/user.rs | 5 +---- src/database/permissions/user.rs | 13 +++++-------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/database/entities/user.rs b/src/database/entities/user.rs index 26f6b77..ff69e93 100644 --- a/src/database/entities/user.rs +++ b/src/database/entities/user.rs @@ -43,6 +43,7 @@ impl User { return self; } + self.relations = None; if let Some(relations) = &user.relations { if let Some(relationship) = relations.iter().find(|x| self.id == x.id) { self.relationship = Some(relationship.status.clone()); @@ -55,10 +56,6 @@ impl User { /// Mutate the user object to appear as seen by user. pub fn with(mut self, permissions: UserPermissions<[u32; 1]>) -> User { - if !permissions.get_view_all() { - self.relations = None; - } - if permissions.get_view_profile() { self.online = Some(is_online(&self.id)); } diff --git a/src/database/permissions/user.rs b/src/database/permissions/user.rs index 1941453..07aa093 100644 --- a/src/database/permissions/user.rs +++ b/src/database/permissions/user.rs @@ -14,8 +14,6 @@ pub enum UserPermission { ViewProfile = 2, SendMessage = 4, Invite = 8, - - ViewAll = 2147483648, } bitfield! { @@ -25,13 +23,9 @@ bitfield! { pub get_view_profile, _: 30; pub get_send_message, _: 29; pub get_invite, _: 28; - - pub get_view_all, _: 0; } impl_op_ex!(+ |a: &UserPermission, b: &UserPermission| -> u32 { *a as u32 | *b as u32 }); -impl_op_ex!(-|a: &UserPermission, b: &UserPermission| -> u32 { *a as u32 & !(*b as u32) }); -impl_op_ex!(-|a: &u32, b: &UserPermission| -> u32 { *a & !(*b as u32) }); impl_op_ex_commutative!(+ |a: &u32, b: &UserPermission| -> u32 { *a | *b as u32 }); pub fn get_relationship(a: &User, b: &str) -> RelationshipStatus { @@ -56,7 +50,7 @@ impl<'a> PermissionCalculator<'a> { let mut permissions: u32 = 0; match get_relationship(&self.perspective, &target) { - RelationshipStatus::Friend => return Ok(u32::MAX - UserPermission::ViewAll), + RelationshipStatus::Friend => return Ok(u32::MAX), RelationshipStatus::Blocked | RelationshipStatus::BlockedOther => { return Ok(UserPermission::Access as u32) } @@ -74,7 +68,10 @@ impl<'a> PermissionCalculator<'a> { || get_collection("channels") .find_one( doc! { - "type": "Group", + "$or": [ + { "type": "Group" }, + { "type": "DirectMessage" }, + ], "$and": { "recipients": &self.perspective.id, "recipients": target -- GitLab