Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
steering
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
Container Registry
Model registry
Operate
Environments
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
AURA
steering
Commits
9d565fb7
Verified
Commit
9d565fb7
authored
1 year ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
feat: add is_writable show filter
parent
38bc37e5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#7411
passed
1 year ago
Stage: build
Stage: deploy
Stage: release
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/filters.py
+20
-0
20 additions, 0 deletions
program/filters.py
with
20 additions
and
0 deletions
program/filters.py
+
20
−
0
View file @
9d565fb7
...
...
@@ -5,6 +5,7 @@ from django_filters import rest_framework as filters
from
django_filters
import
widgets
from
django
import
forms
from
django.conf
import
settings
from
django.db.models
import
Exists
,
OuterRef
,
Q
,
QuerySet
from
django.utils
import
timezone
from
program
import
models
...
...
@@ -80,6 +81,10 @@ class ShowFilterSet(StaticFilterHelpTextMixin, filters.FilterSet):
"
or past or upcoming shows if false.
"
),
)
is_writable
=
filters
.
BooleanFilter
(
method
=
"
filter_writable
"
,
help_text
=
"
Return only shows writable by the requesting authenticated user.
"
,
)
is_public
=
filters
.
BooleanFilter
(
field_name
=
"
is_public
"
,
help_text
=
"
Return only shows that are public/non-public.
"
,
...
...
@@ -145,6 +150,20 @@ class ShowFilterSet(StaticFilterHelpTextMixin, filters.FilterSet):
else
:
return
queryset
.
exclude
(
id__in
=
show_ids
,
is_active
=
True
)
def
filter_writable
(
self
,
queryset
:
QuerySet
,
_
:
str
,
value
:
bool
)
->
QuerySet
:
user
=
self
.
request
.
user
if
self
.
request
.
user
.
is_authenticated
else
None
user_is_privileged
=
(
user
.
groups
.
filter
(
name
=
settings
.
PRIVILEGED_GROUP
).
exists
()
if
user
else
False
)
if
value
and
user_is_privileged
:
return
queryset
elif
value
and
user
:
return
queryset
.
filter
(
owners
=
user
)
else
:
return
models
.
Show
.
objects
.
none
()
class
Meta
:
model
=
models
.
Show
fields
=
[
...
...
@@ -154,6 +173,7 @@ class ShowFilterSet(StaticFilterHelpTextMixin, filters.FilterSet):
"
host_ids
"
,
"
is_active
"
,
"
is_public
"
,
"
is_writable
"
,
"
language_ids
"
,
"
music_focus_ids
"
,
"
music_focus_slug
"
,
...
...
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