Пример #1
0
    def create_role_principal_relation(self):
        """
        """

        group = Group.objects.get(name=settings.DEVELOPERS_GROUP_NAME)
        print group
        if len(get_global_roles(group)) == 0:
            role = Role.objects.get(name=settings.ROLE_DEVELOPER_NAME)
            add_role(group, role)

        group = Group.objects.get(name=settings.ADMINS_GROUP_NAME)
        print group
        if len(get_global_roles(group)) == 0:
            role = Role.objects.get(name=settings.ROLE_ADMIN_NAME)
            add_role(group, role)

        group = Group.objects.get(name=settings.MANAGERS_GROUP_NAME)
        print group
        if len(get_global_roles(group)) == 0:
            role = Role.objects.get(name=settings.ROLE_MANAGER_NAME)
            add_role(group, role)

        group = Group.objects.get(name=settings.EDITORS_GROUP_NAME)
        print group
        if len(get_global_roles(group)) == 0:
            role = Role.objects.get(name=settings.ROLE_EDITOR_NAME)
            add_role(group, role)

        group = Group.objects.get(name=settings.VIEWERS_GROUP_NAME)
        print group
        if len(get_global_roles(group)) == 0:
            role = Role.objects.get(name=settings.ROLE_VIEWER_NAME)
            add_role(group, role)
Пример #2
0
    def forwards(self, orm):
        # move all roles to the new model
        for role in orm.roles.objects.all():
            new_role, created = Role.objects.get_or_create(name=role.roleName)

        for user in orm['auth.User'].objects.all():
            user_profile = orm.UserProfile.objects.get(pk=user.pk)
            try:
                for role in user_profile.roles.all():
                    new_role = Role.objects.get(name=role.roleName)
                    add_role(user, new_role)
            except Exception, e:
                pass
Пример #3
0
 def test_get_local_users(self):
     '''
         This function which requires you to provide an object
         for the content, returns a list of users who are local
         members of this role for this content.
     '''
     
     #if the object has no local roles returns empty list
     self.assertEqual([], self.role_1.get_local_users(self.page_1))
     
     #if the object has a local role with a user return a list containing that user
     self.user_2 = User.objects.create(username="******")
     self.user_2.save()
     add_local_role(self.page_1, self.user, self.role_1)
     add_role(self.user_2, self.role_2)
     self.assertEqual([self.user], self.role_1.get_local_users(self.page_1))
Пример #4
0
    def setUp(self):
        """
        Pre-execution
        """
        # test users
        self.test_admin = User.objects.create_user('admin', '*****@*****.**',
                                                   '123')
        self.test_manager = User.objects.create_user('manager',
                                                     '*****@*****.**', '123')
        self.test_viewer = User.objects.create_user('viewer',
                                                    '*****@*****.**', '123')
        self.test_editor = User.objects.create_user('editor',
                                                    '*****@*****.**', '123')
        self.test_developer = User.objects.create_user('developer',
                                                       '*****@*****.**',
                                                       '123')

        #PERMISSIONS
        register_permission(settings.PERMISSION_VIEW_NAME,
                            settings.PERMISSION_VIEW_NAME)
        register_permission(settings.PERMISSION_EDIT_NAME,
                            settings.PERMISSION_EDIT_NAME)
        register_permission(settings.PERMISSION_CREATE_NAME,
                            settings.PERMISSION_CREATE_NAME)
        register_permission(settings.PERMISSION_DELETE_NAME,
                            settings.PERMISSION_DELETE_NAME)

        # ROLES
        register_role(settings.ROLE_DEVELOPER_NAME)
        register_role(settings.ROLE_ADMIN_NAME)
        register_role(settings.ROLE_MANAGER_NAME)
        register_role(settings.ROLE_EDITOR_NAME)
        register_role(settings.ROLE_VIEWER_NAME)

        # ASSIGN ROlES
        add_role(self.test_editor,
                 Role.objects.get(name=settings.ROLE_EDITOR_NAME))
        add_role(self.test_viewer,
                 Role.objects.get(name=settings.ROLE_VIEWER_NAME))
        add_role(self.test_admin,
                 Role.objects.get(name=settings.ROLE_ADMIN_NAME))
        add_role(self.test_manager,
                 Role.objects.get(name=settings.ROLE_MANAGER_NAME))
        add_role(self.test_developer,
                 Role.objects.get(name=settings.ROLE_DEVELOPER_NAME))
Пример #5
0
def users_update_role_map(request):
    try:
        if request.method == "POST":
            for key, value in request.POST.iteritems():
                if len(key.split('!')) == 3:
                    userinfo = key.split('!')
                    role = Role.objects.get(name=userinfo[0])
                    if not isinstance(role, Role):
                        return HttpResponse('FALSE')
                    user, created = User.objects.get_or_create(username=userinfo[1], email=userinfo[2])
                    if value == 'on':
                        add_role(user, role)
                    else:
                        remove_role(user, role)

            return HttpResponse('TRUE')
    except Exception, e:
        from raven.contrib.django.raven_compat.models import client
        client.captureException()
        return HttpResponse("FALSE")
Пример #6
0
        def create_principal_role_relations(sender, **kwargs):
            try:
                sms_updater_group = Group.objects.get(name=UserProfile.GROUP_SMS_UPDATER)
                sms_manager_group = Group.objects.get(name=UserProfile.GROUP_SMS_MANAGER)
                sms_updater_role  = permissions.Role.objects.get(name=UserProfile.GROUP_SMS_UPDATER)
                sms_manager_role  = permissions.Role.objects.get(name=UserProfile.GROUP_SMS_MANAGER)

                add_role(sms_updater_group, sms_updater_role)
                add_role(sms_manager_group, sms_updater_role)
                add_role(sms_manager_group, sms_manager_role)

                print "Created principal role relations for %s and %s" % (UserProfile.GROUP_SMS_MANAGER, UserProfile.GROUP_SMS_UPDATER)
            except:
                print "Role relations could not be created since fixtures are missing. Run manage.py syncdb again please!"
Пример #7
0
        def create_principal_role_relations(sender, **kwargs):
            try:
                sms_updater_group = Group.objects.get(
                    name=UserProfile.GROUP_SMS_UPDATER)
                sms_manager_group = Group.objects.get(
                    name=UserProfile.GROUP_SMS_MANAGER)
                sms_updater_role = permissions.Role.objects.get(
                    name=UserProfile.GROUP_SMS_UPDATER)
                sms_manager_role = permissions.Role.objects.get(
                    name=UserProfile.GROUP_SMS_MANAGER)

                add_role(sms_updater_group, sms_updater_role)
                add_role(sms_manager_group, sms_updater_role)
                add_role(sms_manager_group, sms_manager_role)

                print "Created principal role relations for %s and %s" % (
                    UserProfile.GROUP_SMS_MANAGER,
                    UserProfile.GROUP_SMS_UPDATER)
            except:
                print "Role relations could not be created since fixtures are missing. Run manage.py syncdb again please!"
Пример #8
0
    def handle(self, role_name="viewer", *args, **options):
        user_ids = UserProfile.objects.all().values_list('id', flat=True)
        users = User.objects.exclude(id__in=user_ids)

        managers_group, created = Group.objects.get_entity(
            name=settings.MANAGERS_GROUP_NAME)
        editors_group, created = Group.objects.get_entity(
            name=settings.EDITORS_GROUP_NAME)
        viewer_group, created = Group.objects.get_entity(
            name=settings.VIEWERS_GROUP_NAME)
        dev_group, created = Group.objects.get_entity(
            name=settings.DEVELOPERS_GROUP_NAME)
        admin_group, created = Group.objects.get_entity(
            name=settings.ADMINS_GROUP_NAME)

        for user in users:
            profile = UserProfile()
            profile.user = user
            profile.save()
            role = None

            if role_name == "viewer":
                role = Role.objects.get(name=settings.ROLE_VIEWER_NAME)
                user.groups.add(viewer_group)
                user.save()
                add_role(viewer_group, role)

            elif role_name == "manager":
                role = Role.objects.get(name=settings.ROLE_MANAGER_NAME)
                user.groups.add(managers_group)
                user.save()
                add_role(managers_group, role)

            elif role_name == "developer":
                role = Role.objects.get(name=settings.ROLE_DEVELOPER_NAME)
                user.groups.add(dev_group)
                user.save()
                add_role(dev_group, role)

            elif role_name == "admin":
                role = Role.objects.get(name=settings.ROLE_ADMIN_NAME)
                user.groups.add(admin_group)
                user.save()
                add_role(admin_group, role)

            elif role_name == "editor":
                role = Role.objects.get(name=settings.ROLE_EDITOR_NAME)
                user.groups.add(editors_group)
                user.save()
                add_role(editors_group, role)

            else:
                role = Role.objects.get(name=settings.ROLE_VIEWER_NAME)
                user.groups.add(viewer_group)
                user.save()
                add_role(viewer_group, role)