diff --git a/frontend/src/components/dialog/transfer-dialog.js b/frontend/src/components/dialog/transfer-dialog.js index fbd08544c9..8ff6db7e60 100644 --- a/frontend/src/components/dialog/transfer-dialog.js +++ b/frontend/src/components/dialog/transfer-dialog.js @@ -34,11 +34,11 @@ class TransferDialog extends React.Component { } componentDidMount() { - seafileAPI.shareableGroups().then((res) => { + seafileAPI.listDepartments().then((res) => { for (let i = 0 ; i < res.data.length; i++) { let obj = {}; obj.value = res.data[i].name; - obj.email = `${res.data[i].id}@seafile_group`; + obj.email = res.data[i].email; obj.label = res.data[i].name; this.options.push(obj); } diff --git a/seahub/api2/endpoints/all_departments.py b/seahub/api2/endpoints/all_departments.py new file mode 100644 index 0000000000..7f4eb006fd --- /dev/null +++ b/seahub/api2/endpoints/all_departments.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- + +import logging +from rest_framework.authentication import SessionAuthentication +from rest_framework.permissions import IsAuthenticated +from rest_framework.response import Response +from rest_framework.views import APIView +from rest_framework import status + +import seaserv +from seaserv import ccnet_api + +from seahub.api2.utils import api_error +from seahub.api2.authentication import TokenAuthentication +from seahub.api2.throttling import UserRateThrottle +from seahub.avatar.templatetags.group_avatar_tags import api_grp_avatar_url, get_default_group_avatar_url +from seahub.utils.timeutils import timestamp_to_isoformat_timestr +from seahub.avatar.settings import GROUP_AVATAR_DEFAULT_SIZE + +logger = logging.getLogger(__name__) + + +class AllDepartments(APIView): + + authentication_classes = (TokenAuthentication, SessionAuthentication) + permission_classes = (IsAuthenticated,) + throttle_classes = (UserRateThrottle, ) + + def get(self, request): + """list all departments + """ + + try: + departments = ccnet_api.list_all_departments() + except Exception as e: + logger.error(e) + error_msg = 'Internal Server Error' + return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) + + try: + avatar_size = int(request.GET.get('avatar_size', GROUP_AVATAR_DEFAULT_SIZE)) + except ValueError: + avatar_size = GROUP_AVATAR_DEFAULT_SIZE + + result = [] + for department in departments: + department = seaserv.get_group(department.id) + + try: + avatar_url, is_default, date_uploaded = api_grp_avatar_url(department.id, avatar_size) + except Exception as e: + logger.error(e) + avatar_url = get_default_group_avatar_url() + + created_at = timestamp_to_isoformat_timestr(department.timestamp) + + department_info = { + "id": department.id, + "email": '%s@seafile_group' % str(department.id), + "parent_group_id": department.parent_group_id, + "name": department.group_name, + "owner": department.creator_name, + "created_at": created_at, + "avatar_url": request.build_absolute_uri(avatar_url), + } + + result.append(department_info) + + return Response(result) diff --git a/seahub/api2/views.py b/seahub/api2/views.py index a00262817d..3601100538 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -1586,9 +1586,14 @@ class RepoOwner(APIView): error_msg = 'Email %s invalid.' % new_owner return api_error(status.HTTP_400_BAD_REQUEST, error_msg) else: - seafile_api.set_repo_owner(repo_id, new_owner) + if '@seafile_group' in new_owner: + group_id = int(new_owner.split('@')[0]) + seafile_api.transfer_repo_to_group(repo_id, group_id, '') + else: + seafile_api.set_repo_owner(repo_id, new_owner) except SearpcError as e: logger.error(e) + print e error_msg = 'Internal Server Error' return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) diff --git a/seahub/urls.py b/seahub/urls.py index 71636fe4f1..baf1050e16 100644 --- a/seahub/urls.py +++ b/seahub/urls.py @@ -23,6 +23,7 @@ from seahub.views.wiki import personal_wiki, personal_wiki_pages, \ from seahub.api2.endpoints.smart_link import SmartLink, SmartLinkToken from seahub.api2.endpoints.groups import Groups, Group from seahub.api2.endpoints.all_groups import AllGroups +from seahub.api2.endpoints.all_departments import AllDepartments from seahub.api2.endpoints.shareable_groups import ShareableGroups from seahub.api2.endpoints.group_libraries import GroupLibraries, GroupLibrary @@ -254,6 +255,9 @@ urlpatterns = [ url(r'^api/v2.1/smart-link/$', SmartLink.as_view(), name="api-v2.1-smart-link"), url(r'^api/v2.1/smart-links/(?P[-0-9a-f]{36})/$', SmartLinkToken.as_view(), name="api-v2.1-smart-links-token"), + # departments + url(r'api/v2.1/all-departments/$', AllDepartments.as_view(), name='api-v2.1-all-departments'), + ## user::groups url(r'^api/v2.1/all-groups/$', AllGroups.as_view(), name='api-v2.1-all-groups'), url(r'^api/v2.1/shareable-groups/$', ShareableGroups.as_view(), name='api-v2.1-shareable-groups'),