mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-25 14:50:29 +00:00
org admin show traffic
This commit is contained in:
@@ -12,6 +12,8 @@ class OrgInfo extends Component {
|
|||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
org_name: '',
|
org_name: '',
|
||||||
|
traffic_this_month: '',
|
||||||
|
traffic_limit: '',
|
||||||
storage_quota: 0,
|
storage_quota: 0,
|
||||||
storage_usage: 0,
|
storage_usage: 0,
|
||||||
member_quota: 0,
|
member_quota: 0,
|
||||||
@@ -23,12 +25,12 @@ class OrgInfo extends Component {
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
orgAdminAPI.orgAdminGetOrgInfo().then(res => {
|
orgAdminAPI.orgAdminGetOrgInfo().then(res => {
|
||||||
const {
|
const {
|
||||||
org_id, org_name,
|
org_id, org_name, traffic_this_month, traffic_limit,
|
||||||
member_quota, member_usage, active_members,
|
member_quota, member_usage, active_members,
|
||||||
storage_quota, storage_usage
|
storage_quota, storage_usage
|
||||||
} = res.data;
|
} = res.data;
|
||||||
this.setState({
|
this.setState({
|
||||||
org_id, org_name,
|
org_id, org_name, traffic_this_month, traffic_limit,
|
||||||
member_quota, member_usage, active_members,
|
member_quota, member_usage, active_members,
|
||||||
storage_quota, storage_usage
|
storage_quota, storage_usage
|
||||||
});
|
});
|
||||||
@@ -37,10 +39,11 @@ class OrgInfo extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
org_id, org_name,
|
org_id, org_name, traffic_this_month, traffic_limit,
|
||||||
member_quota, member_usage, active_members,
|
member_quota, member_usage, active_members,
|
||||||
storage_quota, storage_usage
|
storage_quota, storage_usage
|
||||||
} = this.state;
|
} = this.state;
|
||||||
|
const download_traffic = traffic_this_month.link_file_download + traffic_this_month.sync_file_download + traffic_this_month.web_file_download;
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<MainPanelTopbar/>
|
<MainPanelTopbar/>
|
||||||
@@ -104,6 +107,23 @@ class OrgInfo extends Component {
|
|||||||
<p>{Utils.bytesToSize(storage_usage)}</p>
|
<p>{Utils.bytesToSize(storage_usage)}</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
<div className="info-content-item">
|
||||||
|
<h4 className="info-content-item-heading">{gettext('Traffic this month')}</h4>
|
||||||
|
{traffic_limit > 0 ? (
|
||||||
|
<>
|
||||||
|
<p className="info-content-space-text">{`${(download_traffic / traffic_limit * 100).toFixed(2)}%`}</p>
|
||||||
|
<div className="progress-container">
|
||||||
|
<div className="progress">
|
||||||
|
<div className="progress-bar" role="progressbar" style={{ width: `${download_traffic / traffic_limit * 100}%` }} aria-valuenow={download_traffic / traffic_limit * 100} aria-valuemin="0" aria-valuemax="100"></div>
|
||||||
|
</div>
|
||||||
|
<p className="progress-text m-0">{`${Utils.bytesToSize(download_traffic)} / ${Utils.bytesToSize(traffic_limit)}`}</p>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<p>{Utils.bytesToSize(download_traffic)}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
# Copyright (c) 2012-2016 Seafile Ltd.
|
# Copyright (c) 2012-2016 Seafile Ltd.
|
||||||
import logging
|
import logging
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
@@ -16,12 +17,17 @@ from seahub.api2.permissions import IsProVersion
|
|||||||
from seahub.api2.throttling import UserRateThrottle
|
from seahub.api2.throttling import UserRateThrottle
|
||||||
from seahub.api2.authentication import TokenAuthentication
|
from seahub.api2.authentication import TokenAuthentication
|
||||||
|
|
||||||
from seahub.organizations.models import OrgMemberQuota, FORCE_ADFS_LOGIN, DISABLE_ORG_ENCRYPTED_LIBRARY, DISABLE_ORG_USER_CLEAN_TRASH
|
from seahub.utils import get_org_traffic_by_month
|
||||||
from seahub.utils.file_size import get_file_size_unit
|
from seahub.utils.ccnet_db import CcnetDB
|
||||||
|
from seahub.utils.file_size import get_file_size_unit, get_quota_from_string
|
||||||
|
from seahub.role_permissions.utils import get_enabled_role_permissions_by_role
|
||||||
|
|
||||||
|
from seahub.organizations.api.permissions import IsOrgAdmin
|
||||||
|
from seahub.organizations.models import OrgAdminSettings, \
|
||||||
|
OrgMemberQuota, FORCE_ADFS_LOGIN, DISABLE_ORG_ENCRYPTED_LIBRARY, \
|
||||||
|
DISABLE_ORG_USER_CLEAN_TRASH
|
||||||
from seahub.organizations.settings import ORG_MEMBER_QUOTA_ENABLED, \
|
from seahub.organizations.settings import ORG_MEMBER_QUOTA_ENABLED, \
|
||||||
ORG_ENABLE_ADMIN_CUSTOM_NAME
|
ORG_ENABLE_ADMIN_CUSTOM_NAME
|
||||||
from seahub.organizations.api.permissions import IsOrgAdmin
|
|
||||||
from seahub.organizations.models import OrgAdminSettings
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -84,6 +90,18 @@ def get_org_info(request, org_id):
|
|||||||
if settings.ENABLE_MULTI_ADFS is False:
|
if settings.ENABLE_MULTI_ADFS is False:
|
||||||
info[FORCE_ADFS_LOGIN] = False
|
info[FORCE_ADFS_LOGIN] = False
|
||||||
|
|
||||||
|
current_date = datetime.now()
|
||||||
|
info['traffic_this_month'] = get_org_traffic_by_month(org_id, current_date)
|
||||||
|
|
||||||
|
info['traffic_limit'] = ''
|
||||||
|
role_perm_dict = get_enabled_role_permissions_by_role()
|
||||||
|
monthly_rate_limit_per_user = role_perm_dict.get('monthly_rate_limit_per_user', '')
|
||||||
|
if monthly_rate_limit_per_user:
|
||||||
|
ccnet_db = CcnetDB()
|
||||||
|
user_count = ccnet_db.get_org_user_count(org_id)
|
||||||
|
traffic_limit = get_quota_from_string(monthly_rate_limit_per_user) * user_count
|
||||||
|
info['traffic_limit'] = traffic_limit
|
||||||
|
|
||||||
info['storage_quota'] = storage_quota
|
info['storage_quota'] = storage_quota
|
||||||
info['storage_usage'] = storage_usage
|
info['storage_usage'] = storage_usage
|
||||||
info['user_default_quota'] = user_default_quota
|
info['user_default_quota'] = user_default_quota
|
||||||
|
@@ -47,6 +47,8 @@ DEFAULT_ENABLED_ROLE_PERMISSIONS = {
|
|||||||
'can_publish_wiki': True,
|
'can_publish_wiki': True,
|
||||||
'upload_rate_limit': 0,
|
'upload_rate_limit': 0,
|
||||||
'download_rate_limit': 0,
|
'download_rate_limit': 0,
|
||||||
|
'monthly_rate_limit': '',
|
||||||
|
'monthly_rate_limit_per_user': ''
|
||||||
},
|
},
|
||||||
GUEST_USER: {
|
GUEST_USER: {
|
||||||
'can_add_repo': False,
|
'can_add_repo': False,
|
||||||
@@ -70,6 +72,8 @@ DEFAULT_ENABLED_ROLE_PERMISSIONS = {
|
|||||||
'can_publish_wiki': False,
|
'can_publish_wiki': False,
|
||||||
'upload_rate_limit': 0,
|
'upload_rate_limit': 0,
|
||||||
'download_rate_limit': 0,
|
'download_rate_limit': 0,
|
||||||
|
'monthly_rate_limit': '',
|
||||||
|
'monthly_rate_limit_per_user': ''
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -14,12 +14,9 @@ def get_available_roles():
|
|||||||
return list(ENABLED_ROLE_PERMISSIONS.keys())
|
return list(ENABLED_ROLE_PERMISSIONS.keys())
|
||||||
|
|
||||||
|
|
||||||
def get_enabled_role_permissions_by_role(role):
|
def get_enabled_role_permissions_by_role(role=DEFAULT_USER):
|
||||||
"""Get permissions dict(perm_name: bool) of a role.
|
"""Get permissions dict(perm_name: bool) of a role.
|
||||||
"""
|
"""
|
||||||
if not role:
|
|
||||||
role = DEFAULT_USER
|
|
||||||
|
|
||||||
if role not in list(ENABLED_ROLE_PERMISSIONS.keys()):
|
if role not in list(ENABLED_ROLE_PERMISSIONS.keys()):
|
||||||
logger.warn('%s is not a valid role, use default role.' % role)
|
logger.warn('%s is not a valid role, use default role.' % role)
|
||||||
role = DEFAULT_USER
|
role = DEFAULT_USER
|
||||||
|
@@ -852,6 +852,11 @@ if EVENTS_CONFIG_FILE:
|
|||||||
res = seafevents_api.get_user_traffic_by_month(session, username, month)
|
res = seafevents_api.get_user_traffic_by_month(session, username, month)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def get_org_traffic_by_month(org_id, month):
|
||||||
|
with _get_seafevents_session() as session:
|
||||||
|
res = seafevents_api.get_org_traffic_by_month(session, org_id, month)
|
||||||
|
return res
|
||||||
|
|
||||||
def get_file_history_suffix():
|
def get_file_history_suffix():
|
||||||
return seafevents_api.get_file_history_suffix(parsed_events_conf)
|
return seafevents_api.get_file_history_suffix(parsed_events_conf)
|
||||||
|
|
||||||
@@ -871,6 +876,8 @@ else:
|
|||||||
pass
|
pass
|
||||||
def get_user_traffic_by_month():
|
def get_user_traffic_by_month():
|
||||||
pass
|
pass
|
||||||
|
def get_org_traffic_by_month():
|
||||||
|
pass
|
||||||
def get_user_activity_stats_by_day():
|
def get_user_activity_stats_by_day():
|
||||||
pass
|
pass
|
||||||
def get_org_user_activity_stats_by_day():
|
def get_org_user_activity_stats_by_day():
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
import os
|
import os
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
|
|
||||||
|
|
||||||
def get_ccnet_db_name():
|
def get_ccnet_db_name():
|
||||||
return os.environ.get('SEAFILE_MYSQL_DB_CCNET_DB_NAME', '') or 'ccnet_db'
|
return os.environ.get('SEAFILE_MYSQL_DB_CCNET_DB_NAME', '') or 'ccnet_db'
|
||||||
|
|
||||||
@@ -200,3 +201,13 @@ class CcnetDB:
|
|||||||
active_users.append(user[0])
|
active_users.append(user[0])
|
||||||
|
|
||||||
return active_users
|
return active_users
|
||||||
|
|
||||||
|
def get_org_user_count(self, org_id):
|
||||||
|
sql = f"""
|
||||||
|
SELECT COUNT(1) FROM `{self.db_name}`.`OrgUser` WHERE org_id={org_id}
|
||||||
|
"""
|
||||||
|
user_count = 0
|
||||||
|
with connection.cursor() as cursor:
|
||||||
|
cursor.execute(sql)
|
||||||
|
user_count = cursor.fetchone()[0]
|
||||||
|
return user_count
|
||||||
|
@@ -48,6 +48,8 @@ def get_quota_from_string(quota_str):
|
|||||||
quota = int(quota_str[:-1]) * get_file_size_unit('gb')
|
quota = int(quota_str[:-1]) * get_file_size_unit('gb')
|
||||||
elif quota_str.endswith('m'):
|
elif quota_str.endswith('m'):
|
||||||
quota = int(quota_str[:-1]) * get_file_size_unit('mb')
|
quota = int(quota_str[:-1]) * get_file_size_unit('mb')
|
||||||
|
elif quota_str.endswith('k'):
|
||||||
|
quota = int(quota_str[:-1]) * get_file_size_unit('kb')
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user