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
bf0fe347
Commit
bf0fe347
authored
Dec 13, 2021
by
ynerant
Browse files
Merge branch 'lock-club-notes' into 'beta'
Verrouillage de notes See merge request
!190
parents
41289857
45ba4f95
Pipeline
#9583
passed with stages
in 14 minutes and 45 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/member/views.py
View file @
bf0fe347
...
...
@@ -18,7 +18,7 @@ from django.views.generic import DetailView, UpdateView, TemplateView
from
django.views.generic.edit
import
FormMixin
from
django_tables2.views
import
SingleTableView
from
rest_framework.authtoken.models
import
Token
from
note.models
import
Alias
,
NoteUser
from
note.models
import
Alias
,
NoteUser
,
NoteClub
from
note.models.transactions
import
Transaction
,
SpecialTransaction
from
note.tables
import
HistoryTable
,
AliasTable
from
note_kfet.middlewares
import
_set_current_request
...
...
@@ -174,7 +174,7 @@ class UserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
modified_note
=
NoteUser
.
objects
.
get
(
pk
=
user
.
note
.
pk
)
# Don't log these tests
modified_note
.
_no_signal
=
True
modified_note
.
is_active
=
Tru
e
modified_note
.
is_active
=
Fals
e
modified_note
.
inactivity_reason
=
'manual'
context
[
"can_lock_note"
]
=
user
.
note
.
is_active
and
PermissionBackend
\
.
check_perm
(
self
.
request
,
"note.change_noteuser_is_active"
,
modified_note
)
...
...
@@ -183,14 +183,14 @@ class UserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
modified_note
.
_force_save
=
True
modified_note
.
save
()
context
[
"can_force_lock"
]
=
user
.
note
.
is_active
and
PermissionBackend
\
.
check_perm
(
self
.
request
,
"note.change_note_is_active"
,
modified_note
)
.
check_perm
(
self
.
request
,
"note.change_note
user
_is_active"
,
modified_note
)
old_note
.
_force_save
=
True
old_note
.
_no_signal
=
True
old_note
.
save
()
modified_note
.
refresh_from_db
()
modified_note
.
is_active
=
True
context
[
"can_unlock_note"
]
=
not
user
.
note
.
is_active
and
PermissionBackend
\
.
check_perm
(
self
.
request
,
"note.change_note_is_active"
,
modified_note
)
.
check_perm
(
self
.
request
,
"note.change_note
user
_is_active"
,
modified_note
)
return
context
...
...
@@ -404,9 +404,12 @@ class ClubDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
"""
context
=
super
().
get_context_data
(
**
kwargs
)
club
=
context
[
"club"
]
club
=
self
.
object
context
[
"note"
]
=
club
.
note
if
PermissionBackend
.
check_perm
(
self
.
request
,
"member.change_club_membership_start"
,
club
):
club
.
update_membership_dates
()
# managers list
managers
=
Membership
.
objects
.
filter
(
club
=
self
.
object
,
roles__name
=
"Bureau de club"
,
date_start__lte
=
date
.
today
(),
date_end__gte
=
date
.
today
())
\
...
...
@@ -444,6 +447,29 @@ class ClubDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
context
[
"can_add_members"
]
=
PermissionBackend
()
\
.
has_perm
(
self
.
request
.
user
,
"member.add_membership"
,
empty_membership
)
# Check permissions to see if the authenticated user can lock/unlock the note
with
transaction
.
atomic
():
modified_note
=
NoteClub
.
objects
.
get
(
pk
=
club
.
note
.
pk
)
# Don't log these tests
modified_note
.
_no_signal
=
True
modified_note
.
is_active
=
False
modified_note
.
inactivity_reason
=
'manual'
context
[
"can_lock_note"
]
=
club
.
note
.
is_active
and
PermissionBackend
\
.
check_perm
(
self
.
request
,
"note.change_noteclub_is_active"
,
modified_note
)
old_note
=
NoteClub
.
objects
.
select_for_update
().
get
(
pk
=
club
.
note
.
pk
)
modified_note
.
inactivity_reason
=
'forced'
modified_note
.
_force_save
=
True
modified_note
.
save
()
context
[
"can_force_lock"
]
=
club
.
note
.
is_active
and
PermissionBackend
\
.
check_perm
(
self
.
request
,
"note.change_noteclub_is_active"
,
modified_note
)
old_note
.
_force_save
=
True
old_note
.
_no_signal
=
True
old_note
.
save
()
modified_note
.
refresh_from_db
()
modified_note
.
is_active
=
True
context
[
"can_unlock_note"
]
=
not
club
.
note
.
is_active
and
PermissionBackend
\
.
check_perm
(
self
.
request
,
"note.change_noteclub_is_active"
,
modified_note
)
return
context
...
...
apps/note/tables.py
View file @
bf0fe347
...
...
@@ -198,14 +198,15 @@ class ButtonTable(tables.Table):
)
hideshow
=
tables
.
Column
(
verbose_name
=
_
(
"Hide/Show"
),
accessor
=
"pk"
,
attrs
=
{
'td'
:
{
'class'
:
'col-sm-1'
,
'id'
:
lambda
record
:
"hideshow_"
+
str
(
record
.
pk
),
}
})
verbose_name
=
_
(
"Hide/Show"
),
accessor
=
"pk"
,
attrs
=
{
'td'
:
{
'class'
:
'col-sm-1'
,
'id'
:
lambda
record
:
"hideshow_"
+
str
(
record
.
pk
),
}
},
)
delete_col
=
tables
.
TemplateColumn
(
template_code
=
DELETE_TEMPLATE
,
extra_context
=
{
"delete_trans"
:
_
(
'delete'
)},
...
...
apps/permission/fixtures/initial.json
View file @
bf0fe347
...
...
@@ -2511,7 +2511,7 @@
"note"
,
"noteuser"
],
"query"
:
"[
\"
AND
\"
, {
\"
user
\"
: [
\"
user
\"
]}, [
\"
OR
\"
, {
\"
inactivity_reason
\"
:
\"
manual
\"
}, {
\"
i
n
activ
ity_reason
\"
: null
}]]"
,
"query"
:
"[
\"
AND
\"
, {
\"
user
\"
: [
\"
user
\"
]}, [
\"
OR
\"
, {
\"
inactivity_reason
\"
:
\"
manual
\"
}, {
\"
i
s_
activ
e
\"
: true
}]]"
,
"type"
:
"change"
,
"mask"
:
1
,
"field"
:
"is_active"
,
...
...
@@ -2527,7 +2527,7 @@
"note"
,
"noteuser"
],
"query"
:
"[
\"
AND
\"
, {
\"
user
\"
: [
\"
user
\"
]}, [
\"
OR
\"
, {
\"
inactivity_reason
\"
:
\"
manual
\"
}, {
\"
i
n
activ
ity_reason
\"
: null
}]]"
,
"query"
:
"[
\"
AND
\"
, {
\"
user
\"
: [
\"
user
\"
]}, [
\"
OR
\"
, {
\"
inactivity_reason
\"
:
\"
manual
\"
}, {
\"
i
s_
activ
e
\"
: true
}]]"
,
"type"
:
"change"
,
"mask"
:
1
,
"field"
:
"inactivity_reason"
,
...
...
@@ -2871,6 +2871,38 @@
"description"
:
"Changer l'image de n'importe quelle note"
}
},
{
"model"
:
"permission.permission"
,
"pk"
:
184
,
"fields"
:
{
"model"
:
[
"note"
,
"noteclub"
],
"query"
:
"[
\"
AND
\"
, {
\"
club
\"
: [
\"
club
\"
]}, [
\"
OR
\"
, {
\"
inactivity_reason
\"
:
\"
manual
\"
}, {
\"
is_active
\"
: true}]]"
,
"type"
:
"change"
,
"mask"
:
3
,
"field"
:
"is_active"
,
"permanent"
:
true
,
"description"
:
"(Dé)bloquer la note de son club manuellement"
}
},
{
"model"
:
"permission.permission"
,
"pk"
:
185
,
"fields"
:
{
"model"
:
[
"note"
,
"noteclub"
],
"query"
:
"[
\"
AND
\"
, {
\"
club
\"
: [
\"
club
\"
]}, [
\"
OR
\"
, {
\"
inactivity_reason
\"
:
\"
manual
\"
}, {
\"
is_active
\"
: true}]]"
,
"type"
:
"change"
,
"mask"
:
3
,
"field"
:
"inactivity_reason"
,
"permanent"
:
true
,
"description"
:
"(Dé)bloquer la note de son club et indiquer que cela a été fait manuellement"
}
},
{
"model"
:
"permission.role"
,
"pk"
:
1
,
...
...
@@ -3010,7 +3042,9 @@
166
,
167
,
168
,
182
182
,
184
,
185
]
}
},
...
...
@@ -3278,7 +3312,9 @@
180
,
181
,
182
,
183
183
,
184
,
185
]
}
},
...
...
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