mirror of
https://github.com/ansible/awx.git
synced 2026-01-10 15:32:07 -03:30
A user can access what teams they are on.
This commit is contained in:
parent
6bf4c1604f
commit
0d41b7bf07
@ -110,7 +110,7 @@ class UserHelper(object):
|
||||
return 'partial'
|
||||
if user.is_superuser:
|
||||
return True
|
||||
matching_orgs = len(set(obj.organizations.all()) & set(user.admin_of_organizations.all()))
|
||||
matching_orgs = obj.organizations.filter(admins__in = [user]).count()
|
||||
return matching_orgs
|
||||
|
||||
@classmethod
|
||||
@ -123,7 +123,7 @@ class UserHelper(object):
|
||||
def can_user_delete(cls, user, obj):
|
||||
if user.is_superuser:
|
||||
return True
|
||||
matching_orgs = len(set(obj.organizations.all()) & set(user.admin_of_organizations.all()))
|
||||
matching_orgs = obj.organizations.filter(admins__in = [user]).count()
|
||||
return matching_orgs
|
||||
|
||||
|
||||
|
||||
@ -246,12 +246,30 @@ class ProjectsTest(BaseTest):
|
||||
|
||||
self.assertEquals(Team.objects.get(pk=team.pk).users.count(), 0)
|
||||
|
||||
# =====================================================================
|
||||
# USER TEAMS
|
||||
|
||||
# from a user, can see what teams they are on (related resource)
|
||||
print "TEAMS?"
|
||||
print User.objects.get(username = 'other').teams.all()
|
||||
other = User.objects.get(username = 'other')
|
||||
url = '/api/v1/users/%s/teams/' % other.pk
|
||||
self.get(url, expect=401)
|
||||
self.get(url, expect=401, auth=self.get_invalid_credentials())
|
||||
self.get(url, expect=403, auth=self.get_nobody_credentials())
|
||||
other.organizations.add(Organization.objects.get(pk=2))
|
||||
other.save()
|
||||
my_teams1 = self.get(url, expect=200, auth=self.get_normal_credentials())
|
||||
my_teams2 = self.get(url, expect=200, auth=self.get_other_credentials())
|
||||
self.assertEqual(my_teams1['count'], 2)
|
||||
self.assertEqual(my_teams1, my_teams2)
|
||||
|
||||
# =====================================================================
|
||||
# USER PROJECTS
|
||||
|
||||
url = '/api/v1/users/%s/projects/' % other.pk
|
||||
|
||||
# from a user, can see what projects they can see based on team association
|
||||
# though this resource doesn't do anything else
|
||||
raise Exception("STOP")
|
||||
|
||||
# =====================================================================
|
||||
# CREDENTIALS
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user