Skip to content

Commit ba4bfcf

Browse files
committed
"view:organization" permission for sll org members
- Allow read access to organization for all members - Allow non-owners to remove self from organization
1 parent a332623 commit ba4bfcf

File tree

9 files changed

+196
-107
lines changed

9 files changed

+196
-107
lines changed

tests/unit/accounts/test_views.py

-3
Original file line numberDiff line numberDiff line change
@@ -2257,9 +2257,6 @@ def test_verify_organization_role(
22572257
pretend.call(
22582258
"manage.organization.roles", organization_name=organization.name
22592259
)
2260-
if desired_role == "Owner"
2261-
# TODO: Test redirecting to managing organization projects.
2262-
else pretend.call("manage.organizations")
22632260
]
22642261

22652262
@pytest.mark.parametrize(

tests/unit/manage/test_views.py

+31-1
Original file line numberDiff line numberDiff line change
@@ -3453,7 +3453,7 @@ def test_delete_role(self, db_request, enable_organizations, monkeypatch):
34533453
)
34543454
]
34553455
assert db_request.session.flash.calls == [
3456-
pretend.call("Removed member", queue="success")
3456+
pretend.call("Removed from organization", queue="success")
34573457
]
34583458
assert isinstance(result, HTTPSeeOther)
34593459
assert result.headers["Location"] == "/the-redirect"
@@ -3478,6 +3478,36 @@ def test_delete_missing_role(self, db_request, enable_organizations):
34783478
assert isinstance(result, HTTPSeeOther)
34793479
assert result.headers["Location"] == "/the-redirect"
34803480

3481+
def test_delete_other_role_as_nonowner(self, db_request, enable_organizations):
3482+
organization = OrganizationFactory.create(name="foobar")
3483+
user = UserFactory.create(username="testuser")
3484+
role = OrganizationRoleFactory.create(
3485+
organization=organization,
3486+
user=user,
3487+
role_name=OrganizationRoleType.Owner,
3488+
)
3489+
user_2 = UserFactory.create()
3490+
3491+
db_request.method = "POST"
3492+
db_request.user = user_2
3493+
db_request.POST = MultiDict({"role_id": role.id})
3494+
db_request.has_permission = pretend.call_recorder(lambda *a, **kw: False)
3495+
db_request.session = pretend.stub(
3496+
flash=pretend.call_recorder(lambda *a, **kw: None)
3497+
)
3498+
db_request.route_path = pretend.call_recorder(lambda *a, **kw: "/the-redirect")
3499+
3500+
result = views.delete_organization_role(organization, db_request)
3501+
3502+
assert db_request.has_permission.calls == [pretend.call("manage:organization")]
3503+
assert db_request.session.flash.calls == [
3504+
pretend.call(
3505+
"Cannot remove other people from the organization", queue="error"
3506+
)
3507+
]
3508+
assert isinstance(result, HTTPSeeOther)
3509+
assert result.headers["Location"] == "/the-redirect"
3510+
34813511
def test_delete_own_owner_role(self, db_request, enable_organizations):
34823512
organization = OrganizationFactory.create(name="foobar")
34833513
user = UserFactory.create(username="testuser")

tests/unit/organizations/test_models.py

+32-8
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,50 @@ def test_acl(self, db_session):
8181
# ] +
8282
assert acls == sorted(
8383
[
84-
(Allow, f"user:{owner1.user.id}", ["manage:organization"]),
85-
(Allow, f"user:{owner2.user.id}", ["manage:organization"]),
84+
(
85+
Allow,
86+
f"user:{owner1.user.id}",
87+
["view:organization", "manage:organization"],
88+
),
89+
(
90+
Allow,
91+
f"user:{owner2.user.id}",
92+
["view:organization", "manage:organization"],
93+
),
8694
],
8795
key=lambda x: x[1],
8896
) + sorted(
8997
[
90-
(Allow, f"user:{billing_mgr1.user.id}", ["manage:billing"]),
91-
(Allow, f"user:{billing_mgr2.user.id}", ["manage:billing"]),
98+
(
99+
Allow,
100+
f"user:{billing_mgr1.user.id}",
101+
["view:organization", "manage:billing"],
102+
),
103+
(
104+
Allow,
105+
f"user:{billing_mgr2.user.id}",
106+
["view:organization", "manage:billing"],
107+
),
92108
],
93109
key=lambda x: x[1],
94110
) + sorted(
95111
[
96-
(Allow, f"user:{account_mgr1.user.id}", ["manage:team"]),
97-
(Allow, f"user:{account_mgr2.user.id}", ["manage:team"]),
112+
(
113+
Allow,
114+
f"user:{account_mgr1.user.id}",
115+
["view:organization", "manage:team"],
116+
),
117+
(
118+
Allow,
119+
f"user:{account_mgr2.user.id}",
120+
["view:organization", "manage:team"],
121+
),
98122
],
99123
key=lambda x: x[1],
100124
) + sorted(
101125
[
102-
(Allow, f"user:{member1.user.id}", ["organization:member"]),
103-
(Allow, f"user:{member2.user.id}", ["organization:member"]),
126+
(Allow, f"user:{member1.user.id}", ["view:organization"]),
127+
(Allow, f"user:{member2.user.id}", ["view:organization"]),
104128
],
105129
key=lambda x: x[1],
106130
)

warehouse/accounts/views.py

+4-13
Original file line numberDiff line numberDiff line change
@@ -983,20 +983,11 @@ def _error(message):
983983
queue="success",
984984
)
985985

986-
if desired_role == "Owner":
987-
return HTTPSeeOther(
988-
request.route_path(
989-
"manage.organization.roles", organization_name=organization.name
990-
)
986+
return HTTPSeeOther(
987+
request.route_path(
988+
"manage.organization.roles", organization_name=organization.name
991989
)
992-
else:
993-
# TODO: Redirect to managing organization projects.
994-
# return HTTPSeeOther(
995-
# request.route_path(
996-
# "manage.organization.projects", name=organization.name
997-
# )
998-
# )
999-
return HTTPSeeOther(request.route_path("manage.organizations"))
990+
)
1000991

1001992

1002993
@view_config(

0 commit comments

Comments
 (0)