Skip to content

Commit

Permalink
allow editing/unhiding by group
Browse files Browse the repository at this point in the history
Fixes dani-garcia#2989

Signed-off-by: Jan Jansen <jan.jansen@gdata.de>
  • Loading branch information
farodin91 committed Jan 5, 2023
1 parent 10dadfc commit c1f5283
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
50 changes: 28 additions & 22 deletions src/db/models/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,20 @@ impl Collection {
if user_org.has_full_access() {
return true;
}

db_run! { conn: {
users_collections::table
.filter(users_collections::collection_uuid.eq(&self.uuid))
.filter(users_collections::user_uuid.eq(user_uuid))
.filter(users_collections::read_only.eq(false))
.count()
.first::<i64>(conn)
.ok()
.unwrap_or(0) != 0
}}
match CollectionUser::find_by_collection_and_user(&self.uuid, user_uuid, conn).await {
None => (), // Not in Org
Some(collection_user) => {
if !collection_user.read_only {
return true;
}
}
}
for collection_group in CollectionGroup::find_by_collection_and_user(&self.uuid, user_uuid, conn).await {
if !collection_group.read_only {
return true;
}
}
return false
}
}
}
Expand All @@ -315,17 +318,20 @@ impl Collection {
if user_org.has_full_access() {
return false;
}

db_run! { conn: {
users_collections::table
.filter(users_collections::collection_uuid.eq(&self.uuid))
.filter(users_collections::user_uuid.eq(user_uuid))
.filter(users_collections::hide_passwords.eq(true))
.count()
.first::<i64>(conn)
.ok()
.unwrap_or(0) != 0
}}
match CollectionUser::find_by_collection_and_user(&self.uuid, user_uuid, conn).await {
None => (), // Not in Org
Some(collection_user) => {
if collection_user.hide_passwords {
return false;
}
}
}
for collection_group in CollectionGroup::find_by_collection_and_user(&self.uuid, user_uuid, conn).await {
if collection_group.hide_passwords {
return false;
}
}
return true
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/db/models/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,24 @@ impl CollectionGroup {
}}
}

pub async fn find_by_collection_and_user(collection_uuid: &str, user_uuid: &str, conn: &mut DbConn) -> Vec<Self> {
db_run! { conn: {
collections_groups::table
.filter(collections_groups::collections_uuid.eq(collection_uuid))
.inner_join(groups_users::table.on(
groups_users::groups_uuid.eq(collections_groups::groups_uuid)
))
.inner_join(users_organizations::table.on(
users_organizations::uuid.eq(groups_users::users_organizations_uuid)
))
.filter(users_organizations::user_uuid.eq(user_uuid))
.select(collections_groups::all_columns)
.load::<CollectionGroupDb>(conn)
.expect("Error loading user collection groups")
.from_db()
}}
}

pub async fn find_by_collection(collection_uuid: &str, conn: &mut DbConn) -> Vec<Self> {
db_run! { conn: {
collections_groups::table
Expand Down

0 comments on commit c1f5283

Please sign in to comment.