Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Public contract registry
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Public contract registry
Commits
cf689ac1
Commit
cf689ac1
authored
1 year ago
by
Alexa Valentová
Browse files
Options
Downloads
Patches
Plain Diff
improve UI & permissions
parent
5ee62572
No related branches found
No related tags found
No related merge requests found
Pipeline
#17164
passed
1 year ago
Stage: build
Stage: test_deploy
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
contracts/admin.py
+59
-14
59 additions, 14 deletions
contracts/admin.py
contracts/forms.py
+10
-0
10 additions, 0 deletions
contracts/forms.py
with
69 additions
and
14 deletions
contracts/admin.py
+
59
−
14
View file @
cf689ac1
...
...
@@ -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_
chang
e_permission
(
request
,
obj
)
return
super
().
has_
delet
e_permission
(
request
,
obj
)
list_filter
=
(
AutocompleteFilterFactory
(
"
Typ
"
,
"
types
"
),
...
...
This diff is collapsed.
Click to expand it.
contracts/forms.py
+
10
−
0
View file @
cf689ac1
...
...
@@ -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
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment