mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 10:27:37 -02:30
A user can access what teams they are on.
This commit is contained in:
@@ -110,7 +110,7 @@ class UserHelper(object):
|
|||||||
return 'partial'
|
return 'partial'
|
||||||
if user.is_superuser:
|
if user.is_superuser:
|
||||||
return True
|
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
|
return matching_orgs
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -123,7 +123,7 @@ class UserHelper(object):
|
|||||||
def can_user_delete(cls, user, obj):
|
def can_user_delete(cls, user, obj):
|
||||||
if user.is_superuser:
|
if user.is_superuser:
|
||||||
return True
|
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
|
return matching_orgs
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -246,12 +246,30 @@ class ProjectsTest(BaseTest):
|
|||||||
|
|
||||||
self.assertEquals(Team.objects.get(pk=team.pk).users.count(), 0)
|
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)
|
# from a user, can see what teams they are on (related resource)
|
||||||
print "TEAMS?"
|
other = User.objects.get(username = 'other')
|
||||||
print User.objects.get(username = 'other').teams.all()
|
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
|
# from a user, can see what projects they can see based on team association
|
||||||
# though this resource doesn't do anything else
|
# though this resource doesn't do anything else
|
||||||
|
raise Exception("STOP")
|
||||||
|
|
||||||
# =====================================================================
|
# =====================================================================
|
||||||
# CREDENTIALS
|
# CREDENTIALS
|
||||||
|
|||||||
Reference in New Issue
Block a user