-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(projectHistoryLogs): add endpoints for viewing project history l…
…ogs TASK-973 (#5319) ### 📣 Summary Add two new endpoints for viewing project history logs, one for all logs, and one for logs for a given project. ### 📖 Description Adds two new endpoints: `/api/v2/project-history-logs` (all project history logs) and `/api/v2/assets/<uid>/history` (logs for the specific project). The former is only available to superusers, the latter is available to anyone with the manage_asset permission for the project. Both endpoints can be searched by a all fields, most importantly `action`, `metadata__asset_uid`, and `username`. A full list of available searchable fields is in the endpoint documentation. ### 👀 Preview steps Feature/no-change template: 1. ℹ️ have two accounts, one super and one not. Have at least two projects. 2. Change the name of both projects to generate some logs. 3. Log in as the superuser. 4. Go to `localhost/api/v2/project-history-logs` 5. 🟢 You should see logs for both projects 6. Grant the non-superuser the manage_project permission for one of the projects (they will have this if they are the owner, or you can assign it from Settings > Sharing) 7. Log out 8. 🟢 Go to `localhost/api/v2/project-history-logs`. You should get a 401. 9. Log in as the non-superuser. 10. 🟢 Go to `localhost/api/v2/project-history-logs`. You should get a 403. 11. Go to `localhost/api/v2/assets/<asset_uid>/history` 12. 🟢 You should see project history logs for just that project 13. Revoke the manage_project permission for the user. You can do this by transferring ownership or just removing the singular permission (will require you to log back in as the superuser). 14. 🟢 Reload `localhost/api/v2/assets/<asset_uid>/history`. You should get a 403.
- Loading branch information
Showing
6 changed files
with
810 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
from rest_framework.permissions import IsAdminUser | ||
|
||
from kpi.mixins.validation_password_permission import ( | ||
ValidationPasswordPermissionMixin, | ||
) | ||
from kpi.constants import PERM_MANAGE_ASSET | ||
from kpi.mixins.validation_password_permission import ValidationPasswordPermissionMixin | ||
from kpi.permissions import IsAuthenticated | ||
|
||
|
||
class SuperUserPermission(ValidationPasswordPermissionMixin, IsAdminUser): | ||
|
||
def has_permission(self, request, view): | ||
self.validate_password(request) | ||
return bool(request.user and request.user.is_superuser) | ||
|
||
|
||
class ViewProjectHistoryLogsPermission(IsAuthenticated): | ||
|
||
def has_permission(self, request, view): | ||
has_asset_perm = bool( | ||
request.user | ||
and view.asset.has_perm(user_obj=request.user, perm=PERM_MANAGE_ASSET) | ||
) | ||
return has_asset_perm and super().has_permission(request, view) |
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.