Skip to content
Snippets Groups Projects
Commit 2253bc6c authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

fix approval status permissions

parent 8759af6f
No related branches found
No related tags found
No related merge requests found
Pipeline #13529 passed
...@@ -54,10 +54,28 @@ class ContractAdminForm(forms.ModelForm): ...@@ -54,10 +54,28 @@ class ContractAdminForm(forms.ModelForm):
) )
continue continue
if self.instance.status in ( if (
Contract.StatusTypes.WORK_IN_PROGRESS, choice_key == Contract.StatusTypes.TO_BE_APPROVED
Contract.StatusTypes.TO_BE_APPROVED, and self.instance.status != Contract.StatusTypes.APPROVED
and (
self.current_user == self.instance.created_by
or self.current_user.has_perm("contract.edit_others")
)
): ):
allowed_choices.append((choice_key, choice_label))
if self.instance.status == Contract.StatusTypes.APPROVED:
if self.current_user.has_perm("contract.approve"):
if choice_key == Contract.StatusTypes.WORK_IN_PROGRESS:
allowed_choices.append(
(
choice_key,
choice_label,
)
)
continue
if self.instance.status == Contract.StatusTypes.TO_BE_APPROVED:
if self.current_user.has_perm("contract.approve"): if self.current_user.has_perm("contract.approve"):
if choice_key in ( if choice_key in (
Contract.StatusTypes.APPROVED, Contract.StatusTypes.APPROVED,
...@@ -99,7 +117,8 @@ class ContractAdminForm(forms.ModelForm): ...@@ -99,7 +117,8 @@ class ContractAdminForm(forms.ModelForm):
) )
if ( if (
clean_data.get("status", self.instance.status) not self.current_user.is_superuser
and clean_data.get("status", self.instance.status)
in (self.instance.StatusTypes.APPROVED, self.instance.StatusTypes.REJECTED) in (self.instance.StatusTypes.APPROVED, self.instance.StatusTypes.REJECTED)
and self.instance.status != clean_data.get("status", self.instance.status) and self.instance.status != clean_data.get("status", self.instance.status)
and self.current_user == self.instance.created_by and self.current_user == self.instance.created_by
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment