Skip to content
Snippets Groups Projects
Commit cf689ac1 authored by Alexa Valentová's avatar Alexa Valentová
Browse files

improve UI & permissions

parent 5ee62572
No related branches found
No related tags found
No related merge requests found
Pipeline #17164 passed
......@@ -121,7 +121,34 @@ class ContractFileAdmin(
form = ContractFileAdminForm
class ContracteeSignatureRepresentativeInline(NestedStackedInline):
class ParentContractInlineMixin:
def has_add_permission(self, request, obj=None):
if (
obj is not None
and not request.user.has_perm("contracts.edit_when_approved")
and not obj.is_editable_without_approve_permission
):
return False
return super().has_add_permission(request, obj)
def has_change_permission(self, request, obj=None):
return self.has_add_permission(request, obj)
def has_delete_permission(self, request, obj=None):
if (
obj is not None
and not request.user.has_perm("contracts.delete_when_approved")
and not obj.is_editable_without_approve_permission
):
return False
return super().has_change_permission(request, obj)
class ContracteeSignatureRepresentativeInline(
ParentContractInlineMixin, NestedStackedInline
):
model = ContracteeSignatureRepresentative
extra = 1
formset = SingnatureRepresentativeFormSet
......@@ -133,48 +160,45 @@ class ContracteeSignatureRepresentativeInline(NestedStackedInline):
return formset
class ContracteeSignatureInline(NestedStackedInline):
class ContracteeSignatureInline(ParentContractInlineMixin, NestedStackedInline):
model = ContracteeSignature
autocomplete_fields = ("contractee",)
inlines = (ContracteeSignatureRepresentativeInline,)
extra = 0
class SigneeSignatureRepresentativeInline(NestedStackedInline):
class SigneeSignatureRepresentativeInline(
ParentContractInlineMixin, NestedStackedInline
):
model = SigneeSignatureRepresentative
extra = 0
class SigneeSignatureInline(NestedStackedInline):
class SigneeSignatureInline(ParentContractInlineMixin, NestedStackedInline):
model = SigneeSignature
autocomplete_fields = ("signee",)
inlines = (SigneeSignatureRepresentativeInline,)
extra = 0
class ContractFileInline(NestedTabularInline):
class ContractFileInline(ParentContractInlineMixin, NestedTabularInline):
model = ContractFile
form = ContractFileAdminForm
extra = 0
class ContractApprovalInline(NestedTabularInline):
class ContractApprovalInline(ParentContractInlineMixin, NestedTabularInline):
model = ContractApproval
extra = 0
class ContractIntentInline(NestedTabularInline):
class ContractIntentInline(ParentContractInlineMixin, NestedTabularInline):
model = ContractIntent
extra = 0
class ContractAdmin(
OwnPermissionsMixin,
permissions_mixin_factory(
"contracts.edit_when_approved",
"contracts.delete_when_approved",
obj_conditional=lambda request, obj: not obj.is_editable_without_approve_permission,
),
MarkdownxGuardedModelAdmin,
NestedModelAdmin,
):
......@@ -538,11 +562,32 @@ class ContractAdmin(
return parent_save_response
def get_readonly_fields(self, request, obj=None):
readonly_fields = []
fields = []
for fieldset in self.get_fieldsets(request):
fields += fieldset[1]["fields"]
if (
obj.created_by == request.user
and obj.status == obj.StatusTypes.TO_BE_APPROVED
and not request.user.has_perm("contracts.edit_when_approved")
):
fields.remove("status")
print("returning", fields)
return fields
return list(self.readonly_fields)
def has_change_permission(self, request, obj=None):
if (
obj is not None
and not request.user.has_perm("contracts.edit_when_approved")
and not obj.is_editable_without_approve_permission
and obj.status == obj.StatusTypes.APPROVED
):
return False
......@@ -556,7 +601,7 @@ class ContractAdmin(
):
return False
return super().has_change_permission(request, obj)
return super().has_delete_permission(request, obj)
list_filter = (
AutocompleteFilterFactory("Typ", "types"),
......
......@@ -131,7 +131,17 @@ class ContractAdminForm(forms.ModelForm):
choice_label,
)
)
continue
elif choice_key == Contract.StatusTypes.WORK_IN_PROGRESS:
allowed_choices.append(
(
choice_key,
choice_label,
)
)
continue
if self.instance.status == Contract.StatusTypes.REJECTED:
if choice_key in (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment