コード例 #1
0
ファイル: models.py プロジェクト: wheelcms/wheelcms_users
    def user_data(self, handler, instance):
        if handler.request.method == "POST":
            data = load_json(handler.request.POST.get('data', "{}"))

            for user in data.get('existing', []):
                state = user.get('state', '')

                if state == 'deleted':
                    try:
                        User.objects.get(pk=user['id']).delete()
                    except (ValueError, User.DoesNotExist):
                        pass
                elif state in ("added", "modified"):
                    try:
                        u = User.objects.get(pk=user['id'])
                        u.username = user.get('username').strip()
                        u.first_name = user.get('firstname', '')
                        u.last_name = user.get('lastname', '')
                        u.email = user.get('email', '')
                        ## active?
                    except (ValueError, User.DoesNotExist):
                        u = User(username=user.get('username').strip(),
                                 first_name=user.get('firstname', ''),
                                 last_name=user.get('lastname', ''),
                                 email=user.get('email', ''))
                        u.save()

                    password = user.get('password', '').strip()
                    if password:
                        u.set_password(password)

                    u.roles.all().delete()

                    for role, isset in user.get('roles', {}).iteritems():
                        if isset:
                            WheelRole(role=Role(role), user=u).save()

                    u.save()

                ## roles


        users = User.objects.all()
        data = {}
        data['existing'] = [dict(id=u.id,
                              username=u.username,
                              firstname=u.first_name,
                              lastname=u.last_name,
                              email=u.email,
                              active=u.is_active,
                              superuser=u.is_superuser,
                              roles=dict((role.role.id, True)
                                         for role in u.roles.all())
                              ) for u in users]
        data['roles'] = [dict(id=role.id,
                              name=role.name,
                              description=role.description)
                         for role in Role.all()]

        return data
コード例 #2
0
ファイル: spoke.py プロジェクト: wheelcms/wheelcms_axle
    def auth(self, handler, request, action):
        ##
        ## If post, handle/reset perm changes

        if request.method == "POST":
            existing = RolePermission.assignments(self.instance)
            assignments = request.POST.getlist('assignment')
            for e in existing:
                if "{0}/{1}".format(e.permission, e.role) not in assignments:
                    e.delete()

            for assignment in assignments:
                perm, role = assignment.split('/', 1)
                RolePermission.assign(self.instance, Role(role),
                                      Permission(perm)).save()

        ctx = {'spoke':self}


        roles = Role.all()
        permissions = []

        ## order roles, permissions (alphabetically?)
        for perm in Permission.all():
            d = dict(perm=perm, roles=[])
            perms_per_role = RolePermission.assignments(
                                        self.instance).filter(
                                        permission=perm.id,
                                        ).values_list('role', flat=True)
            r = []
            for role in roles:
                r.append(dict(role=role, checked=role.id in perms_per_role))

            d['roles'] = r

            permissions.append(d)

        ctx['roles'] = roles
        ctx['permissions'] = permissions
        return handler.template("wheelcms_axle/edit_permissions.html", **ctx)
コード例 #3
0
ファイル: test_roles.py プロジェクト: iivvoo/django_drole
 def test_all(self):
     """ retrieve all created permissions """
     r1 = Role.create("r1")
     r2 = Role.create("r2")
     r3 = Role.create("r2") # duplicate!
     assert set(Role.all()) == set((r1, r2))
コード例 #4
0
ファイル: test_roles.py プロジェクト: iivvoo/django_drole
 def test_all_empty(self):
     """ empty role collection """
     assert len(Role.all()) == 0
コード例 #5
0
ファイル: test_roles.py プロジェクト: iivvoo/django_drole
 def test_equality(self):
     """ ordinary comparison. Will succeed since it will be the same
         objects """
     assert Role.create("foo") == Role.create("foo")
コード例 #6
0
ファイル: test_roles.py プロジェクト: iivvoo/django_drole
 def test_uniqueness_differ(self):
     """ 
         Role with different identifier are not equal
     """
     assert Role.create("foo") != Role("bar")
コード例 #7
0
ファイル: test_roles.py プロジェクト: iivvoo/django_drole
 def test_uniqueness_attrs(self):
     """ Different instances with same identifier are identical, even
         if other attributes differ """
     assert Role.create("foo", "bar", "bla") is \
            Role.create("foo", "this", "that")
コード例 #8
0
ファイル: test_roles.py プロジェクト: iivvoo/django_drole
 def test_uniqueness_id(self):
     """ Different instances with same identifier are identical """
     assert Role.create("foo") is Role.create("foo")
コード例 #9
0
ファイル: test_roles.py プロジェクト: iivvoo/django_drole
 def test_create(self):
     """ Role are implicitly created """
     assert Role.create("foo") is not None
コード例 #10
0
ファイル: test_roles.py プロジェクト: iivvoo/django_drole
 def test_unicode(self):
     assert isinstance(Role.create("foo").__unicode__(), unicode)
コード例 #11
0
ファイル: auth.py プロジェクト: wheelcms/wheelcms_axle
def Role(id, name="", description=""):
    return droleRole.create(id, name, description)