Merge lp:~zyga/django-restricted-resource/fix-is-owned-by-for-group-owners into lp:django-restricted-resource

Proposed by Zygmunt Krynicki
Status: Merged
Merged at revision: 22
Proposed branch: lp:~zyga/django-restricted-resource/fix-is-owned-by-for-group-owners
Merge into: lp:django-restricted-resource
Diff against target: 53 lines (+28/-3)
2 files modified
django_restricted_resource/models.py (+15/-3)
django_restricted_resource/tests.py (+13/-0)
To merge this branch: bzr merge lp:~zyga/django-restricted-resource/fix-is-owned-by-for-group-owners
Reviewer Review Type Date Requested Status
Paul Larson (community) Approve
Michael Hudson-Doyle (community) Approve
Linaro Infrastructure Pending
Review via email: mp+74841@code.launchpad.net

Description of the change

Fix resource.is_owned_by(user) when user belongs to resource.group owner.

To post a comment you must log in.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Looks fine, but I find the comments a little confusing.

+ # If the principal is an User then this object is owned by that user or
+ # the group the user belongs to.

I think if this was phrased as a question it would be more clear: "is this object owned by that user or a group that the user belongs to?" Similarly for the next comment down.

review: Approve
Revision history for this message
Paul Larson (pwlars) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'django_restricted_resource/models.py'
2--- django_restricted_resource/models.py 2011-06-23 09:59:46 +0000
3+++ django_restricted_resource/models.py 2011-09-09 17:39:26 +0000
4@@ -117,10 +117,22 @@
5 """
6 if principal is None:
7 return False
8- if not isinstance(principal,
9- (User, Group, AnonymousUser, type(None))):
10+ # If the principal is an User then this object is owned by that user or
11+ # the group the user belongs to.
12+ if isinstance(principal, (User, AnonymousUser, type(None))):
13+ user = filter_bogus_users(principal)
14+ if user is None:
15+ return False
16+ if self.user is not None:
17+ return self.user == user
18+ else:
19+ return self.group in user.groups.all()
20+ # If the principal is a Group then this object is owned by that group
21+ elif isinstance(principal, Group):
22+ group = principal
23+ return self.group == group
24+ else:
25 raise TypeError("Expected User or Group instance as argument")
26- return self.user == principal or self.group == principal
27
28 def get_access_type(self, principal):
29 """
30
31=== modified file 'django_restricted_resource/tests.py'
32--- django_restricted_resource/tests.py 2011-05-23 16:41:17 +0000
33+++ django_restricted_resource/tests.py 2011-09-09 17:39:26 +0000
34@@ -165,6 +165,19 @@
35 self.assertTrue(resource.is_owned_by(self.owner))
36
37
38+class GroupMemberOwnsResource(FixtureHelper):
39+
40+ def test(self):
41+ """
42+ RestrictedResource.is_owned_by() returns True for owning group members
43+ """
44+ group = self.getUniqueGroup()
45+ user = self.getUniqueUser()
46+ user.groups.add(group)
47+ resource = self.getUniqueResource(owner=group)
48+ self.assertTrue(resource.is_owned_by(user))
49+
50+
51 class ResourceManagerOwnerSetFindsNoMatchesForOthers(
52 FixtureHelper, TestCaseWithInvariants):
53 """

Subscribers

People subscribed via source and target branches

to all changes: