Example #1
0
    def get(self, request, org_id):
        """ Get all groups in an org.

        Permission checking:
        1. only admin can perform this action.
        """
        org_id = int(org_id)
        if org_id == 0:
            error_msg = 'org_id invalid.'
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        org = ccnet_api.get_org_by_id(org_id)
        if not org:
            error_msg = 'Organization %d not found.' % org_id
            return api_error(status.HTTP_404_NOT_FOUND, error_msg)

        try:
            groups = ccnet_api.get_org_groups(org_id, -1, -1)
        except Exception as e:
            logger.error(e)
            error_msg = "Internal Server Error"
            return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

        groups_info = []
        for group in groups:
            groups_info.append(get_org_group_info(group))

        return Response({'group_list': groups_info})
Example #2
0
    def get(self, request, org_id):
        """ Get all groups in an org.

        Permission checking:
        1. only admin can perform this action.
        """
        org_id = int(org_id)
        if org_id == 0:
            error_msg = 'org_id invalid.'
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        org = ccnet_api.get_org_by_id(org_id)
        if not org:
            error_msg = 'Organization %d not found.' % org_id
            return api_error(status.HTTP_404_NOT_FOUND, error_msg)

        try:
            groups = ccnet_api.get_org_groups(org_id, -1, -1)
        except Exception as e:
            logger.error(e)
            error_msg = "Internal Server Error"
            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 = []
        for group in groups:
            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})
Example #3
0
def get_org_detailed_info(org):
    org_id = org.org_id
    org_info = get_org_info(org)

    # users
    users = ccnet_api.get_org_emailusers(org.url_prefix, -1, -1)
    org_info['users_count'] = len(users)

    # groups
    groups = ccnet_api.get_org_groups(org_id, -1, -1)
    org_info['groups_count'] = len(groups)

    return org_info
Example #4
0
    def delete(self, request, org_id):
        """ Delete an organization

        Permission checking:
        1. only admin can perform this action.
        """

        if not MULTI_TENANCY:
            error_msg = 'Feature is not enabled.'
            return api_error(status.HTTP_403_FORBIDDEN, error_msg)

        if not request.user.admin_permissions.other_permission():
            return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied.')

        org_id = int(org_id)
        if org_id == 0:
            error_msg = 'org_id invalid.'
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        org = ccnet_api.get_org_by_id(org_id)
        if not org:
            error_msg = 'Organization %s not found.' % org_id
            return api_error(status.HTTP_404_NOT_FOUND, error_msg)

        try:
            # remove org users
            users = ccnet_api.get_org_emailusers(org.url_prefix, -1, -1)
            for u in users:
                ccnet_api.remove_org_user(org_id, u.email)
                User.objects.get(email=u.email).delete()

            # remove org groups
            groups = ccnet_api.get_org_groups(org_id, -1, -1)
            for g in groups:
                ccnet_api.remove_org_group(org_id, g.gid)

            # remove org repos
            seafile_api.remove_org_repo_by_org_id(org_id)

            # remove org
            ccnet_api.remove_org(org_id)
        except Exception as e:
            logger.error(e)
            error_msg = 'Internal Server Error'
            return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

        return Response({'success': True})
Example #5
0
def remove_org(org_id):
    org_id = int(org_id)
    org = ccnet_api.get_org_by_id(org_id)
    if org:
        users = ccnet_api.get_org_emailusers(org.url_prefix, -1, -1)
        for u in users:
            ccnet_api.remove_org_user(org_id, u.email)

        groups = ccnet_api.get_org_groups(org.org_id, -1, -1)
        for g in groups:
            ccnet_api.remove_org_group(org_id, g.gid)

        # remove org repos
        seafserv_threaded_rpc.remove_org_repo_by_org_id(org_id)

        # remove org
        ccnet_api.remove_org(org_id)
Example #6
0
def get_org_detailed_info(org):
    org_id = org.org_id
    org_info = get_org_info(org)

    # users
    users = ccnet_api.get_org_emailusers(org.url_prefix, -1, -1)
    org_info['users_count'] = len(users)

    # groups
    groups = ccnet_api.get_org_groups(org_id, -1, -1)
    org_info['groups_count'] = len(groups)

    if ORG_TRIAL_DAYS > 0:
        org_info['expiration'] = datetime.datetime.fromtimestamp(
            org.ctime / 1e6) + timedelta(days=ORG_TRIAL_DAYS)
    else:
        org_info['expiration'] = ''

    return org_info
Example #7
0
    def delete(self, request, org_id):
        """ Delete an organization

        Permission checking:
        1. only admin can perform this action.
        """

        if not (CLOUD_MODE and MULTI_TENANCY):
            error_msg = 'Feature is not enabled.'
            return api_error(status.HTTP_403_FORBIDDEN, error_msg)

        org_id = int(org_id)
        if org_id == 0:
            error_msg = 'org_id invalid.'
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        org = ccnet_api.get_org_by_id(org_id)
        if not org:
            error_msg = 'Organization %s not found.' % org_id
            return api_error(status.HTTP_404_NOT_FOUND, error_msg)

        try:
            # remove org users
            users = ccnet_api.get_org_emailusers(org.url_prefix, -1, -1)
            for u in users:
                ccnet_api.remove_org_user(org_id, u.email)

            # remove org groups
            groups = ccnet_api.get_org_groups(org_id, -1, -1)
            for g in groups:
                ccnet_api.remove_org_group(org_id, g.gid)

            # remove org repos
            seafile_api.remove_org_repo_by_org_id(org_id)

            # remove org
            ccnet_api.remove_org(org_id)
        except Exception as e:
            logger.error(e)
            error_msg = 'Internal Server Error'
            return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

        return Response({'success': True})
Example #8
0
    def get(self, request, format=None):
        """  Search group.

        Permission checking:
        1. default(NOT guest) user;
        """

        # argument check
        q = request.GET.get('q', None)
        if not q:
            error_msg = 'q invalid.'
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        # permission check
        if not self._can_use_global_address_book(request):
            error_msg = 'Permission denied.'
            return api_error(status.HTTP_403_FORBIDDEN, error_msg)

        if CLOUD_MODE:
            if is_org_context(request):
                org_id = request.user.org.org_id
                groups = ccnet_api.get_org_groups(org_id, -1, -1)
            elif settings.ENABLE_GLOBAL_ADDRESSBOOK:
                groups = ccnet_api.get_all_groups(-1, -1)
            else:
                username = request.user.username
                groups = seaserv.get_personal_groups_by_user(username)
        else:
            groups = ccnet_api.get_all_groups(-1, -1)

        result = []
        for group in groups:
            group_name = group.group_name
            if not group_name:
                continue

            if q.lower() in group_name.lower():
                group_info = get_group_info(group.id)
                result.append(group_info)

        return Response(result)
Example #9
0
    def get(self, request, format=None):
        """  Search group.

        Permission checking:
        1. default(NOT guest) user;
        """

        # argument check
        q = request.GET.get('q', None)
        if not q:
            error_msg = 'q invalid.'
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        # permission check
        if not self._can_use_global_address_book(request):
            error_msg = 'Permission denied.'
            return api_error(status.HTTP_403_FORBIDDEN, error_msg)

        if CLOUD_MODE:
            if is_org_context(request):
                org_id = request.user.org.org_id
                groups = ccnet_api.get_org_groups(org_id, -1, -1)
            elif settings.ENABLE_GLOBAL_ADDRESSBOOK:
                groups = ccnet_api.get_all_groups(-1, -1)
            else:
                username = request.user.username
                groups = ccnet_api.get_groups(username)
        else:
            groups = ccnet_api.get_all_groups(-1, -1)

        result = []
        for group in groups:
            group_name = group.group_name
            if not group_name:
                continue

            if q.lower() in group_name.lower():
                group_info = get_group_info(group.id)
                result.append(group_info)

        return Response(result)
Example #10
0
def get_org_groups(org_id, start, limit):
    return ccnet_api.get_org_groups(org_id, start, limit)