1
0
Fork 0

Updated Organizations overview

- Changed HTML to match users overview
- Added User count
- Added Org cipher amount
- Added Attachment count and size
Dieser Commit ist enthalten in:
BlackDex 2020-06-03 20:37:31 +02:00
Ursprung 2fffaec226
Commit ac2723f898
6 geänderte Dateien mit 73 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -15,6 +15,7 @@ use crate::config::ConfigBuilder;
use crate::db::{backup_database, models::*, DbConn}; use crate::db::{backup_database, models::*, DbConn};
use crate::error::Error; use crate::error::Error;
use crate::mail; use crate::mail;
use crate::util::get_display_size;
use crate::CONFIG; use crate::CONFIG;
pub fn routes() -> Vec<Route> { pub fn routes() -> Vec<Route> {
@ -253,8 +254,6 @@ 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| {
@ -312,7 +311,14 @@ fn update_revision_users(_token: AdminToken, conn: DbConn) -> EmptyResult {
#[get("/organizations/overview")] #[get("/organizations/overview")]
fn organizations_overview(_token: AdminToken, conn: DbConn) -> ApiResult<Html<String>> { fn organizations_overview(_token: AdminToken, conn: DbConn) -> ApiResult<Html<String>> {
let organizations = Organization::get_all(&conn); let organizations = Organization::get_all(&conn);
let organizations_json: Vec<Value> = organizations.iter().map(|o| o.to_json()).collect(); let organizations_json: Vec<Value> = organizations.iter().map(|o| {
let mut org = o.to_json();
org["user_count"] = json!(UserOrganization::count_by_org(&o.uuid, &conn));
org["cipher_count"] = json!(Cipher::count_by_org(&o.uuid, &conn));
org["attachment_count"] = json!(Attachment::count_by_org(&o.uuid, &conn));
org["attachment_size"] = json!(get_display_size(Attachment::size_by_org(&o.uuid, &conn) as i32));
org
}).collect();
let text = AdminTemplateData::organizations(organizations_json).render()?; let text = AdminTemplateData::organizations(organizations_json).render()?;
Ok(Html(text)) Ok(Html(text))

Datei anzeigen

@ -150,4 +150,14 @@ impl Attachment {
result.unwrap_or(0) result.unwrap_or(0)
} }
pub fn count_by_org(org_uuid: &str, conn: &DbConn) -> i64 {
attachments::table
.left_join(ciphers::table.on(ciphers::uuid.eq(attachments::cipher_uuid)))
.filter(ciphers::organization_uuid.eq(org_uuid))
.count()
.first(&**conn)
.ok()
.unwrap_or(0)
}
} }

Datei anzeigen

@ -370,6 +370,15 @@ impl Cipher {
.load::<Self>(&**conn).expect("Error loading ciphers") .load::<Self>(&**conn).expect("Error loading ciphers")
} }
pub fn count_by_org(org_uuid: &str, conn: &DbConn) -> i64 {
ciphers::table
.filter(ciphers::organization_uuid.eq(org_uuid))
.count()
.first::<i64>(&**conn)
.ok()
.unwrap_or(0)
}
pub fn find_by_folder(folder_uuid: &str, conn: &DbConn) -> Vec<Self> { pub fn find_by_folder(folder_uuid: &str, conn: &DbConn) -> Vec<Self> {
folders_ciphers::table.inner_join(ciphers::table) folders_ciphers::table.inner_join(ciphers::table)
.filter(folders_ciphers::folder_uuid.eq(folder_uuid)) .filter(folders_ciphers::folder_uuid.eq(folder_uuid))

Datei anzeigen

@ -437,6 +437,15 @@ impl UserOrganization {
.expect("Error loading user organizations") .expect("Error loading user organizations")
} }
pub fn count_by_org(org_uuid: &str, conn: &DbConn) -> i64 {
users_organizations::table
.filter(users_organizations::org_uuid.eq(org_uuid))
.count()
.first::<i64>(&**conn)
.ok()
.unwrap_or(0)
}
pub fn find_by_org_and_type(org_uuid: &str, atype: i32, conn: &DbConn) -> Vec<Self> { pub fn find_by_org_and_type(org_uuid: &str, atype: i32, conn: &DbConn) -> Vec<Self> {
users_organizations::table users_organizations::table
.filter(users_organizations::org_uuid.eq(org_uuid)) .filter(users_organizations::org_uuid.eq(org_uuid))

Datei anzeigen

@ -2,24 +2,45 @@
<div id="organizations-block" class="my-3 p-3 bg-white rounded shadow"> <div id="organizations-block" class="my-3 p-3 bg-white rounded shadow">
<h6 class="border-bottom pb-2 mb-0">Organizations</h6> <h6 class="border-bottom pb-2 mb-0">Organizations</h6>
<div id="organizations-list"> <div class="table-responsive-xl small">
{{#each organizations}} <table class="table table-sm table-striped table-hover">
<div class="media pt-3"> <thead>
<img class="mr-2 rounded identicon" data-src="{{Name}}_{{BillingEmail}}"> <tr>
<div class="media-body pb-3 mb-0 small border-bottom"> <th style="width: 24px;" colspan="2">Organization</th>
<div class="row justify-content-between"> <th>Users</th>
<div class="col"> <th>Items</th>
<th>Attachments</th>
</tr>
</thead>
<tbody>
{{#each organizations}}
<tr>
<td><img class="rounded identicon" data-src="{{Id}}"></td>
<td>
<strong>{{Name}}</strong> <strong>{{Name}}</strong>
{{#if Id}} <span class="mr-2">({{BillingEmail}})</span>
<span class="badge badge-success ml-2">{{Id}}</span> <span class="d-block">
<span class="badge badge-success">{{Id}}</span>
</span>
</td>
<td>
<span class="d-block">{{user_count}}</span>
</td>
<td>
<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}} {{/if}}
<span class="d-block">{{BillingEmail}}</span> </td>
</div> </tr>
</div> {{/each}}
</div> </tbody>
</div> </table>
{{/each}}
</div> </div>
</div> </div>
</main> </main>

Datei anzeigen

@ -2,8 +2,6 @@
<div id="users-block" class="my-3 p-3 bg-white rounded shadow"> <div id="users-block" class="my-3 p-3 bg-white rounded shadow">
<h6 class="border-bottom pb-2 mb-0">Registered Users</h6> <h6 class="border-bottom pb-2 mb-0">Registered Users</h6>
<div class="table-responsive-xl small"> <div class="table-responsive-xl small">
<table class="table table-sm table-striped table-hover"> <table class="table table-sm table-striped table-hover">
<thead> <thead>