Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group support #2667

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ab6f3c7
migration scripts added
MFijak Jul 27, 2022
891f4c8
enable UI group support
MFijak Jul 27, 2022
68cfd90
schema added
MFijak Jul 27, 2022
5a53041
Db CRUD operations and API endpoints implemented
MFijak Jul 29, 2022
ad7e6bf
load assigned group collections for user
MFijak Jul 29, 2022
073daeb
revision update implemented
MFijak Jul 29, 2022
82091bd
fixes for mysql, sqlite
MFijak Aug 1, 2022
064a1e3
cipher readonly, hide_passwords
MFijak Aug 1, 2022
39d078a
use cipher sync data if possible
MFijak Aug 2, 2022
827bf4c
fix for group collections
MFijak Aug 2, 2022
11cc5a7
collection endpoint support for groups implemented
MFijak Aug 2, 2022
25764eb
Table and two variables renamed
MFijak Aug 2, 2022
c08f893
respect groups when deleting & adding collections
MFijak Aug 2, 2022
35f528e
fix clippy warnings
MFijak Aug 3, 2022
c6a707a
fix cargo fmt
MFijak Aug 3, 2022
72de021
converted to HashMap
MFijak Aug 8, 2022
274ad68
bugfix
MFijak Aug 8, 2022
ef35960
Merge branch 'main' into group_support
MFijak Sep 16, 2022
45acec7
Post merge conflicts cleanup
MFijak Sep 16, 2022
10bbf7d
Fix migration postgresql script
MFijak Sep 16, 2022
85e82b3
group: external id is now optional
MFijak Sep 16, 2022
63a08f1
Update to APIResult
MFijak Sep 16, 2022
909477a
Switched to ApiResult<T>
MFijak Sep 16, 2022
0da96ca
group full access cached
MFijak Sep 17, 2022
cab9252
simplified access flag appending
MFijak Sep 17, 2022
6b54891
Merge branch 'main' into group_support
MFijak Sep 26, 2022
d6ae0a4
Merge branch 'main' into group_support
MFijak Oct 10, 2022
3edf35f
Merge branch 'main' into group_support
MFijak Oct 18, 2022
7ac0b92
Merge branch 'main' into group_support
MFijak Oct 20, 2022
30869f6
Merge branch 'dani-garcia:main' into group_support
MFijak Oct 20, 2022
10d038e
removed whitespaces
MFijak Oct 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions migrations/mysql/2022-07-27-110000_add_group_support/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DROP TABLE `groups`;
DROP TABLE groups_users;
DROP TABLE collections_groups;
23 changes: 23 additions & 0 deletions migrations/mysql/2022-07-27-110000_add_group_support/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CREATE TABLE `groups` (
uuid CHAR(36) NOT NULL PRIMARY KEY,
organizations_uuid VARCHAR(40) NOT NULL REFERENCES organizations (uuid),
name VARCHAR(100) NOT NULL,
access_all BOOLEAN NOT NULL,
external_id VARCHAR(300) NULL,
creation_date DATETIME NOT NULL,
revision_date DATETIME NOT NULL
);

CREATE TABLE groups_users (
groups_uuid CHAR(36) NOT NULL REFERENCES `groups` (uuid),
users_organizations_uuid VARCHAR(36) NOT NULL REFERENCES users_organizations (uuid),
UNIQUE (groups_uuid, users_organizations_uuid)
);

CREATE TABLE collections_groups (
collections_uuid VARCHAR(40) NOT NULL REFERENCES collections (uuid),
groups_uuid CHAR(36) NOT NULL REFERENCES `groups` (uuid),
read_only BOOLEAN NOT NULL,
hide_passwords BOOLEAN NOT NULL,
UNIQUE (collections_uuid, groups_uuid)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DROP TABLE groups;
DROP TABLE groups_users;
DROP TABLE collections_groups;
23 changes: 23 additions & 0 deletions migrations/postgresql/2022-07-27-110000_add_group_support/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CREATE TABLE groups (
uuid CHAR(36) NOT NULL PRIMARY KEY,
organizations_uuid VARCHAR(40) NOT NULL REFERENCES organizations (uuid),
name VARCHAR(100) NOT NULL,
access_all BOOLEAN NOT NULL,
external_id VARCHAR(300) NULL,
creation_date TIMESTAMP NOT NULL,
revision_date TIMESTAMP NOT NULL
);

CREATE TABLE groups_users (
groups_uuid CHAR(36) NOT NULL REFERENCES groups (uuid),
users_organizations_uuid VARCHAR(36) NOT NULL REFERENCES users_organizations (uuid),
PRIMARY KEY (groups_uuid, users_organizations_uuid)
);

CREATE TABLE collections_groups (
collections_uuid VARCHAR(40) NOT NULL REFERENCES collections (uuid),
groups_uuid CHAR(36) NOT NULL REFERENCES groups (uuid),
read_only BOOLEAN NOT NULL,
hide_passwords BOOLEAN NOT NULL,
PRIMARY KEY (collections_uuid, groups_uuid)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DROP TABLE groups;
DROP TABLE groups_users;
DROP TABLE collections_groups;
23 changes: 23 additions & 0 deletions migrations/sqlite/2022-07-27-110000_add_group_support/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CREATE TABLE groups (
uuid TEXT NOT NULL PRIMARY KEY,
organizations_uuid TEXT NOT NULL REFERENCES organizations (uuid),
name TEXT NOT NULL,
access_all BOOLEAN NOT NULL,
external_id TEXT NULL,
creation_date TIMESTAMP NOT NULL,
revision_date TIMESTAMP NOT NULL
);

CREATE TABLE groups_users (
groups_uuid TEXT NOT NULL REFERENCES groups (uuid),
users_organizations_uuid TEXT NOT NULL REFERENCES users_organizations (uuid),
UNIQUE (groups_uuid, users_organizations_uuid)
);

CREATE TABLE collections_groups (
collections_uuid TEXT NOT NULL REFERENCES collections (uuid),
groups_uuid TEXT NOT NULL REFERENCES groups (uuid),
read_only BOOLEAN NOT NULL,
hide_passwords BOOLEAN NOT NULL,
UNIQUE (collections_uuid, groups_uuid)
);
14 changes: 14 additions & 0 deletions src/api/core/ciphers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,8 @@ pub struct CipherSyncData {
pub cipher_collections: HashMap<String, Vec<String>>,
pub user_organizations: HashMap<String, UserOrganization>,
pub user_collections: HashMap<String, CollectionUser>,
pub user_collections_groups: HashMap<String, CollectionGroup>,
pub user_group_full_access_for_organizations: HashSet<String>,
}

pub enum CipherSyncType {
Expand Down Expand Up @@ -1554,13 +1556,25 @@ impl CipherSyncData {
.collect()
.await;

// Generate a HashMap with the collections_uuid as key and the CollectionGroup record
let user_collections_groups = stream::iter(CollectionGroup::find_by_user(user_uuid, conn).await)
.map(|collection_group| (collection_group.collections_uuid.clone(), collection_group))
.collect()
.await;

// Get all organizations that the user has full access to via group assignement
let user_group_full_access_for_organizations =
stream::iter(Group::gather_user_organizations_full_access(user_uuid, conn).await).collect().await;

Self {
cipher_attachments,
cipher_folders,
cipher_favorites,
cipher_collections,
user_organizations,
user_collections,
user_collections_groups,
user_group_full_access_for_organizations,
}
}
}
Loading