-
-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(organizations)!: Restrict project usage access to admins and org…
…anization owners (#5333) ### 📣 Summary Restricted access to project usage data to admins and organization owners only. ### 📖 Description This PR introduces stricter access control for project usage data, limiting visibility and management to admins and organization owners. This change ensures that only authorized users can access and manage usage metrics, protecting organizational data from unauthorized access.
- Loading branch information
1 parent
3f471dc
commit 0bb717d
Showing
11 changed files
with
128 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,6 +169,70 @@ def test_api_response_includes_is_mmo_with_override_and_subscription( | |
self.assertEqual(response.data['is_mmo'], True) | ||
|
||
|
||
@ddt | ||
class OrganizationDetailAPITestCase(BaseTestCase): | ||
|
||
fixtures = ['test_data'] | ||
URL_NAMESPACE = URL_NAMESPACE | ||
|
||
def setUp(self): | ||
self.someuser = User.objects.get(username='someuser') | ||
self.organization = self.someuser.organization | ||
self.organization.mmo_override = True | ||
self.organization.save(update_fields=['mmo_override']) | ||
|
||
# anotheruser is an admin of someuser's organization | ||
self.anotheruser = User.objects.get(username='anotheruser') | ||
self.organization.add_user(self.anotheruser, is_admin=True) | ||
|
||
# alice is a regular member of someuser's organization | ||
self.alice = User.objects.create_user( | ||
username='alice', password='alice', email='[email protected]' | ||
) | ||
self.organization.add_user(self.alice, is_admin=False) | ||
|
||
# bob is external to someuser's organization | ||
self.bob = User.objects.create_user( | ||
username='bob', password='bob', email='[email protected]' | ||
) | ||
|
||
@data( | ||
('someuser', status.HTTP_200_OK), | ||
('anotheruser', status.HTTP_200_OK), | ||
('alice', status.HTTP_403_FORBIDDEN), | ||
('bob', status.HTTP_404_NOT_FOUND), | ||
) | ||
@unpack | ||
def test_asset_usage(self, username, expected_status_code): | ||
user = User.objects.get(username=username) | ||
self.client.force_login(user) | ||
|
||
url = reverse( | ||
self._get_endpoint('organizations-asset-usage'), | ||
kwargs={'id': self.organization.id} | ||
) | ||
response = self.client.get(url) | ||
assert response.status_code == expected_status_code | ||
|
||
@data( | ||
('someuser', status.HTTP_200_OK), | ||
('anotheruser', status.HTTP_200_OK), | ||
('alice', status.HTTP_200_OK), | ||
('bob', status.HTTP_404_NOT_FOUND), | ||
) | ||
@unpack | ||
def test_service_usage(self, username, expected_status_code): | ||
user = User.objects.get(username=username) | ||
self.client.force_login(user) | ||
|
||
url = reverse( | ||
self._get_endpoint('organizations-service-usage'), | ||
kwargs={'id': self.organization.id} | ||
) | ||
response = self.client.get(url) | ||
assert response.status_code == expected_status_code | ||
|
||
|
||
class BaseOrganizationAssetApiTestCase(BaseAssetTestCase): | ||
""" | ||
This test suite (e.g. classes which inherit from this one) does not cover | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.