mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2025-08-19 09:15:24 +00:00
Adding some oganization features
This commit is contained in:
parent
5210f9b951
commit
c5185ddb83
5 changed files with 202 additions and 12 deletions
|
@ -65,4 +65,65 @@ impl Collection {
|
|||
.filter(collections::uuid.eq(uuid))
|
||||
.first::<Self>(&**conn).ok()
|
||||
}
|
||||
|
||||
pub fn find_by_user_uuid(uuid: &str, conn: &DbConn) -> Vec<Self> {
|
||||
match users_collections::table
|
||||
.filter(users_collections::user_uuid.eq(uuid))
|
||||
.select(users_collections::columns::collection_uuid)
|
||||
.load(&**conn) {
|
||||
Ok(uuids) => uuids.iter().map(|uuid: &String| {
|
||||
Collection::find_by_uuid(uuid, &conn).unwrap()
|
||||
}).collect(),
|
||||
Err(list) => vec![]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find_by_uuid_and_user(uuid: &str, user_uuid: &str, conn: &DbConn) -> Option<Self> {
|
||||
match users_collections::table
|
||||
.filter(users_collections::collection_uuid.eq(uuid))
|
||||
.filter(users_collections::user_uuid.eq(user_uuid))
|
||||
.first::<CollectionUsers>(&**conn).ok() {
|
||||
None => None,
|
||||
Some(collection_user) => Collection::find_by_uuid(&collection_user.collection_uuid, &conn)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use super::User;
|
||||
|
||||
#[derive(Debug, Identifiable, Queryable, Insertable, Associations)]
|
||||
#[table_name = "users_collections"]
|
||||
#[belongs_to(User, foreign_key = "user_uuid")]
|
||||
#[belongs_to(Collection, foreign_key = "collection_uuid")]
|
||||
#[primary_key(user_uuid, collection_uuid)]
|
||||
pub struct CollectionUsers {
|
||||
pub user_uuid: String,
|
||||
pub collection_uuid: String,
|
||||
}
|
||||
|
||||
/// Local methods
|
||||
impl CollectionUsers {
|
||||
pub fn new(
|
||||
user_uuid: String,
|
||||
collection_uuid: String,
|
||||
) -> Self {
|
||||
Self {
|
||||
user_uuid,
|
||||
collection_uuid,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use db::schema::users_collections;
|
||||
|
||||
/// Database methods
|
||||
impl CollectionUsers {
|
||||
pub fn save(&mut self, conn: &DbConn) -> bool {
|
||||
match diesel::replace_into(users_collections::table)
|
||||
.values(&*self)
|
||||
.execute(&**conn) {
|
||||
Ok(1) => true, // One row inserted
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,8 +12,6 @@ pub use self::cipher::Cipher;
|
|||
pub use self::device::Device;
|
||||
pub use self::folder::Folder;
|
||||
pub use self::user::User;
|
||||
|
||||
pub use self::collection::Collection;
|
||||
pub use self::organization::Organization;
|
||||
|
||||
pub use self::organization::{UserOrganization, UserOrgStatus, UserOrgType};
|
||||
pub use self::collection::{Collection, CollectionUsers};
|
||||
|
|
|
@ -6,6 +6,7 @@ use uuid::Uuid;
|
|||
use crypto;
|
||||
use CONFIG;
|
||||
|
||||
|
||||
#[derive(Debug, Identifiable, Queryable, Insertable)]
|
||||
#[table_name = "users"]
|
||||
#[primary_key(uuid)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue