mirror of
https://github.com/haiwen/seahub.git
synced 2025-07-12 22:49:15 +00:00
add field in sysadmin org group and repo api (#4161)
This commit is contained in:
parent
b2f2d85f0d
commit
5ad35b3e9e
@ -12,7 +12,9 @@ from seahub.api2.authentication import TokenAuthentication
|
|||||||
from seahub.api2.throttling import UserRateThrottle
|
from seahub.api2.throttling import UserRateThrottle
|
||||||
from seahub.api2.utils import api_error
|
from seahub.api2.utils import api_error
|
||||||
from seahub.api2.permissions import IsProVersion
|
from seahub.api2.permissions import IsProVersion
|
||||||
|
from seahub.utils import is_pro_version
|
||||||
from seahub.utils.timeutils import timestamp_to_isoformat_timestr
|
from seahub.utils.timeutils import timestamp_to_isoformat_timestr
|
||||||
|
from seahub.base.templatetags.seahub_tags import email2nickname, email2contact_email
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from seahub.settings import ORG_MEMBER_QUOTA_ENABLED
|
from seahub.settings import ORG_MEMBER_QUOTA_ENABLED
|
||||||
@ -22,16 +24,6 @@ except ImportError:
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def get_org_group_info(group):
|
|
||||||
group_info = {}
|
|
||||||
group_info['group_name'] = group.group_name
|
|
||||||
group_info['creator_name'] = group.creator_name
|
|
||||||
group_info['created_at'] = timestamp_to_isoformat_timestr(group.timestamp)
|
|
||||||
group_info['group_id'] = group.id
|
|
||||||
|
|
||||||
return group_info
|
|
||||||
|
|
||||||
|
|
||||||
class AdminOrgGroups(APIView):
|
class AdminOrgGroups(APIView):
|
||||||
|
|
||||||
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||||
@ -61,8 +53,27 @@ class AdminOrgGroups(APIView):
|
|||||||
error_msg = "Internal Server Error"
|
error_msg = "Internal Server Error"
|
||||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
|
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
|
||||||
|
|
||||||
|
# Use dict to reduce memcache fetch cost in large for-loop.
|
||||||
|
nickname_dict = {}
|
||||||
|
contact_email_dict = {}
|
||||||
|
creator_name_set = set([g.creator_name for g in groups])
|
||||||
|
for e in creator_name_set:
|
||||||
|
if e not in nickname_dict:
|
||||||
|
nickname_dict[e] = email2nickname(e)
|
||||||
|
if e not in contact_email_dict:
|
||||||
|
contact_email_dict[e] = email2contact_email(e)
|
||||||
|
|
||||||
groups_info = []
|
groups_info = []
|
||||||
for group in groups:
|
for group in groups:
|
||||||
groups_info.append(get_org_group_info(group))
|
group_info = {}
|
||||||
|
group_info['group_name'] = group.group_name
|
||||||
|
group_info['creator_email'] = group.creator_name
|
||||||
|
group_info['creator_name'] = nickname_dict.get(group.creator_name, '')
|
||||||
|
group_info['creator_contact_email'] = contact_email_dict.get(group.creator_name, '')
|
||||||
|
group_info['created_at'] = timestamp_to_isoformat_timestr(group.timestamp)
|
||||||
|
group_info['parent_group_id'] = group.parent_group_id if is_pro_version() else 0
|
||||||
|
group_info['group_id'] = group.id
|
||||||
|
|
||||||
|
groups_info.append(group_info)
|
||||||
|
|
||||||
return Response({'group_list': groups_info})
|
return Response({'group_list': groups_info})
|
||||||
|
@ -22,15 +22,6 @@ except ImportError:
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def get_org_repo_info(repo):
|
|
||||||
repo_info = {}
|
|
||||||
repo_info['repo_name'] = repo.repo_name
|
|
||||||
repo_info['owner_email'] = seafile_api.get_org_repo_owner(repo.id)
|
|
||||||
repo_info['repo_id'] = repo.id
|
|
||||||
|
|
||||||
return repo_info
|
|
||||||
|
|
||||||
|
|
||||||
class AdminOrgRepos(APIView):
|
class AdminOrgRepos(APIView):
|
||||||
|
|
||||||
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||||
@ -60,8 +51,27 @@ class AdminOrgRepos(APIView):
|
|||||||
error_msg = "Internal Server Error"
|
error_msg = "Internal Server Error"
|
||||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
|
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
|
||||||
|
|
||||||
|
# Use dict to reduce memcache fetch cost in large for-loop.
|
||||||
|
repo_id_2_email_dict = {repo.id: seafile_api.get_org_repo_owner(repo.id) for repo in repos}
|
||||||
|
owner_email_set = set(repo_id_2_email_dict.values())
|
||||||
|
nickname_dict = {}
|
||||||
|
contact_email_dict = {}
|
||||||
|
for e in owner_email_set:
|
||||||
|
if e not in nickname_dict:
|
||||||
|
nickname_dict[e] = email2nickname(e)
|
||||||
|
if e not in contact_email_dict:
|
||||||
|
contact_email_dict[e] = email2contact_email(e)
|
||||||
|
|
||||||
repos_info = []
|
repos_info = []
|
||||||
for repo in repos:
|
for repo in repos:
|
||||||
repos_info.append(get_org_repo_info(repo))
|
repo_info = {}
|
||||||
|
repo_info['repo_name'] = repo.repo_name
|
||||||
|
owner_email = repo_id_2_email_dict.get(repo.id, '')
|
||||||
|
repo_info['owner_email'] = owner_email
|
||||||
|
repo_info['owner_name'] = nickname_dict.get(owner_email, '')
|
||||||
|
repo_info['owner_contact_email'] = contact_email_dict.get(owner_email, '')
|
||||||
|
repo_info['repo_id'] = repo.id
|
||||||
|
|
||||||
|
repos_info.append(repo_info)
|
||||||
|
|
||||||
return Response({'repo_list': repos_info})
|
return Response({'repo_list': repos_info})
|
||||||
|
Loading…
Reference in New Issue
Block a user