Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nk20
Manage
Activity
Members
Labels
Plan
Issues
32
Issue boards
Milestones
Wiki
Code
Merge requests
6
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
BDE
nk20
Commits
e461d70b
Commit
e461d70b
authored
5 years ago
by
ynerant
Browse files
Options
Downloads
Patches
Plain Diff
Improve add permissions
parent
057f42fd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!10
Système de droits
Pipeline
#7963
passed with warnings with stages
in 4 minutes and 15 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/note/models/transactions.py
+4
-3
4 additions, 3 deletions
apps/note/models/transactions.py
apps/permission/models.py
+16
-4
16 additions, 4 deletions
apps/permission/models.py
apps/permission/signals.py
+4
-0
4 additions, 0 deletions
apps/permission/signals.py
with
24 additions
and
7 deletions
apps/note/models/transactions.py
+
4
−
3
View file @
e461d70b
...
...
@@ -129,14 +129,13 @@ class Transaction(PolymorphicModel):
models
.
Index
(
fields
=
[
'
destination
'
]),
]
def
save
(
self
,
*
args
,
**
kwargs
):
def
post_
save
(
self
,
*
args
,
**
kwargs
):
"""
When saving, also transfer money between two notes
"""
if
self
.
source
.
pk
==
self
.
destination
.
pk
:
# When source == destination, no money is transfered
super
().
save
(
*
args
,
**
kwargs
)
return
created
=
self
.
pk
is
None
...
...
@@ -152,10 +151,12 @@ class Transaction(PolymorphicModel):
self
.
source
.
balance
-=
to_transfer
self
.
destination
.
balance
+=
to_transfer
# We save first the transaction, in case of the user has no right to transfer money
super
().
save
(
*
args
,
**
kwargs
)
# Save notes
self
.
source
.
save
()
self
.
destination
.
save
()
super
().
save
(
*
args
,
**
kwargs
)
@property
def
total
(
self
):
...
...
This diff is collapsed.
Click to expand it.
apps/permission/models.py
+
16
−
4
View file @
e461d70b
...
...
@@ -25,13 +25,14 @@ class InstancedPermission:
Returns True if the permission applies to
the field `field_name` object `obj`
"""
if
ContentType
.
objects
.
get_for_model
(
obj
)
!=
self
.
model
:
# The permission does not apply to the model
return
False
if
self
.
type
==
'
add
'
:
if
permission_type
==
self
.
type
:
return
self
.
query
(
obj
)
if
ContentType
.
objects
.
get_for_model
(
obj
)
!=
self
.
model
:
# The permission does not apply to the model
return
False
if
permission_type
==
self
.
type
:
if
self
.
field
and
field_name
!=
self
.
field
:
return
False
...
...
@@ -202,7 +203,18 @@ class Permission(models.Model):
def
func
(
obj
):
nonlocal
q_kwargs
for
arg
in
q_kwargs
:
if
getattr
(
obj
,
arg
)
!=
q_kwargs
[
arg
]:
spl
=
arg
.
split
(
'
__
'
)
value
=
obj
last
=
None
for
s
in
spl
:
if
not
hasattr
(
obj
,
s
):
last
=
s
break
value
=
getattr
(
obj
,
s
)
if
last
==
"
lte
"
:
# TODO Add more filters
if
value
>
q_kwargs
[
arg
]:
return
False
elif
value
!=
q_kwargs
[
arg
]:
return
False
return
True
return
func
...
...
This diff is collapsed.
Click to expand it.
apps/permission/signals.py
+
4
−
0
View file @
e461d70b
...
...
@@ -14,6 +14,10 @@ EXCLUDED = [
'
contenttypes.contenttype
'
,
'
logs.changelog
'
,
'
migrations.migration
'
,
'
note.note
'
,
'
note.noteuser
'
,
'
note.noteclub
'
,
'
note.notespecial
'
,
'
sessions.session
'
,
]
...
...
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