mirror of
https://github.com/ViViDboarder/bitwarden_rs.git
synced 2024-11-22 13:16:39 +00:00
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
This commit is contained in:
parent
5c54dfee3a
commit
2fffaec226
@ -253,13 +253,15 @@ fn get_users_json(_token: AdminToken, conn: DbConn) -> JsonResult {
|
|||||||
|
|
||||||
#[get("/users/overview")]
|
#[get("/users/overview")]
|
||||||
fn users_overview(_token: AdminToken, conn: DbConn) -> ApiResult<Html<String>> {
|
fn users_overview(_token: AdminToken, conn: DbConn) -> ApiResult<Html<String>> {
|
||||||
|
use crate::util::get_display_size;
|
||||||
|
|
||||||
let users = User::get_all(&conn);
|
let users = User::get_all(&conn);
|
||||||
let users_json: Vec<Value> = users.iter()
|
let users_json: Vec<Value> = users.iter()
|
||||||
.map(|u| {
|
.map(|u| {
|
||||||
let mut usr = u.to_json(&conn);
|
let mut usr = u.to_json(&conn);
|
||||||
if let Some(ciphers) = Cipher::count_owned_by_user(&u.uuid, &conn) {
|
usr["cipher_count"] = json!(Cipher::count_owned_by_user(&u.uuid, &conn));
|
||||||
usr["cipher_count"] = json!(ciphers);
|
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
|
usr
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
|
@ -130,6 +130,16 @@ impl Attachment {
|
|||||||
result.unwrap_or(0)
|
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 {
|
pub fn size_by_org(org_uuid: &str, conn: &DbConn) -> i64 {
|
||||||
let result: Option<i64> = attachments::table
|
let result: Option<i64> = attachments::table
|
||||||
.left_join(ciphers::table.on(ciphers::uuid.eq(attachments::cipher_uuid)))
|
.left_join(ciphers::table.on(ciphers::uuid.eq(attachments::cipher_uuid)))
|
||||||
|
@ -355,12 +355,13 @@ impl Cipher {
|
|||||||
.load::<Self>(&**conn).expect("Error loading ciphers")
|
.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
|
ciphers::table
|
||||||
.filter(ciphers::user_uuid.eq(user_uuid))
|
.filter(ciphers::user_uuid.eq(user_uuid))
|
||||||
.count()
|
.count()
|
||||||
.first::<i64>(&**conn)
|
.first::<i64>(&**conn)
|
||||||
.ok()
|
.ok()
|
||||||
|
.unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_by_org(org_uuid: &str, conn: &DbConn) -> Vec<Self> {
|
pub fn find_by_org(org_uuid: &str, conn: &DbConn) -> Vec<Self> {
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th style="width: 24px;">User</th>
|
<th style="width: 24px;">User</th>
|
||||||
<th></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="min-width: 140px;">Organizations</th>
|
||||||
<th style="width: 140px; min-width: 140px;">Actions</th>
|
<th style="width: 140px; min-width: 140px;">Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -37,6 +38,12 @@
|
|||||||
<td>
|
<td>
|
||||||
<span class="d-block">{{cipher_count}}</span>
|
<span class="d-block">{{cipher_count}}</span>
|
||||||
</td>
|
</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>
|
<td>
|
||||||
{{#each Organizations}}
|
{{#each Organizations}}
|
||||||
<span class="badge badge-primary" data-orgtype="{{Type}}">{{Name}}</span>
|
<span class="badge badge-primary" data-orgtype="{{Type}}">{{Name}}</span>
|
||||||
|
Loading…
Reference in New Issue
Block a user