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
f3384681
Verified
Commit
f3384681
authored
1 year ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
fix: simplify logic allowing to update fields
parent
02a82096
No related branches found
No related tags found
No related merge requests found
Pipeline
#7364
passed
1 year ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/serializers.py
+15
-21
15 additions, 21 deletions
program/serializers.py
with
15 additions
and
21 deletions
program/serializers.py
+
15
−
21
View file @
f3384681
...
...
@@ -381,21 +381,18 @@ class HostSerializer(serializers.ModelSerializer):
raise
exceptions
.
PermissionDenied
(
detail
=
"
You are not allowed to update this host.
"
)
# Only users with edit permissions are allowed to edit these fields
if
(
biography
:
=
validated_data
.
get
(
"
biography
"
)
)
and
"
biography
"
not
in
user_edit_permissions
:
if
"
biography
"
in
validated_data
and
"
biography
"
not
in
user_edit_permissions
:
raise
exceptions
.
PermissionDenied
(
detail
=
"
You are not allowed to edit the host’s biography.
"
)
else
:
instance
.
biography
=
biography
if
(
name
:
=
validated_data
.
get
(
"
name
"
))
and
"
name
"
not
in
user_edit_permissions
:
if
"
name
"
in
validated_data
and
"
name
"
not
in
user_edit_permissions
:
raise
exceptions
.
PermissionDenied
(
detail
=
"
You are not allowed to edit the host’s name.
"
)
else
:
instance
.
name
=
name
instance
.
biography
=
validated_data
.
get
(
"
biography
"
,
instance
.
biography
)
instance
.
name
=
validated_data
.
get
(
"
name
"
,
instance
.
name
)
# Only update these fields if the user is privileged, ignore otherwise
if
user_is_privileged
:
...
...
@@ -606,30 +603,27 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer):
raise
exceptions
.
PermissionDenied
(
detail
=
"
You are not allowed to update this show.
"
)
# Only users with edit permissions are allowed to update these fields
if
(
description
:
=
validated_data
.
get
(
"
description
"
)
)
and
"
description
"
not
in
user_edit_permissions
:
if
"
description
"
in
validated_data
and
"
description
"
not
in
user_edit_permissions
:
raise
exceptions
.
PermissionDenied
(
detail
=
"
You are not allowed to edit the show’s description.
"
)
else
:
instance
.
description
=
description
if
(
name
:
=
validated_data
.
get
(
"
name
"
))
and
"
name
"
not
in
user_edit_permissions
:
if
"
name
"
in
validated_data
and
"
name
"
not
in
user_edit_permissions
:
raise
exceptions
.
PermissionDenied
(
detail
=
"
You are not allowed to edit the show’s name.
"
)
else
:
instance
.
name
=
name
if
(
short_description
:
=
validated_data
.
get
(
"
short_description
"
)
)
and
"
short_description
"
not
in
user_edit_permissions
:
"
short_description
"
in
validated_data
and
"
short_description
"
not
in
user_edit_permissions
):
raise
exceptions
.
PermissionDenied
(
detail
=
"
You are not allowed to edit the show’s short description.
"
)
else
:
instance
.
short_description
=
short_description
instance
.
description
=
validated_data
.
get
(
"
description
"
,
instance
.
description
)
instance
.
name
=
validated_data
.
get
(
"
name
"
,
instance
.
name
)
instance
.
short_description
=
validated_data
.
get
(
"
name
"
,
instance
.
name
)
# Only update these fields if the user is privileged, ignore otherwise
if
user_is_privileged
:
...
...
@@ -642,7 +636,7 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer):
"
funding_category_id
"
,
instance
.
funding_category
)
instance
.
image
=
validated_data
.
get
(
"
image_id
"
,
instance
.
image
)
instance
.
internal_note
=
validated_data
.
get
(
"
interna_note
"
,
instance
.
internal_note
)
instance
.
internal_note
=
validated_data
.
get
(
"
interna
l
_note
"
,
instance
.
internal_note
)
instance
.
is_active
=
validated_data
.
get
(
"
is_active
"
,
instance
.
is_active
)
instance
.
is_public
=
validated_data
.
get
(
"
is_public
"
,
instance
.
is_public
)
instance
.
logo
=
validated_data
.
get
(
"
logo
"
,
instance
.
logo
)
...
...
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