当前位置: 首页>>代码示例>>Python>>正文


Python seaserv.is_group_user函数代码示例

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


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

示例1: group_message_remove

def group_message_remove(request, group_id, msg_id):
    """
    Remove group message and all message replies and attachments.
    """
    # Checked by URL Conf
    group_id_int = int(group_id)
    msg_id = int(msg_id)
    group = get_group(group_id_int)
    if not group:
        raise Http404

    # Test whether user is in the group
    if not is_group_user(group_id_int, request.user.username):
        raise Http404

    try:
        gm = GroupMessage.objects.get(id=msg_id)
    except GroupMessage.DoesNotExist:
        return HttpResponse(
            json.dumps({"success": False, "err_msg": _(u"The message doesn't exist")}),
            content_type="application/json; charset=utf-8",
        )
    else:
        # Test whether user is group admin or message owner.
        if seaserv.check_group_staff(group_id, request.user.username) or gm.from_email == request.user.username:
            gm.delete()
            return HttpResponse(json.dumps({"success": True}), content_type="application/json; charset=utf-8")
        else:
            return HttpResponse(
                json.dumps({"success": False, "err_msg": _(u"You don't have the permission.")}),
                content_type="application/json; charset=utf-8",
            )
开发者ID:octomike,项目名称:seahub,代码行数:32,代码来源:views.py

示例2: group_recommend

def group_recommend(request):
    """
    Recommend a file or directory to a group.
    """
    if request.method != 'POST':
        raise Http404

    next = request.META.get('HTTP_REFERER', None)
    if not next:
        next = SITE_ROOT
    
    form = GroupRecommendForm(request.POST)
    if form.is_valid():
        repo_id = form.cleaned_data['repo_id']
        attach_type = form.cleaned_data['attach_type']
        path = form.cleaned_data['path']
        message = form.cleaned_data['message']
        groups = request.POST.getlist('groups') # groups is a group_id list, e.g. [u'1', u'7']
        username = request.user.username

        # Check group id format
        for group_id in groups:
            try:
                group_id = int(group_id)
            except ValueError:
                messages.error(request, _(u'Error: wrong group id'))
                return HttpResponseRedirect(next)

            # Get that group
            group = get_group(group_id)

            # TODO: Check whether repo is in the group and Im in the group
            if not is_group_user(group_id, username):
                err_msg = _(u'Error: you are not in group %s.')
                messages.error(request, err_msg %  group.group_name)
                continue

            # save message to group
            gm = GroupMessage(group_id=group_id, from_email=username,
                              message=message)
            gm.save()

            # send signal
            grpmsg_added.send(sender=GroupMessage, group_id=group_id,
                              from_email=request.user.username)
                    
            # save attachment
            ma = MessageAttachment(group_message=gm, repo_id=repo_id,
                                   attach_type=attach_type, path=path,
                                   src='recommend')
            ma.save()

            group_url = reverse('group_info', args=[group_id])
            msg = _(u'Successfully recommended to <a href="%(url)s" target="_blank">%(name)s</a>.') %\
                {'url':group_url, 'name':group.group_name}
            messages.add_message(request, messages.INFO, msg)

    else:
        messages.add_message(request, messages.ERROR, _(u'Failed to recommend.'))
    return HttpResponseRedirect(next)
开发者ID:chuyskywalker,项目名称:seahub,代码行数:60,代码来源:views.py

示例3: _decorated

    def _decorated(view, request, group_id, *args, **kwargs):
        group_id = int(group_id) # Checked by URL Conf
        try:
            group = seaserv.get_group(group_id)
        except SearpcError as e:
            logger.error(e)
            error_msg = _(u'Internal Server Error')
            return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

        if not group:
            error_msg = _(u'Group does not exist.')
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        username = request.user.username
        try:
            is_group_member = seaserv.is_group_user(group_id,
                                                    username)
        except SearpcError as e:
            logger.error(e)
            error_msg = _(u'Internal Server Error')
            return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

        if not is_group_member:
            error_msg = _(u'Permission denied')
            return api_error(status.HTTP_403_FORBIDDEN, error_msg)

        return func(view, request, group_id, *args, **kwargs)
开发者ID:ERamseth,项目名称:seahub,代码行数:27,代码来源:utils.py

示例4: post

    def post(self, request, email, format=None):
        # migrate an account's repos and groups to an exist account
        if not is_valid_username(email):
            return api_error(status.HTTP_400_BAD_REQUEST, 'Email %s invalid.' % email)

        op = request.data.get('op', '').lower()
        if op == 'migrate':
            from_user = email
            to_user = request.data.get('to_user', '')
            if not is_valid_username(to_user):
                return api_error(status.HTTP_400_BAD_REQUEST, 'Email %s invalid.' % to_user)

            try:
                user2 = User.objects.get(email=to_user)
            except User.DoesNotExist:
                return api_error(status.HTTP_404_NOT_FOUND, 'User %s not found.' % to_user)

            # transfer owned repos to new user
            for r in seafile_api.get_owned_repo_list(from_user):
                seafile_api.set_repo_owner(r.id, user2.username)

            # transfer joined groups to new user
            for g in seaserv.get_personal_groups_by_user(from_user):
                if not seaserv.is_group_user(g.id, user2.username):
                    # add new user to the group on behalf of the group creator
                    ccnet_threaded_rpc.group_add_member(g.id, g.creator_name,
                                                        to_user)

                if from_user == g.creator_name:
                    ccnet_threaded_rpc.set_group_creator(g.id, to_user)

            return Response("success")
        else:
            return api_error(status.HTTP_400_BAD_REQUEST, 'op can only be migrate.')
开发者ID:RaphaelWimmer,项目名称:seahub,代码行数:34,代码来源:account.py

示例5: _decorated

    def _decorated(view, request, group_id, *args, **kwargs):
        group_id_int = int(group_id) # Checked by URL Conf
        group = get_group(group_id_int)
        if not group:
            return api_error(status.HTTP_404_NOT_FOUND, 'Group not found.')
        group.is_staff = False
        if PublicGroup.objects.filter(group_id=group.id):
            group.is_pub = True
        else:
            group.is_pub = False

        joined = is_group_user(group_id_int, request.user.username)
        if joined:
            group.view_perm = "joined"
            group.is_staff = is_group_staff(group, request.user)
            return func(view, request, group, *args, **kwargs)
        if request.user.is_staff:
            # viewed by system admin
            group.view_perm = "sys_admin"
            return func(view, request, group, *args, **kwargs)

        if group.is_pub:
            group.view_perm = "pub"
            return func(view, request, group, *args, **kwargs)

        # Return group public info page.
        return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to access this group.')
开发者ID:RaphaelWimmer,项目名称:seahub,代码行数:27,代码来源:utils.py

示例6: get_shared_groups_by_repo_and_user

def get_shared_groups_by_repo_and_user(repo_id, username):
    """Get all groups which this repo is shared.
    """
    repo_shared_groups = seaserv.get_shared_groups_by_repo(repo_id)

    # Filter out groups that user is joined.
    groups = [x for x in repo_shared_groups if seaserv.is_group_user(x.id, username)]
    return groups
开发者ID:biddyweb,项目名称:seahub,代码行数:8,代码来源:repo.py

示例7: create_group_repo

def create_group_repo(request, group_id):
    """Create a repo and share it to current group"""

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

    def json_error(err_msg):
        result = {'error': [err_msg]}
        return HttpResponseBadRequest(json.dumps(result),
                                      content_type=content_type)
    group_id = int(group_id)
    if not get_group(group_id):
        return json_error(_(u'Failed to create: the group does not exist.'))

    # Check whether user belongs to the group.
    if not is_group_user(group_id, request.user.username):
        return json_error(_(u'Failed to create: you are not in the group.'))

    form = SharedRepoCreateForm(request.POST)
    if not form.is_valid():
        return json_error(form.errors)
    else:
        repo_name = form.cleaned_data['repo_name']
        repo_desc = form.cleaned_data['repo_desc']
        permission = form.cleaned_data['permission']
        encrypted = form.cleaned_data['encryption']
        passwd = form.cleaned_data['passwd']
        user = request.user.username

        org, base_template = check_and_get_org_by_group(group_id, user)
        if org:
            # create group repo in org context
            try:
                repo_id = create_org_repo(repo_name, repo_desc, user, passwd,
                                          org.org_id)
            except:
                repo_id = None
            if not repo_id:
                return json_error(_(u'Failed to create'))

            try:
                status = seafserv_threaded_rpc.add_org_group_repo(repo_id,
                                                                  org.org_id,
                                                                  group_id,
                                                                  user,
                                                                  permission)
            except SearpcError, e:
                status = -1
                
            # if share failed, remove the newly created repo
            if status != 0:
                seafserv_threaded_rpc.remove_repo(repo_id)
                return json_error(_(u'Failed to create: internal error.'))
            else:
                result = {'success': True}
                return HttpResponse(json.dumps(result),
                                    content_type=content_type)
        else:
开发者ID:chuyskywalker,项目名称:seahub,代码行数:57,代码来源:views.py

示例8: put

    def put(self, request, group_id):
        """ Rename, transfer a specific group
        """

        group = seaserv.get_group(group_id)
        username = request.user.username

        new_group_name = request.data.get('name', None)
        if new_group_name:
            # rename a group
            # Check whether group name is validate.
            if not validate_group_name(new_group_name):
                error_msg = _(u'Group 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, new_group_name):
                error_msg = _(u'There is already a group with that name.')
                return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

            try:
                seaserv.ccnet_threaded_rpc.set_group_name(group_id, new_group_name)
            except SearpcError as e:
                logger.error(e)
                error_msg = _(u'Internal Server Error')
                return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

        new_creator= request.data.get('creator', None)
        if new_creator:
            # transfer a group
            if not is_valid_username(new_creator):
                error_msg = _('Creator %s is not valid.') % new_creator
                return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

            if new_creator == group.creator_name:
                error_msg = _('%s is already group owner') % new_creator
                return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

            try:
                if not seaserv.is_group_user(group_id, new_creator):
                    seaserv.ccnet_threaded_rpc.group_add_member(group_id, username, new_creator)

                if not seaserv.check_group_staff(group_id, new_creator):
                    seaserv.ccnet_threaded_rpc.group_set_admin(group_id, new_creator)

                seaserv.ccnet_threaded_rpc.set_group_creator(group_id, new_creator)
            except SearpcError as e:
                logger.error(e)
                error_msg = _(u'Internal Server Error')
                return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

        # get new info of this group
        group_info = get_group_info(request, group_id, GROUP_AVATAR_DEFAULT_SIZE)

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

示例9: get_repo_shared_groups

    def get_repo_shared_groups(self):
        if self.user.org:
            org_id = self.user.org['org_id']
            repo_shared_groups = get_org_groups_by_repo(org_id, self.repo_id)
        else:
            repo_shared_groups = get_shared_groups_by_repo(self.repo_id)

        # Filter out groups that user is joined.
        groups = [ x for x in repo_shared_groups if \
                       is_group_user(x.id, self.user.username)]
        return groups
开发者ID:orymate,项目名称:seahub,代码行数:11,代码来源:repo.py

示例10: _decorated

 def _decorated(request, group_id, *args, **kwargs):
     group_id_int = int(group_id) # Checked by URL Conf
     group = get_group(group_id_int)
     if not group:
         return HttpResponseRedirect(reverse('group_list', args=[]))
     joined = is_group_user(group_id_int, request.user.username)
     if not joined and not request.user.is_staff:
         # Return group public info page.
         return render_to_response('group/group_pubinfo.html', {
                 'group': group,
                 }, context_instance=RequestContext(request))
     return func(request, group, *args, **kwargs)
开发者ID:beride,项目名称:seahub,代码行数:12,代码来源:views.py

示例11: create_group_repo

def create_group_repo(request, group_id):
    """Create a repo and share it to current group"""

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

    def json_error(err_msg):
        result = {'error': err_msg}
        return HttpResponseBadRequest(json.dumps(result),
                                      content_type=content_type)
    group_id = int(group_id)
    group = get_group(group_id)
    if not group:
        return json_error(_(u'Failed to create: the group does not exist.'))

    # Check whether user belongs to the group.
    username = request.user.username
    if not is_group_user(group_id, username):
        return json_error(_(u'Failed to create: you are not in the group.'))

    form = SharedRepoCreateForm(request.POST)
    if not form.is_valid():
        return json_error(str(form.errors.values()[0]))

    # Form is valid, create group repo
    repo_name = form.cleaned_data['repo_name']
    repo_desc = form.cleaned_data['repo_desc']
    permission = form.cleaned_data['permission']
    encryption = int(form.cleaned_data['encryption'])

    uuid = form.cleaned_data['uuid']
    magic_str = form.cleaned_data['magic_str']
    encrypted_file_key = form.cleaned_data['encrypted_file_key']

    if is_org_context(request):
        org_id = request.user.org.org_id
        try:
            if encryption:
                repo_id = seafile_api.create_org_enc_repo(
                    uuid, repo_name, repo_desc, username, magic_str,
                    encrypted_file_key, enc_version=2, org_id=org_id)
            else:
                repo_id = seafile_api.create_org_repo(repo_name, repo_desc,
                                                      username, None, org_id)
        except SearpcError, e:
            logger.error(e)
            return json_error(_(u'Failed to create'))

        try:
            seafile_api.add_org_group_repo(repo_id, org_id, group.id,
                                           username, permission)
        except SearpcError, e:
            logger.error(e)
            return json_error(_(u'Failed to create: internal error.'))
开发者ID:TanLian,项目名称:seahub,代码行数:53,代码来源:views.py

示例12: group_joinrequest

def group_joinrequest(request, group_id):
    """
    Handle post request to join a group.
    """
    if not request.is_ajax() or request.method != 'POST':
        raise Http404

    result = {}
    content_type = 'application/json; charset=utf-8'

    group_id = int(group_id)
    group =get_group(group_id) 
    if not group:
        raise Http404

    user = request.user.username
    # TODO: Group creator is group staff now, but may changed in future.
    staff = group.creator_name
    if is_group_user(group_id, user):
        # Already in the group. Normally, this case should not happen.
        err = _(u'You are already in the group.')
        return HttpResponseBadRequest(json.dumps({'error': err}),
                                      content_type=content_type)
    else:
        form = GroupJoinMsgForm(request.POST)
        if form.is_valid():
            group_join_msg = form.cleaned_data['group_join_msg']
            # Send the message to group staff.
            use_https = request.is_secure()
            domain = RequestSite(request).domain
            t = loader.get_template('group/group_join_email.html')
            c = {
                'staff': staff,
                'user': user,
                'group_name': group.group_name,
                'group_join_msg': group_join_msg,
                'site_name': SITE_NAME,
                }
            try:
                send_mail(_(u'apply to join the group'), t.render(Context(c)), None, [staff],
                          fail_silently=False)
                messages.success(request, _(u'Sent successfully, the group admin will handle it.'))
                return HttpResponse(json.dumps('success'),
                                    content_type=content_type)
            except:
                err = _(u'Failed to send. You can try it again later.')
                return HttpResponse(json.dumps({'error': err}), status=500,
                                    content_type=content_type)
        else:
            return HttpResponseBadRequest(json.dumps(form.errors),
                                          content_type=content_type)
开发者ID:chuyskywalker,项目名称:seahub,代码行数:51,代码来源:views.py

示例13: attention

def attention(request):
    """
    Handle ajax request to query group members used in autocomplete.
    """
    if not request.is_ajax():
        raise Http404

    user = request.user.username
    name_str =  request.GET.get('name_startsWith')
    gids = request.GET.get('gids', '')
    result = []

    members = []
    for gid in gids.split('_'):
        try:
            gid = int(gid)
        except ValueError:
            continue

        if not is_group_user(gid, user):
            continue

        # Get all group users
        members += get_group_members(gid)

    member_names = []
    for m in members:
        if len(result) == 10:   # Return at most 10 results.
            break
        
        if m.user_name == user:
            continue
        
        if m.user_name in member_names:
            # Remove duplicated member names
            continue
        else:
            member_names.append(m.user_name)

        from base.templatetags.seahub_tags import email2nickname, char2pinyin
        nickname = email2nickname(m.user_name)
        pinyin = char2pinyin(nickname)
        if nickname.startswith(name_str) or pinyin.startswith(name_str):
            result.append({'contact_name': nickname})

    content_type = 'application/json; charset=utf-8'
    
    return HttpResponse(json.dumps(result), content_type=content_type)
开发者ID:chuyskywalker,项目名称:seahub,代码行数:48,代码来源:views.py

示例14: group_add_admin

def group_add_admin(request, group_id):
    """
    Add group admin.
    """
    group_id = int(group_id)    # Checked by URL Conf
    
    if request.method != 'POST' or not request.is_ajax():
        raise Http404

    result = {}
    content_type = 'application/json; charset=utf-8'

    member_name_str = request.POST.get('user_name', '')
    member_list = string2list(member_name_str)

    for member_name in member_list:
        # Add user to contacts.
        mail_sended.send(sender=None, user=request.user.username,
                         email=member_name)

        if not is_registered_user(member_name):
            err_msg = _(u'Failed to add, %s is not registrated.') % member_name
            result['error'] = err_msg
            return HttpResponse(json.dumps(result), status=400,
                                content_type=content_type)
        
        # Check whether user is in the group
        if is_group_user(group_id, member_name):
            try:
                ccnet_threaded_rpc.group_set_admin(group_id, member_name)
            except SearpcError, e:
                result['error'] = _(e.msg)
                return HttpResponse(json.dumps(result), status=500,
                                    content_type=content_type)
        else:
            try:
                ccnet_threaded_rpc.group_add_member(group_id,
                                                    request.user.username,
                                                    member_name)
                ccnet_threaded_rpc.group_set_admin(group_id, member_name)
            except SearpcError, e:
                result['error'] = _(e.msg)
                return HttpResponse(json.dumps(result), status=500,
                                    content_type=content_type)
开发者ID:chuyskywalker,项目名称:seahub,代码行数:44,代码来源:views.py

示例15: _decorated

    def _decorated(request, group_id, *args, **kwargs):
        group_id_int = int(group_id)  # Checked by URL Conf
        group = get_group(group_id_int)
        if not group:
            return HttpResponseRedirect(reverse("group_list", args=[]))
        group.is_staff = False
        if PublicGroup.objects.filter(group_id=group.id):
            group.is_pub = True
        else:
            group.is_pub = False

        if not request.user.is_authenticated():
            if not group.is_pub:
                login_url = settings.LOGIN_URL
                path = urlquote(request.get_full_path())
                tup = login_url, REDIRECT_FIELD_NAME, path
                return HttpResponseRedirect("%s?%s=%s" % tup)
            else:
                group.view_perm = "pub"
                return func(request, group, *args, **kwargs)

        joined = is_group_user(group_id_int, request.user.username)
        if joined:
            group.view_perm = "joined"
            group.is_staff = is_group_staff(group, request.user)
            return func(request, group, *args, **kwargs)
        if request.user.is_staff:
            # viewed by system admin
            group.view_perm = "sys_admin"
            return func(request, group, *args, **kwargs)

        if group.is_pub:
            group.view_perm = "pub"
            return func(request, group, *args, **kwargs)

        return render_to_response(
            "error.html", {"error_msg": _("Permission denied")}, context_instance=RequestContext(request)
        )
开发者ID:octomike,项目名称:seahub,代码行数:38,代码来源:views.py


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