• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.is_org_context函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中seahub.utils.is_org_context函数的典型用法代码示例。如果您正苦于以下问题:Python is_org_context函数的具体用法?Python is_org_context怎么用?Python is_org_context使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了is_org_context函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: share_to_group

def share_to_group(request, repo, group, permission):
    """Share repo to group with given permission.
    """
    repo_id = repo.id
    group_id = group.id
    from_user = request.user.username

    if is_org_context(request):
        org_id = request.user.org.org_id
        group_repo_ids = seafile_api.get_org_group_repoids(org_id, group.id)
    else:
        group_repo_ids = seafile_api.get_group_repoids(group.id)

    if repo.id in group_repo_ids:
        return False

    try:
        if is_org_context(request):
            org_id = request.user.org.org_id
            seafile_api.add_org_group_repo(repo_id, org_id, group_id,
                                           from_user, permission)
        else:
            seafile_api.set_group_repo(repo_id, group_id, from_user,
                                       permission)
        return True
    except Exception, e:
        logger.error(e)
        return False
开发者ID:insky2005,项目名称:seahub,代码行数:28,代码来源:views.py


示例2: share_to_group

def share_to_group(request, repo, group, permission):
    """Share repo to group with given permission.
    """
    repo_id = repo.id
    group_id = group.id
    group_name = group.group_name
    from_user = request.user.username

    if is_org_context(request):
        org_id = request.user.org.org_id
        group_repo_ids = seafile_api.get_org_group_repoids(org_id, group.id)
    else:
        group_repo_ids = seafile_api.get_group_repoids(group.id)
    if repo.id in group_repo_ids:
        msg = _(u'"%(repo)s" is already in group %(group)s. <a href="%(href)s">View</a>') % {
            'repo': repo.name, 'group': group.group_name,
            'href': reverse('group_info', args=[group.id])}
        messages.error(request, msg)
        return

    try:
        if is_org_context(request):
            org_id = request.user.org.org_id
            seafile_api.add_org_group_repo(repo_id, org_id, group_id,
                                           from_user, permission)
        else:
            seafile_api.set_group_repo(repo_id, group_id, from_user,
                                       permission)
    except Exception, e:
        logger.error(e)
        msg = _(u'Failed to share %(repo)s to %(group)s, please try again later.') % \
            {'repo': repo.name, 'group': group_name}
        messages.error(request, msg)
开发者ID:allo-,项目名称:seahub,代码行数:33,代码来源:views.py


示例3: share_to_user

def share_to_user(request, repo, to_user, permission):
    """Share repo to a user with given permission.
    """
    repo_id = repo.id
    from_user = request.user.username

    if from_user == to_user:
        return False

    # permission check
    if is_org_context(request):
        org_id = request.user.org.org_id
        if not seaserv.ccnet_threaded_rpc.org_user_exists(org_id, to_user):
            return False
    else:
        if not is_registered_user(to_user):
            return False

    try:
        if is_org_context(request):
            org_id = request.user.org.org_id
            org_share_repo(org_id, repo_id, from_user, to_user, permission)
        else:
            seafile_api.share_repo(repo_id, from_user, to_user, permission)
    except SearpcError as e:
            return False
            logger.error(e)
    else:
        # send a signal when sharing repo successful
        share_repo_to_user_successful.send(sender=None,
                                           from_user=from_user,
                                           to_user=to_user, repo=repo)
        return True
开发者ID:insky2005,项目名称:seahub,代码行数:33,代码来源:views.py


示例4: get

    def get(self, request, format=None):
        """ List all shared out folders.

        Permission checking:
        1. all authenticated user can perform this action.
        """

        shared_repos = []
        username = request.user.username

        try:
            if is_org_context(request):
                org_id = request.user.org.org_id
                shared_repos += seafile_api.get_org_share_out_repo_list(org_id, username, -1, -1)
                shared_repos += seaserv.seafserv_threaded_rpc.get_org_group_repos_by_owner(org_id, username)
            else:
                shared_repos += seafile_api.get_share_out_repo_list(username, -1, -1)
                shared_repos += seafile_api.get_group_repos_by_owner(username)
        except Exception as e:
            logger.error(e)
            error_msg = 'Internal Server Error'
            return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

        returned_result = []
        shared_repos.sort(lambda x, y: cmp(x.repo_name, y.repo_name))
        for repo in shared_repos:
            if not repo.is_virtual:
                    continue

            result = {}
            result['repo_id'] = repo.origin_repo_id
            result['repo_name'] = repo.origin_repo_name
            result['path'] = repo.origin_path
            result['folder_name'] = repo.name
            result['share_type'] = repo.share_type
            result['share_permission'] = repo.permission

            if repo.share_type == 'personal':
                result['user_name'] = email2nickname(repo.user)
                result['user_email'] = repo.user
                result['contact_email'] = Profile.objects.get_contact_email_by_user(repo.user)

            if repo.share_type == 'group':
                group = ccnet_api.get_group(repo.group_id)

                if not group:
                    if is_org_context(request):
                        seafile_api.org_unshare_subdir_for_group(org_id,
                                repo.repo_id, repo.origin_path, username, repo.group_id)
                    else:
                        seafile_api.unshare_subdir_for_group(
                                repo.repo_id, repo.origin_path, username, repo.group_id)
                    continue

                result['group_id'] = repo.group_id
                result['group_name'] = group.group_name

            returned_result.append(result)

        return Response(returned_result)
开发者ID:haiwen,项目名称:seahub,代码行数:60,代码来源:shared_folders.py


示例5: unsetinnerpub

def unsetinnerpub(request, repo_id):
    """Unshare repos in organization or in share admin page.

    Only system admin, organization admin or repo owner can perform this op.
    """
    repo = get_repo(repo_id)
    perm = request.GET.get('permission', None)
    if perm is None:
        return render_error(request, _(u'Argument is not valid'))
    if not repo:
        messages.error(request, _('Failed to unshare the library, as it does not exist.'))
        return HttpResponseRedirect(reverse('share_admin'))

    # permission check
    username = request.user.username
    if is_org_context(request):
        org_id = request.user.org.org_id
        repo_owner = seafile_api.get_org_repo_owner(repo.id)
        is_repo_owner = True if repo_owner == username else False
        if not (request.user.org.is_staff or is_repo_owner):
            raise Http404
    else:
        repo_owner = seafile_api.get_repo_owner(repo.id)
        is_repo_owner = True if repo_owner == username else False
        if not (request.user.is_staff or is_repo_owner):
            raise Http404

    try:
        if is_org_context(request):
            org_id = request.user.org.org_id
            seaserv.seafserv_threaded_rpc.unset_org_inner_pub_repo(org_id,
                                                                   repo.id)
        else:
            seaserv.unset_inner_pub_repo(repo.id)

            origin_repo_id, origin_path = get_origin_repo_info(repo.id)
            if origin_repo_id is not None:
                perm_repo_id = origin_repo_id
                perm_path = origin_path
            else:
                perm_repo_id = repo.id
                perm_path =  '/'

            send_perm_audit_msg('delete-repo-perm', username, 'all',
                                perm_repo_id, perm_path, perm)

        messages.success(request, _('Unshare "%s" successfully.') % repo.name)
    except SearpcError:
        messages.error(request, _('Failed to unshare "%s".') % repo.name)

    referer = request.META.get('HTTP_REFERER', None)
    next = settings.SITE_ROOT if referer is None else referer

    return HttpResponseRedirect(next)
开发者ID:littlehei,项目名称:seahub,代码行数:54,代码来源:__init__.py


示例6: get_shared_link

def get_shared_link(request):
    """
    Handle ajax request to generate file or dir shared link.
    """
    content_type = 'application/json; charset=utf-8'

    repo_id = request.GET.get('repo_id', '')
    share_type = request.GET.get('type', 'f')  # `f` or `d`
    path = request.GET.get('p', '')
    use_passwd = True if int(request.POST.get('use_passwd', '0')) == 1 else False
    passwd = request.POST.get('passwd') if use_passwd else None

    try:
        expire_days = int(request.POST.get('expire_days', 0))
    except ValueError:
        expire_days = 0
    if expire_days <= 0:
        expire_date = None
    else:
        expire_date = timezone.now() + relativedelta(days=expire_days)

    if not (repo_id and path):
        err = _('Invalid arguments')
        data = json.dumps({'error': err})
        return HttpResponse(data, status=400, content_type=content_type)

    if share_type != 'f' and path == '/':
        err = _('You cannot share the library in this way.')
        data = json.dumps({'error': err})
        return HttpResponse(data, status=400, content_type=content_type)

    username = request.user.username
    if share_type == 'f':
        fs = FileShare.objects.get_file_link_by_path(username, repo_id, path)
        if fs is None:
            fs = FileShare.objects.create_file_link(username, repo_id, path,
                                                    passwd, expire_date)
            if is_org_context(request):
                org_id = request.user.org.org_id
                OrgFileShare.objects.set_org_file_share(org_id, fs)
    else:
        fs = FileShare.objects.get_dir_link_by_path(username, repo_id, path)
        if fs is None:
            fs = FileShare.objects.create_dir_link(username, repo_id, path,
                                                   passwd, expire_date)
            if is_org_context(request):
                org_id = request.user.org.org_id
                OrgFileShare.objects.set_org_file_share(org_id, fs)

    token = fs.token
    shared_link = gen_shared_link(token, fs.s_type)
    data = json.dumps({'token': token, 'shared_link': shared_link})
    return HttpResponse(data, status=200, content_type=content_type)
开发者ID:allo-,项目名称:seahub,代码行数:53,代码来源:views.py


示例7: get_group_repos_by_owner

def get_group_repos_by_owner(request):
    username = request.user.username
    if is_org_context(request):
        org_id = request.user.org.org_id
        return get_org_group_repos_by_owner(org_id, username)
    else:
        return seaserv.get_group_repos_by_owner(username)
开发者ID:disk42-com,项目名称:seahub,代码行数:7,代码来源:views.py


示例8: repo_has_been_shared_out

def repo_has_been_shared_out(request, repo_id):

    has_been_shared_out = False
    username = request.user.username

    if is_org_context(request):
        org_id = request.user.org.org_id

        is_inner_org_pub_repo = False
        # check if current repo is pub-repo
        org_pub_repos = seafile_api.list_org_inner_pub_repos_by_owner(
                org_id, username)
        for org_pub_repo in org_pub_repos:
            if repo_id == org_pub_repo.id:
                is_inner_org_pub_repo = True
                break

        if seafile_api.org_repo_has_been_shared(repo_id, including_groups=True) or is_inner_org_pub_repo:
            has_been_shared_out = True
    else:
        if seafile_api.repo_has_been_shared(repo_id, including_groups=True) or \
                (not request.cloud_mode and seafile_api.is_inner_pub_repo(repo_id)):
            has_been_shared_out = True

    return has_been_shared_out
开发者ID:haiwen,项目名称:seahub,代码行数:25,代码来源:repo.py


示例9: delete

    def delete(self, request, repo_id, org_id, format=None):
        """ Delete repo user share permission.

        Permission checking:
        1. is group admin
        """

        # parameter check
        to_user = request.data.get('username', None)
        if not to_user:
            error_msg = 'username invalid.'
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        # permission check
        repo_owner = get_repo_owner(request, repo_id)
        group_id = get_group_id_by_repo_owner(repo_owner)
        username = request.user.username
        if not is_group_admin(group_id, username):
            error_msg = 'Permission denied.'
            return api_error(status.HTTP_403_FORBIDDEN, error_msg)

        path = request.data.get('path', '/')
        SeafileAPI.delete_shared_user_by_repo_path(
            repo_id, repo_owner, to_user, path, org_id=org_id)

        permission = check_user_share_out_permission(repo_id, path, to_user, is_org_context(request))
        send_perm_audit_msg('delete-repo-perm', username, to_user,
                            repo_id, path, permission)

        return Response({'success': True})
开发者ID:haiwen,项目名称:seahub,代码行数:30,代码来源:group_owned_libraries.py


示例10: get_unencry_rw_repos_by_user

def get_unencry_rw_repos_by_user(request):
    """Get all unencrypted repos a logged-in user can read and write.
    """
    username = request.user.username
    if not username:
        return []

    def has_repo(repos, repo):
        for r in repos:
            if repo.id == r.id:
                return True
        return False

    org_id = request.user.org.org_id if is_org_context(request) else None
    owned_repos, shared_repos, groups_repos, public_repos = get_user_repos(
        username, org_id=org_id)

    accessible_repos = []

    for r in owned_repos:
        if not has_repo(accessible_repos, r) and not r.encrypted:
            accessible_repos.append(r)

    for r in shared_repos + groups_repos + public_repos:
        if not has_repo(accessible_repos, r) and not r.encrypted:
            if check_folder_permission(request, r.id, '/') == 'rw':
                accessible_repos.append(r)

    return accessible_repos
开发者ID:domal,项目名称:seahub,代码行数:29,代码来源:__init__.py


示例11: rename_group_with_new_name

def rename_group_with_new_name(request, group_id, new_group_name):
    """Rename a group with new name.

    Arguments:
    - `request`:
    - `group_id`:
    - `new_group_name`:

    Raises:
        BadGroupNameError: New group name format is not valid.
        ConflictGroupNameError: New group name confilicts with existing name.
    """
    if not validate_group_name(new_group_name):
        raise BadGroupNameError

    # Check whether group name is duplicated.
    username = request.user.username
    org_id = -1
    if is_org_context(request):
        org_id = request.user.org.org_id
        checked_groups = seaserv.get_org_groups_by_user(org_id, username)
    else:
        if request.cloud_mode:
            checked_groups = seaserv.get_personal_groups_by_user(username)
        else:
            checked_groups = get_all_groups(-1, -1)

    for g in checked_groups:
        if g.group_name == new_group_name:
            raise ConflictGroupNameError

    ccnet_threaded_rpc.set_group_name(group_id, new_group_name)
开发者ID:octomike,项目名称:seahub,代码行数:32,代码来源:views.py


示例12: get

    def get(self, request):
        """ List groups that user can share a library to.
        """
        if config.ENABLE_SHARE_TO_ALL_GROUPS:
            if CUSTOM_GET_GROUPS:
                groups = custom_get_groups(request)
            else:
                groups = ccnet_api.get_all_groups(-1, -1)
        else:
            username = request.user.username
            if is_org_context(request):
                org_id = request.user.org.org_id
                groups = ccnet_api.get_org_groups_by_user(org_id, username)
            else:
                groups = ccnet_api.get_groups(username)

        try:
            avatar_size = int(request.GET.get('avatar_size',
                GROUP_AVATAR_DEFAULT_SIZE))
        except ValueError:
            avatar_size = GROUP_AVATAR_DEFAULT_SIZE

        result = [self._get_group_info(request, group, avatar_size) for group in groups]

        return Response(result)
开发者ID:haiwen,项目名称:seahub,代码行数:25,代码来源:shareable_groups.py


示例13: repo_online_gc

def repo_online_gc(request, repo_id):
    if request.method != 'POST':
        raise Http404

    repo = get_repo(repo_id)
    if not repo:
        raise Http404

    referer = request.META.get('HTTP_REFERER', None)
    next = settings.SITE_ROOT if referer is None else referer

    username = request.user.username
    if is_org_context(request):
        repo_owner = seafile_api.get_org_repo_owner(repo.id)
    else:
        repo_owner = seafile_api.get_repo_owner(repo.id)
    is_repo_owner = True if repo_owner == username else False
    if not is_repo_owner:
        messages.error(request, _('Permission denied'))
        return HttpResponseRedirect(next)

    day = int(request.POST.get('day'))
    try:
        seafile_api.clean_up_repo_history(repo.id, day)
    except SearpcError as e:
        logger.error(e)
        messages.error(request, _('Internal server error'))
        return HttpResponseRedirect(next)

    return HttpResponseRedirect(next)
开发者ID:domal,项目名称:seahub,代码行数:30,代码来源:__init__.py


示例14: get

    def get(self, request):
        """ List all groups.
        """

        org_id = None
        username = request.user.username
        if is_org_context(request):
            org_id = request.user.org.org_id
            user_groups = seaserv.get_org_groups_by_user(org_id, username)
        else:
            user_groups = seaserv.get_personal_groups_by_user(username)

        try:
            size = int(request.GET.get('avatar_size', GROUP_AVATAR_DEFAULT_SIZE))
        except ValueError:
            size = GROUP_AVATAR_DEFAULT_SIZE

        try:
            with_repos = int(request.GET.get('with_repos', 0))
        except ValueError:
            with_repos = 0

        if with_repos not in (0, 1):
            error_msg = _(u'Argument can only be 0 or 1')
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        groups = []
        for g in user_groups:
            group_info = get_group_info(request, g.id , size)

            if with_repos:
                if org_id:
                    group_repos = seafile_api.get_org_group_repos(org_id, g.id)
                else:
                    group_repos = seafile_api.get_repos_by_group(g.id)

                repos = []
                for r in group_repos:
                    repo = {
                        "id": r.id,
                        "name": r.name,
                        "desc": r.desc,
                        "size": r.size,
                        "size_formatted": filesizeformat(r.size),
                        "mtime": r.last_modified,
                        "mtime_relative": translate_seahub_time(r.last_modified),
                        "encrypted": r.encrypted,
                        "permission": r.permission,
                        "owner": r.user,
                        "owner_nickname": email2nickname(r.user),
                        "share_from_me": True if username == r.user else False,
                    }
                    repos.append(repo)

                group_info['repos'] = repos

            groups.append(group_info)

        return Response(groups)
开发者ID:ERamseth,项目名称:seahub,代码行数:59,代码来源:groups.py


示例15: post

    def post(self, request):
        """Add a group in address book.

        parent_group: -1 - no parent group;
                      > 0 - have parent group.
        group_owner: default to system admin
        group_staff: default to system admin
        """
        group_name = request.data.get('group_name', '').strip()
        if not group_name:
            error_msg = 'name %s invalid.' % group_name
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        # Check whether group name is validate.
        if not validate_group_name(group_name):
            error_msg = _(u'Name can only contain letters, numbers, blank, hyphen or underscore.')
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        # Check whether group name is duplicated.
        if check_group_name_conflict(request, group_name):
            error_msg = _(u'The name already exists.')
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        # Group owner is 'system admin'
        group_owner = request.data.get('group_owner', '')

        try:
            parent_group = int(request.data.get('parent_group', -1))
        except ValueError:
            error_msg = 'parent_group invalid'
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        if parent_group < 0 and parent_group != -1:
            error_msg = 'parent_group invalid'
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        # TODO: check parent group exists

        try:
            if is_org_context(request):
                # request called by org admin
                org_id = request.user.org.org_id
                group_id = ccnet_api.create_org_group(
                    org_id, group_name, group_owner,
                    parent_group_id=parent_group)
            else:
                group_id = ccnet_api.create_group(group_name, group_owner,
                                                  parent_group_id=parent_group)
            seafile_api.set_group_quota(group_id, -2)
        except SearpcError as e:
            logger.error(e)
            error_msg = 'Internal Server Error'
            return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

        # get info of new group
        group_info = address_book_group_to_dict(group_id)

        return Response(group_info, status=status.HTTP_200_OK)
开发者ID:haiwen,项目名称:seahub,代码行数:58,代码来源:groups.py


示例16: get_owned_repo_list

def get_owned_repo_list(request):
    """List owned repos.
    """
    username = request.user.username
    if is_org_context(request):
        org_id = request.user.org.org_id
        return seafile_api.get_org_owned_repo_list(org_id, username)
    else:
        return seafile_api.get_owned_repo_list(username)
开发者ID:domal,项目名称:seahub,代码行数:9,代码来源:__init__.py


示例17: group_add

def group_add(request):
    """Add a new group"""
    if request.method != 'POST':
        raise Http404

    username = request.user.username
    result = {}
    content_type = 'application/json; charset=utf-8'

    user_can_add_group = request.user.permissions.can_add_group()
    if not user_can_add_group:
            result['error'] = _(u'You do not have permission to create group.')
            return HttpResponse(json.dumps(result), status=403,
                                content_type=content_type)

    # check plan
    num_of_groups = getattr(request.user, 'num_of_groups', -1)
    if num_of_groups > 0:
        current_groups = len(request.user.joined_groups)
        if current_groups > num_of_groups:
            result['error'] = _(u'You can only create %d groups.<a href="http://seafile.com/">Upgrade account.</a>') % num_of_groups
            return HttpResponse(json.dumps(result), status=403,
                                content_type=content_type)

    form = GroupAddForm(request.POST)
    if form.is_valid():
        group_name = form.cleaned_data['group_name']

        # Check whether group name is duplicated.
        org_id = -1
        if is_org_context(request):
            org_id = request.user.org.org_id
            checked_groups = seaserv.get_org_groups_by_user(org_id, username)
        else:
            if request.cloud_mode:
                checked_groups = seaserv.get_personal_groups_by_user(username)
            else:
                checked_groups = get_all_groups(-1, -1)
        for g in checked_groups:
            if g.group_name == group_name:
                result['error'] = _(u'There is already a group with that name.')
                return HttpResponse(json.dumps(result), status=400,
                                    content_type=content_type)

        # Group name is valid, create that group.
        try:
            if org_id > 0:
                create_org_group(org_id, group_name, username)
            else:
                create_group(group_name, username)

            return HttpResponse(json.dumps({'success': True}),
                        content_type=content_type)
        except SearpcError, e:
            result['error'] = _(e.msg)
            return HttpResponse(json.dumps(result), status=500,
                            content_type=content_type)
开发者ID:TanLian,项目名称:seahub,代码行数:57,代码来源:views.py


示例18: get_inner_pub_repo_list

def get_inner_pub_repo_list(request):
    username = request.user.username
    if is_org_context(request):
        org_id = request.user.org.org_id
        return list_org_inner_pub_repos_by_owner(org_id, username)
    elif request.cloud_mode:
        return seaserv.list_inner_pub_repos_by_owner(username)
    else:
        return []
开发者ID:disk42-com,项目名称:seahub,代码行数:9,代码来源:views.py


示例19: get_shared_link

def get_shared_link(request):
    """
    Handle ajax request to generate file or dir shared link.
    """
    if not request.is_ajax():
        raise Http404

    content_type = 'application/json; charset=utf-8'

    repo_id = request.GET.get('repo_id', '')
    share_type = request.GET.get('type', 'f')  # `f` or `d`
    path = request.GET.get('p', '')

    if not (repo_id and path):
        err = _('Invalid arguments')
        data = json.dumps({'error': err})
        return HttpResponse(data, status=400, content_type=content_type)

    if share_type != 'f' and path == '/':
        err = _('You cannot share the library in this way.')
        data = json.dumps({'error': err})
        return HttpResponse(data, status=400, content_type=content_type)

    username = request.user.username
    if share_type == 'f':
        fs = FileShare.objects.get_file_link_by_path(username, repo_id, path)
        if fs is None:
            fs = FileShare.objects.create_file_link(username, repo_id, path)
            if is_org_context(request):
                org_id = request.user.org.org_id
                OrgFileShare.objects.set_org_file_share(org_id, fs)
    else:
        fs = FileShare.objects.get_dir_link_by_path(username, repo_id, path)
        if fs is None:
            fs = FileShare.objects.create_dir_link(username, repo_id, path)
            if is_org_context(request):
                org_id = request.user.org.org_id
                OrgFileShare.objects.set_org_file_share(org_id, fs)

    token = fs.token
    shared_link = gen_shared_link(token, fs.s_type)
    data = json.dumps({'token': token, 'shared_link': shared_link})
    return HttpResponse(data, status=200, content_type=content_type)
开发者ID:rutsky,项目名称:seahub,代码行数:43,代码来源:views.py


示例20: share_permission_admin

def share_permission_admin(request):
    """Change repo share permission in ShareAdmin.
    """
    share_type = request.GET.get('share_type', '')
    content_type = 'application/json; charset=utf-8'

    form = RepoShareForm(request.POST)
    form.is_valid()

    email_or_group = form.cleaned_data['email_or_group']
    repo_id = form.cleaned_data['repo_id']
    permission = form.cleaned_data['permission']
    from_email = request.user.username

    if share_type == 'personal':
        if not is_valid_username(email_or_group):
            return HttpResponse(json.dumps({'success': False}), status=400,
                                content_type=content_type)

        try:
            seafile_api.set_share_permission(repo_id, from_email,
                                             email_or_group, permission)
        except SearpcError:
            return HttpResponse(json.dumps({'success': False}), status=500,
                                content_type=content_type)
        return HttpResponse(json.dumps({'success': True}),
                            content_type=content_type)

    elif share_type == 'group':
        try:
            seafile_api.set_group_repo_permission(int(email_or_group),
                                                  repo_id, permission)
        except SearpcError:
            return HttpResponse(json.dumps({'success': False}), status=500,
                                content_type=content_type)
        return HttpResponse(json.dumps({'success': True}),
                            content_type=content_type)

    elif share_type == 'public':
        try:        
            if is_org_context(request):
                org_id = request.user.org.org_id
                seaserv.seafserv_threaded_rpc.set_org_inner_pub_repo(
                    org_id, repo_id, permission)
            else:
                seafile_api.add_inner_pub_repo(repo_id, permission)
        except SearpcError:
            return HttpResponse(json.dumps({'success': False}), status=500,
                                content_type=content_type)
        return HttpResponse(json.dumps({'success': True}),
                            content_type=content_type)

    else:
        return HttpResponse(json.dumps({'success': False}), status=400,
                            content_type=content_type)
开发者ID:disk42-com,项目名称:seahub,代码行数:55,代码来源:views.py



注:本文中的seahub.utils.is_org_context函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.is_pro_version函数代码示例发布时间:2022-05-27
下一篇:
Python utils.get_file_type_and_ext函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap