diff options
author | BlackDex <[email protected]> | 2020-06-03 17:57:03 +0200 |
---|---|---|
committer | BlackDex <[email protected]> | 2020-06-03 17:57:03 +0200 |
commit | 2fffaec226e2dcfb9b013aa985049e368b88f368 (patch) | |
tree | 81c378742bdf9cf27c11b53ed610af169930f3dd | |
parent | 5c54dfee3adabe4e070dd02020ac3d96972bdec0 (diff) | |
download | vaultwarden-2fffaec226e2dcfb9b013aa985049e368b88f368.tar.gz vaultwarden-2fffaec226e2dcfb9b013aa985049e368b88f368.zip |
Added attachment info per user and some layout fix
- Added the amount and size of the attachments per user
- Changed the items count function a bit
- Some small layout changes
-rw-r--r-- | src/api/admin.rs | 8 | ||||
-rw-r--r-- | src/db/models/attachment.rs | 10 | ||||
-rw-r--r-- | src/db/models/cipher.rs | 3 | ||||
-rw-r--r-- | src/static/templates/admin/users.hbs | 9 |
4 files changed, 25 insertions, 5 deletions
diff --git a/src/api/admin.rs b/src/api/admin.rs index 46338a9c..4921c30a 100644 --- a/src/api/admin.rs +++ b/src/api/admin.rs @@ -253,13 +253,15 @@ fn get_users_json(_token: AdminToken, conn: DbConn) -> JsonResult { #[get("/users/overview")] fn users_overview(_token: AdminToken, conn: DbConn) -> ApiResult<Html<String>> { + use crate::util::get_display_size; + let users = User::get_all(&conn); let users_json: Vec<Value> = users.iter() .map(|u| { let mut usr = u.to_json(&conn); - if let Some(ciphers) = Cipher::count_owned_by_user(&u.uuid, &conn) { - usr["cipher_count"] = json!(ciphers); - }; + usr["cipher_count"] = json!(Cipher::count_owned_by_user(&u.uuid, &conn)); + usr["attachment_count"] = json!(Attachment::count_by_user(&u.uuid, &conn)); + usr["attachment_size"] = json!(get_display_size(Attachment::size_by_user(&u.uuid, &conn) as i32)); usr }).collect(); diff --git a/src/db/models/attachment.rs b/src/db/models/attachment.rs index f0efa93a..58f893bc 100644 --- a/src/db/models/attachment.rs +++ b/src/db/models/attachment.rs @@ -130,6 +130,16 @@ impl Attachment { result.unwrap_or(0) } + pub fn count_by_user(user_uuid: &str, conn: &DbConn) -> i64 { + attachments::table + .left_join(ciphers::table.on(ciphers::uuid.eq(attachments::cipher_uuid))) + .filter(ciphers::user_uuid.eq(user_uuid)) + .count() + .first::<i64>(&**conn) + .ok() + .unwrap_or(0) + } + pub fn size_by_org(org_uuid: &str, conn: &DbConn) -> i64 { let result: Option<i64> = attachments::table .left_join(ciphers::table.on(ciphers::uuid.eq(attachments::cipher_uuid))) diff --git a/src/db/models/cipher.rs b/src/db/models/cipher.rs index 94d7d1ec..2fb09c00 100644 --- a/src/db/models/cipher.rs +++ b/src/db/models/cipher.rs @@ -355,12 +355,13 @@ impl Cipher { .load::<Self>(&**conn).expect("Error loading ciphers") } - pub fn count_owned_by_user(user_uuid: &str, conn: &DbConn) -> Option<i64> { + pub fn count_owned_by_user(user_uuid: &str, conn: &DbConn) -> i64 { ciphers::table .filter(ciphers::user_uuid.eq(user_uuid)) .count() .first::<i64>(&**conn) .ok() + .unwrap_or(0) } pub fn find_by_org(org_uuid: &str, conn: &DbConn) -> Vec<Self> { diff --git a/src/static/templates/admin/users.hbs b/src/static/templates/admin/users.hbs index 758031fc..297a04f0 100644 --- a/src/static/templates/admin/users.hbs +++ b/src/static/templates/admin/users.hbs @@ -10,7 +10,8 @@ <tr> <th style="width: 24px;">User</th> <th></th> - <th style="width:90px; min-width: 90px;">Items</th> + <th style="width:60px; min-width: 60px;">Items</th> + <th>Attachments</th> <th style="min-width: 140px;">Organizations</th> <th style="width: 140px; min-width: 140px;">Actions</th> </tr> @@ -38,6 +39,12 @@ <span class="d-block">{{cipher_count}}</span> </td> <td> + <span class="d-block"><strong>Amount:</strong> {{attachment_count}}</span> + {{#if attachment_count}} + <span class="d-block"><strong>Size:</strong> {{attachment_size}}</span> + {{/if}} + </td> + <td> {{#each Organizations}} <span class="badge badge-primary" data-orgtype="{{Type}}">{{Name}}</span> {{/each}} |