mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-01 23:38:37 +00:00
update sysinfo page
This commit is contained in:
parent
9a9b6eb9e1
commit
38a06be960
@ -14,6 +14,7 @@ from seahub.utils.licenseparse import parse_license
|
||||
|
||||
from seahub.api2.authentication import TokenAuthentication
|
||||
from seahub.api2.throttling import UserRateThrottle
|
||||
from seahub.api2.models import TokenV2
|
||||
|
||||
try:
|
||||
from seahub.settings import MULTI_TENANCY
|
||||
@ -87,6 +88,7 @@ class SysInfo(APIView):
|
||||
inactive_users = inactive_db_users + inactive_ldap_users if inactive_ldap_users > 0 \
|
||||
else inactive_db_users
|
||||
|
||||
# get license info
|
||||
is_pro = is_pro_version()
|
||||
if is_pro:
|
||||
license_dict = parse_license()
|
||||
@ -104,10 +106,39 @@ class SysInfo(APIView):
|
||||
with_license = False
|
||||
max_users = 0
|
||||
|
||||
# count total file number
|
||||
try:
|
||||
total_files_count = seafile_api.get_total_file_number()
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
total_files_count = 0
|
||||
|
||||
# count total storage
|
||||
try:
|
||||
total_storage = seafile_api.get_total_storage()
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
total_storage = 0
|
||||
|
||||
# count devices number
|
||||
try:
|
||||
total_devices_count = TokenV2.objects.get_total_devices_count()
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
total_devices_count = 0
|
||||
|
||||
# count current connected devices
|
||||
try:
|
||||
current_connected_devices_count = TokenV2.objects.get_current_connected_devices_count()
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
current_connected_devices_count= 0
|
||||
|
||||
info = {
|
||||
'users_count': active_users + inactive_users,
|
||||
'active_users_count': active_users,
|
||||
'repos_count': repos_count,
|
||||
'total_files_count': total_files_count,
|
||||
'groups_count': groups_count,
|
||||
'org_count': org_count,
|
||||
'multi_tenancy_enabled': multi_tenancy_enabled,
|
||||
@ -116,6 +147,9 @@ class SysInfo(APIView):
|
||||
'license_expiration': license_dict.get('Expiration', ''),
|
||||
'license_maxusers': max_users,
|
||||
'license_to': license_dict.get('Name', ''),
|
||||
'total_storage': total_storage,
|
||||
'total_devices_count': total_devices_count,
|
||||
'current_connected_devices_count': current_connected_devices_count,
|
||||
}
|
||||
|
||||
return Response(info)
|
||||
|
@ -2,7 +2,6 @@
|
||||
import uuid
|
||||
import hmac
|
||||
import datetime
|
||||
import time
|
||||
from hashlib import sha1
|
||||
|
||||
from django.db import models
|
||||
@ -46,6 +45,19 @@ class TokenV2Manager(models.Manager):
|
||||
|
||||
return devices
|
||||
|
||||
def get_total_devices_count(self):
|
||||
devices = super(TokenV2Manager, self).filter(wiped_at=None)
|
||||
return len(devices)
|
||||
|
||||
def get_current_connected_devices_count(self):
|
||||
# get number of devices last one hour accessed
|
||||
devices = super(TokenV2Manager, self).filter(wiped_at=None)
|
||||
date_from = datetime.datetime.now() - datetime.timedelta(hours=1)
|
||||
|
||||
# greater than or equal to.
|
||||
results = devices.filter(last_accessed__gte=date_from)
|
||||
return len(results)
|
||||
|
||||
def get_user_devices(self, username):
|
||||
'''List user devices, most recently used first'''
|
||||
devices = super(TokenV2Manager, self).filter(user=username).filter(wiped_at=None)
|
||||
|
@ -19,7 +19,7 @@ from seahub.auth import login
|
||||
from seahub.constants import DEFAULT_USER
|
||||
from seahub.profile.models import Profile, DetailedProfile
|
||||
from seahub.role_permissions.utils import get_enabled_role_permissions_by_role
|
||||
from seahub.utils import is_valid_username, is_user_password_strong, \
|
||||
from seahub.utils import is_user_password_strong, \
|
||||
clear_token, get_system_admins
|
||||
from seahub.utils.mail import send_html_email_with_dj_template, MAIL_PRIORITY
|
||||
from seahub.utils.licenseparse import user_number_over_limit
|
||||
|
@ -3,8 +3,7 @@ import os
|
||||
import datetime
|
||||
import hashlib
|
||||
import logging
|
||||
import json
|
||||
from django.db import models, IntegrityError
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
||||
from pysearpc import SearpcError
|
||||
|
@ -106,8 +106,14 @@
|
||||
<% } %>
|
||||
</dd>
|
||||
|
||||
<dt>{% trans "Libraries" %}</dt>
|
||||
<dd><%- repos_count %></dd>
|
||||
<dt>{% trans "Libraries" %} / {% trans "Files" %}</dt>
|
||||
<dd><%- repos_count %> / <%- total_files_count %></dd>
|
||||
|
||||
<dt>{% trans "Storage Used" %}</dt>
|
||||
<dd><%- formatted_storage %></dd>
|
||||
|
||||
<dt>{% trans "Total Devices" %} / {% trans "Current Connected Devices" %}</dt>
|
||||
<dd><%- total_devices_count %> / <%- current_connected_devices_count %></dd>
|
||||
|
||||
<% if (is_pro) { %>
|
||||
<dt>{% trans "Active Users" %} / {% trans "Total Users" %} / {% trans "Limits" %}</dt>
|
||||
|
@ -903,6 +903,34 @@ define([
|
||||
}
|
||||
},
|
||||
|
||||
quotaSizeFormat: function(bytes, precision) {
|
||||
var kilobyte = 1000;
|
||||
var megabyte = kilobyte * 1000;
|
||||
var gigabyte = megabyte * 1000;
|
||||
var terabyte = gigabyte * 1000;
|
||||
|
||||
var precision = precision || 0;
|
||||
|
||||
if ((bytes >= 0) && (bytes < kilobyte)) {
|
||||
return bytes + ' B';
|
||||
|
||||
} else if ((bytes >= kilobyte) && (bytes < megabyte)) {
|
||||
return (bytes / kilobyte).toFixed(precision) + ' KB';
|
||||
|
||||
} else if ((bytes >= megabyte) && (bytes < gigabyte)) {
|
||||
return (bytes / megabyte).toFixed(precision) + ' MB';
|
||||
|
||||
} else if ((bytes >= gigabyte) && (bytes < terabyte)) {
|
||||
return (bytes / gigabyte).toFixed(precision) + ' GB';
|
||||
|
||||
} else if (bytes >= terabyte) {
|
||||
return (bytes / terabyte).toFixed(precision) + ' TB';
|
||||
|
||||
} else {
|
||||
return bytes + ' B';
|
||||
}
|
||||
},
|
||||
|
||||
groupId2Name: function(group_id) {
|
||||
var group_name;
|
||||
var groups = app.pageOptions.groups;
|
||||
|
@ -61,7 +61,9 @@ define([
|
||||
|
||||
reset: function() {
|
||||
this.$loadingTip.hide();
|
||||
this.$sysinfo.html(this.template(this.sysinfo.toJSON()));
|
||||
var json_data = this.sysinfo.toJSON();
|
||||
json_data['formatted_storage'] = Common.quotaSizeFormat(json_data['total_storage'], 1)
|
||||
this.$sysinfo.html(this.template(json_data));
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -22,7 +22,7 @@ class SysinfoTest(BaseTestCase):
|
||||
resp = self.client.get(url)
|
||||
json_resp = json.loads(resp.content)
|
||||
|
||||
assert len(json_resp) == 11
|
||||
assert len(json_resp) == 15
|
||||
assert json_resp['is_pro'] is False
|
||||
assert json_resp['multi_tenancy_enabled'] is False
|
||||
assert json_resp['license_maxusers'] == 0
|
||||
@ -49,6 +49,6 @@ class SysinfoTest(BaseTestCase):
|
||||
resp = self.client.get(url)
|
||||
json_resp = json.loads(resp.content)
|
||||
|
||||
assert len(json_resp) == 11
|
||||
assert len(json_resp) == 15
|
||||
assert json_resp['license_maxusers'] == 500
|
||||
assert json_resp['license_to'] == test_user
|
||||
|
Loading…
Reference in New Issue
Block a user