Skip to content

fix(arhcived-project-tasks): only superuser can edit tasks of archived projects #668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions backend/timed/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ def has_object_permission(self, request, view, _obj):
return self.has_permission(request, view)


class IsProjectActive(BasePermission):
"""Allows access to object only if a project is not archived."""

def has_object_permission(self, _request, _view, task):
return not task.project.archived


class IsAuthenticated(IsAuthenticated):
"""Support mixing permission IsAuthenticated with object permission.

Expand Down
5 changes: 3 additions & 2 deletions backend/timed/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
IsCustomer,
IsInternal,
IsManager,
IsProjectActive,
IsReadOnly,
IsSuperUser,
IsUpdateOnly,
Expand Down Expand Up @@ -177,8 +178,8 @@ class TaskViewSet(ModelViewSet):
(
# superuser may edit all tasks
IsSuperUser
# managers may edit all tasks
| IsManager
# only superuser can update tasks of archived projects
| (IsUpdateOnly & IsProjectActive & IsManager)
# all authenticated users may read all tasks
| IsAuthenticated & IsReadOnly
),
Expand Down
17 changes: 16 additions & 1 deletion frontend/app/projects/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
class="rounded"
data-test-name
@required={{true}}
@disabled={{this.selectedProject.archived}}
/>

<f.input @labelComponent="void" @name="estimatedTime" as |fi|>
Expand All @@ -211,6 +212,7 @@
<Durationpicker
data-test-estimated-time={{true}}
@value={{fi.value}}
@disabled={{this.selectedProject.archived}}
@onChange={{if
remainingEffortTracking
(queue fi.update (fn this.updateRemainingEffort f.model))
Expand All @@ -226,6 +228,7 @@
class="rounded"
data-test-reference
@required={{false}}
@disabled={{this.selectedProject.archived}}
/>

{{#if remainingEffortTracking}}
Expand All @@ -244,6 +247,7 @@
@value={{fi.value}}
@min={{0}}
@onChange={{fi.update}}
@disabled={{this.selectedProject.archived}}
/>
</div>
</f.input>
Expand All @@ -257,6 +261,7 @@
@checked={{this.selectedTask.archived}}
@value={{fi.value}}
@onChange={{fi.update}}
@disabled={{this.selectedProject.archived}}
/>
</f.input>

Expand All @@ -267,7 +272,17 @@
type="button"
{{on "click" (fn (mut this.selectedTask) null)}}
>Cancel</button>
<f.submit data-test-save @disabled={{f.model.isInvalid}} />
<f.submit
data-test-save
title={{if
this.selectedProject.archived
"You can not update or add tasks to an archived project"
}}
@disabled={{or
f.model.isInvalid
this.selectedProject.archived
}}
/>
</div>
</ValidatedForm>
</div>
Expand Down
Loading