diff options
Diffstat (limited to 'src/db/models')
-rw-r--r-- | src/db/models/auth_request.rs | 11 | ||||
-rw-r--r-- | src/db/models/folder.rs | 3 | ||||
-rw-r--r-- | src/db/models/group.rs | 3 | ||||
-rw-r--r-- | src/db/models/org_policy.rs | 10 | ||||
-rw-r--r-- | src/db/models/send.rs | 16 |
5 files changed, 28 insertions, 15 deletions
diff --git a/src/db/models/auth_request.rs b/src/db/models/auth_request.rs index 9388c71a..3aca20cb 100644 --- a/src/db/models/auth_request.rs +++ b/src/db/models/auth_request.rs @@ -111,6 +111,17 @@ impl AuthRequest { }} } + pub async fn find_by_uuid_and_user(uuid: &str, user_uuid: &str, conn: &mut DbConn) -> Option<Self> { + db_run! {conn: { + auth_requests::table + .filter(auth_requests::uuid.eq(uuid)) + .filter(auth_requests::user_uuid.eq(user_uuid)) + .first::<AuthRequestDb>(conn) + .ok() + .from_db() + }} + } + pub async fn find_by_user(user_uuid: &str, conn: &mut DbConn) -> Vec<Self> { db_run! {conn: { auth_requests::table diff --git a/src/db/models/folder.rs b/src/db/models/folder.rs index 5370c9dd..45460720 100644 --- a/src/db/models/folder.rs +++ b/src/db/models/folder.rs @@ -120,10 +120,11 @@ impl Folder { Ok(()) } - pub async fn find_by_uuid(uuid: &str, conn: &mut DbConn) -> Option<Self> { + pub async fn find_by_uuid_and_user(uuid: &str, user_uuid: &str, conn: &mut DbConn) -> Option<Self> { db_run! { conn: { folders::table .filter(folders::uuid.eq(uuid)) + .filter(folders::user_uuid.eq(user_uuid)) .first::<FolderDb>(conn) .ok() .from_db() diff --git a/src/db/models/group.rs b/src/db/models/group.rs index e226512d..d9a08970 100644 --- a/src/db/models/group.rs +++ b/src/db/models/group.rs @@ -191,10 +191,11 @@ impl Group { }} } - pub async fn find_by_uuid(uuid: &str, conn: &mut DbConn) -> Option<Self> { + pub async fn find_by_uuid_and_org(uuid: &str, org_uuid: &str, conn: &mut DbConn) -> Option<Self> { db_run! { conn: { groups::table .filter(groups::uuid.eq(uuid)) + .filter(groups::organizations_uuid.eq(org_uuid)) .first::<GroupDb>(conn) .ok() .from_db() diff --git a/src/db/models/org_policy.rs b/src/db/models/org_policy.rs index 23e583b4..14447c05 100644 --- a/src/db/models/org_policy.rs +++ b/src/db/models/org_policy.rs @@ -142,16 +142,6 @@ impl OrgPolicy { }} } - pub async fn find_by_uuid(uuid: &str, conn: &mut DbConn) -> Option<Self> { - db_run! { conn: { - org_policies::table - .filter(org_policies::uuid.eq(uuid)) - .first::<OrgPolicyDb>(conn) - .ok() - .from_db() - }} - } - pub async fn find_by_org(org_uuid: &str, conn: &mut DbConn) -> Vec<Self> { db_run! { conn: { org_policies::table diff --git a/src/db/models/send.rs b/src/db/models/send.rs index 36944281..fb95f86b 100644 --- a/src/db/models/send.rs +++ b/src/db/models/send.rs @@ -268,9 +268,8 @@ impl Send { use data_encoding::BASE64URL_NOPAD; use uuid::Uuid; - let uuid_vec = match BASE64URL_NOPAD.decode(access_id.as_bytes()) { - Ok(v) => v, - Err(_) => return None, + let Ok(uuid_vec) = BASE64URL_NOPAD.decode(access_id.as_bytes()) else { + return None; }; let uuid = match Uuid::from_slice(&uuid_vec) { @@ -291,6 +290,17 @@ impl Send { }} } + pub async fn find_by_uuid_and_user(uuid: &str, user_uuid: &str, conn: &mut DbConn) -> Option<Self> { + db_run! {conn: { + sends::table + .filter(sends::uuid.eq(uuid)) + .filter(sends::user_uuid.eq(user_uuid)) + .first::<SendDb>(conn) + .ok() + .from_db() + }} + } + pub async fn find_by_user(user_uuid: &str, conn: &mut DbConn) -> Vec<Self> { db_run! {conn: { sends::table |