Пример #1
0
    def get_all_permissions(self, user_obj, obj=None):
        # LOG.debug("get_all_permissions for user: %s" % user_obj)
        if user_obj.is_anonymous() or obj is not None:
            return set()
        if not hasattr(user_obj, '_perm_cache'):
            user_obj._perm_cache = (Team.get_all_permissions_for(
                user=user_obj))

        return user_obj._perm_cache
Пример #2
0
    def get_all_permissions(self, user_obj, obj=None):
        # LOG.debug("get_all_permissions for user: %s" % user_obj)
        if user_obj.is_anonymous() or obj is not None:
            return set()
        if not hasattr(user_obj, '_perm_cache'):
            user_obj._perm_cache = (
                Team.get_all_permissions_for(user=user_obj))

        return user_obj._perm_cache
 def test_can_get_same_team_users(self):
     new_team2 = factory.TeamFactory()
     expected_users = [factory.UserFactory() for _ in range(10)]
     new_team2.users.add(expected_users[0])
     for user in expected_users[0:6]:
         self.new_team.users.add(user)
     for user in expected_users[4:]:
         new_team2.users.add(user)
     self.new_team.save()
     resulted_users = Team.users_at_same_team(expected_users[0])
     self.assertEqual(resulted_users, expected_users)
Пример #4
0
 def test_can_get_same_team_users(self):
     new_team2 = factory.TeamFactory()
     expected_users = [factory.UserFactory() for _ in range(10)]
     new_team2.users.add(expected_users[0])
     for user in expected_users[0:6]:
         self.new_team.users.add(user)
     for user in expected_users[4:]:
         new_team2.users.add(user)
     self.new_team.save()
     resulted_users = Team.users_at_same_team(expected_users[0])
     self.assertEqual(resulted_users, expected_users)
Пример #5
0
    def get_all_permissions(self, user_obj, obj=None):
        # LOG.debug("get_all_permissions for user: %s" % user_obj)
        if user_obj.is_anonymous() or obj is not None:
            return set()
        if not hasattr(user_obj, '_perm_cache'):
            user_obj._perm_cache = set(["%s.%s" % (p.content_type.app_label, p.codename) for p in user_obj.user_permissions.select_related()])
            user_obj._perm_cache.update(self.get_group_permissions(user_obj))
            #get team permissions
            user_obj._perm_cache.update(Team.get_all_permissions_for(user=user_obj))

        return user_obj._perm_cache
Пример #6
0
    def queryset(self, request):
        qs = None

        if request.user.has_perm(self.perm_add_database_infra):
            qs = super(TaskHistoryAdmin, self).queryset(request)
            return qs

        if request.GET.get('user'):
            query_dict_copy = request.GET.copy()
            del query_dict_copy['user']
            request.GET = query_dict_copy

        qs = super(TaskHistoryAdmin, self).queryset(request)
        same_team_users = Team.users_at_same_team(request.user)
        return qs.filter(user__in=[user.username for user in same_team_users])
    def queryset(self, request):
        qs = None

        if request.user.has_perm(self.perm_add_database_infra):
            qs = super(TaskHistoryAdmin, self).queryset(request)
            return qs

        if request.GET.get('user'):
            query_dict_copy = request.GET.copy()
            del query_dict_copy['user']
            request.GET = query_dict_copy

        qs = super(TaskHistoryAdmin, self).queryset(request)
        same_team_users = Team.users_at_same_team(request.user)
        return qs.filter(user__in=[user.username for user in same_team_users])
Пример #8
0
    def test_can_get_same_team_users(self):
        new_team2 = mommy.make_recipe('account.team')
        expected_users = sorted(mommy.make_recipe('account.user',
                                                  _quantity=10),
                                key=lambda u: u.id)

        new_team2.users.add(expected_users[0])
        for user in expected_users[0:6]:
            self.new_team.users.add(user)
        self.new_team.save()
        for user in expected_users[4:]:
            new_team2.users.add(user)
        new_team2.save()
        resulted_users = sorted(Team.users_at_same_team(expected_users[0]),
                                key=lambda u: u.id)

        self.assertEqual(resulted_users, expected_users)
Пример #9
0
 def test_can_get_same_team_users_empty_user(self):
     resulted_users = set(Team.users_at_same_team(None))
     self.assertFalse(resulted_users)
Пример #10
0
 def test_cant_create_a_new_user(self):
     team = Team()
     team.name = "Team1"
     team.role_id = factory.RoleFactory().pk
     team.organization_id = factory.OrganizationFactory().pk
     self.assertFalse(team.save())
 def test_can_get_same_team_users_empty_user(self):
     resulted_users = set(Team.users_at_same_team(None))
     self.assertFalse(resulted_users)
 def test_cant_create_a_new_user(self):
     team = Team()
     team.name = "Team1"
     team.role_id = factory.RoleFactory().pk
     team.organization_id = factory.OrganizationFactory().pk
     self.assertFalse(team.save())
Пример #13
0
 def test_cant_create_a_new_user(self):
     team = Team()
     team.name = "Team1"
     team.role_id = mommy.make_recipe('account.role', ).pk
     team.organization_id = mommy.make('Organization').pk
     self.assertFalse(team.save())