Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BDE
nk20
Commits
78586b93
Commit
78586b93
authored
Sep 07, 2020
by
ynerant
Browse files
Don't trigger signals when we add an object through a permission check
parent
35341661
Pipeline
#8693
passed with stages
in 11 minutes and 22 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/logs/signals.py
View file @
78586b93
...
...
@@ -50,7 +50,7 @@ def save_object(sender, instance, **kwargs):
in order to store each modification made
"""
# noinspection PyProtectedMember
if
instance
.
_meta
.
label_lower
in
EXCLUDED
or
hasattr
(
instance
,
"_no_
log
"
):
if
instance
.
_meta
.
label_lower
in
EXCLUDED
or
hasattr
(
instance
,
"_no_
signal
"
):
return
# noinspection PyProtectedMember
...
...
@@ -117,7 +117,7 @@ def delete_object(sender, instance, **kwargs):
Each time a model is deleted, an entry in the table `Changelog` is added in the database
"""
# noinspection PyProtectedMember
if
instance
.
_meta
.
label_lower
in
EXCLUDED
or
hasattr
(
instance
,
"_no_
log
"
):
if
instance
.
_meta
.
label_lower
in
EXCLUDED
or
hasattr
(
instance
,
"_no_
signal
"
):
return
# Si un utilisateur est connecté, on récupère l'utilisateur courant ainsi que son adresse IP
...
...
apps/member/signals.py
View file @
78586b93
...
...
@@ -6,7 +6,7 @@ def save_user_profile(instance, created, raw, **_kwargs):
"""
Hook to create and save a profile when an user is updated if it is not registered with the signup form
"""
if
not
raw
and
created
and
instance
.
is_active
:
if
not
raw
and
created
and
instance
.
is_active
and
not
hasattr
(
instance
,
"_no_signal"
)
:
from
.models
import
Profile
Profile
.
objects
.
get_or_create
(
user
=
instance
)
if
instance
.
is_superuser
:
...
...
apps/note/signals.py
View file @
78586b93
...
...
@@ -6,7 +6,8 @@ def save_user_note(instance, raw, **_kwargs):
"""
Hook to create and save a note when an user is updated
"""
if
not
raw
and
(
instance
.
is_superuser
or
instance
.
profile
.
registration_valid
):
if
not
raw
and
(
instance
.
is_superuser
or
instance
.
profile
.
registration_valid
)
\
and
not
hasattr
(
instance
,
"_no_signal"
):
# Create note only when the registration is validated
from
note.models
import
NoteUser
NoteUser
.
objects
.
get_or_create
(
user
=
instance
)
...
...
@@ -17,18 +18,17 @@ def save_club_note(instance, raw, **_kwargs):
"""
Hook to create and save a note when a club is updated
"""
if
raw
:
# When provisionning data, do not try to autocreate
return
from
.models
import
NoteClub
NoteClub
.
objects
.
get_or_create
(
club
=
instance
)
instance
.
note
.
save
()
# When provisionning data, do not try to autocreate
if
not
raw
and
not
hasattr
(
instance
,
"_no_signal"
):
from
.models
import
NoteClub
NoteClub
.
objects
.
get_or_create
(
club
=
instance
)
instance
.
note
.
save
()
def
delete_transaction
(
instance
,
**
_kwargs
):
"""
Whenever we want to delete a transaction (caution with this), we ensure the transaction is invalid first.
"""
instance
.
valid
=
False
instance
.
save
()
if
not
hasattr
(
instance
,
"_no_signal"
):
instance
.
valid
=
False
instance
.
save
()
apps/permission/models.py
View file @
78586b93
...
...
@@ -57,8 +57,8 @@ class InstancedPermission:
# Force insertion, no data verification, no trigger
obj
.
_force_save
=
True
# We don't want
log anything
obj
.
_
no_
log
=
True
# We don't want
to trigger any signal (log, ...)
obj
.
no_
signal
=
True
Model
.
save
(
obj
,
force_insert
=
True
)
ret
=
self
.
model
.
model_class
().
objects
.
filter
(
self
.
query
&
Q
(
pk
=
0
)).
exists
()
# Delete testing object
...
...
apps/permission/signals.py
View file @
78586b93
...
...
@@ -28,7 +28,7 @@ def pre_save_object(sender, instance, **kwargs):
if
instance
.
_meta
.
label_lower
in
EXCLUDED
:
return
if
hasattr
(
instance
,
"_force_save"
):
if
hasattr
(
instance
,
"_force_save"
)
or
hasattr
(
instance
,
"_no_signal"
)
:
return
user
=
get_current_authenticated_user
()
...
...
@@ -82,7 +82,8 @@ def pre_delete_object(instance, **kwargs):
if
instance
.
_meta
.
label_lower
in
EXCLUDED
:
return
if
hasattr
(
instance
,
"_force_delete"
)
or
hasattr
(
instance
,
"pk"
)
and
instance
.
pk
==
0
:
if
hasattr
(
instance
,
"_force_delete"
)
or
hasattr
(
instance
,
"pk"
)
and
instance
.
pk
==
0
\
or
hasattr
(
instance
,
"_no_signal"
):
# Don't check permissions on force-deleted objects
return
...
...
apps/treasury/signals.py
View file @
78586b93
...
...
@@ -9,9 +9,10 @@ def save_special_transaction(instance, created, **kwargs):
When a special transaction is created, we create its linked proxy
"""
if
instance
.
is_credit
():
if
created
and
RemittanceType
.
objects
.
filter
(
note
=
instance
.
source
).
exists
():
SpecialTransactionProxy
.
objects
.
create
(
transaction
=
instance
,
remittance
=
None
).
save
()
else
:
if
created
and
RemittanceType
.
objects
.
filter
(
note
=
instance
.
destination
).
exists
():
SpecialTransactionProxy
.
objects
.
create
(
transaction
=
instance
,
remittance
=
None
).
save
()
if
not
hasattr
(
instance
,
"_no_signal"
):
if
instance
.
is_credit
():
if
created
and
RemittanceType
.
objects
.
filter
(
note
=
instance
.
source
).
exists
():
SpecialTransactionProxy
.
objects
.
create
(
transaction
=
instance
,
remittance
=
None
).
save
()
else
:
if
created
and
RemittanceType
.
objects
.
filter
(
note
=
instance
.
destination
).
exists
():
SpecialTransactionProxy
.
objects
.
create
(
transaction
=
instance
,
remittance
=
None
).
save
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment