Example #1
0
    def setUp(self):

        self.login_as(self.admin)

        # create group for admin user
        self.admin_group_1_name = randstring(6)
        self.admin_group_1_id = ccnet_threaded_rpc.create_group(self.admin_group_1_name,
                self.admin.email)

        # create another group for admin user
        self.admin_group_2_name = randstring(6)
        self.admin_group_2_id = ccnet_threaded_rpc.create_group(self.admin_group_2_name,
                self.admin.email)

        # create repo for admin user
        self.admin_repo_name = randstring(6)
        r = seafile_api.get_repo(self.create_repo(name=self.admin_repo_name,
            desc='', username=self.admin.email, passwd=None))
        self.admin_repo_id = r.id

        # set common user as staff in admin user's group
        ccnet_threaded_rpc.group_add_member(self.admin_group_1_id,
                self.admin.email, self.user.email)
        ccnet_threaded_rpc.group_set_admin(self.admin_group_1_id, self.user.email)

        # add common user to admin user's another group
        ccnet_threaded_rpc.group_add_member(self.admin_group_2_id,
                self.admin.email, self.user.email)

        # share admin user's repo to common user
        seafile_api.share_repo(self.admin_repo_id, self.admin.email,
                               self.user.email, 'rw')
Example #2
0
def group_list(request):
    username = request.user.username

    if request.method == "POST":
        """
        Add a new group.
        """
        result = {}
        content_type = "application/json; charset=utf-8"

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

            # Check whether group name is duplicated.
            if request.cloud_mode:
                checked_groups = get_personal_groups_by_user(username)
            else:
                checked_groups = get_personal_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:
                ccnet_threaded_rpc.create_group(group_name.encode("utf-8"), 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)
        else:
            return HttpResponseBadRequest(json.dumps(form.errors), content_type=content_type)
Example #3
0
 def create_group(self, **kwargs):
     group_name = kwargs['group_name']
     username = kwargs['username']
     group_id = ccnet_threaded_rpc.create_group(group_name, username)
     return ccnet_threaded_rpc.get_group(group_id)
Example #4
0
 def create_group(self, **kwargs):
     group_name = kwargs['group_name']
     username = kwargs['username']
     group_id = ccnet_threaded_rpc.create_group(group_name, username)
     return ccnet_threaded_rpc.get_group(group_id)