Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tdt4242-base
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
Package registry
Container 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
Håvard Farestveit
tdt4242-base
Commits
0fc87444
Commit
0fc87444
authored
4 years ago
by
Elias Sagmo Larsen
Browse files
Options
Downloads
Patches
Plain Diff
pylint/views_duplicated_code&naming_convention
parent
c29db9c8
No related branches found
No related tags found
No related merge requests found
Pipeline
#127140
passed
4 years ago
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend/secfit/comments/admin.py
+1
-1
1 addition, 1 deletion
backend/secfit/comments/admin.py
backend/secfit/comments/views.py
+11
-22
11 additions, 22 deletions
backend/secfit/comments/views.py
with
12 additions
and
23 deletions
backend/secfit/comments/admin.py
+
1
−
1
View file @
0fc87444
from
django.contrib
import
admin
from
models
import
Comment
from
comments.
models
import
Comment
# Register your models here.
...
...
This diff is collapsed.
Click to expand it.
backend/secfit/comments/views.py
+
11
−
22
View file @
0fc87444
...
...
@@ -30,32 +30,21 @@ class CommentList(
serializer
.
save
(
owner
=
self
.
request
.
user
)
def
get_queryset
(
self
):
workout_pk
=
self
.
kwargs
.
get
(
"
pk
"
)
qs
=
Comment
.
objects
.
none
()
if
workout_pk
:
qs
=
Comment
.
objects
.
filter
(
workout
=
workout_pk
)
elif
self
.
request
.
user
:
"""
A comment should be visible to the requesting user if any of the following hold:
- The comment is on a public visibility workout
- The comment was written by the user
- The comment is on a coach visibility workout and the user is the workout owner
'
s coach
- The comment is on a workout owned by the user
"""
# The code below is kind of duplicate of the one in ./permissions.py
# We should replace it with a better solution.
# Or maybe not.
qs
=
Comment
.
objects
.
filter
(
Q
(
workout__visibility
=
"
PU
"
)
|
Q
(
owner
=
self
.
request
.
user
)
|
(
Q
(
workout__visibility
=
"
CO
"
)
&
Q
(
workout__owner__coach
=
self
.
request
.
user
)
)
|
Q
(
workout__owner
=
self
.
request
.
user
)
).
distinct
()
return
qs
workout_pk
=
self
.
kwargs
.
get
(
"
pk
"
)
queryset
=
Comment
.
objects
.
none
()
if
workout_pk
:
queryset
=
Comment
.
objects
.
filter
(
workout
=
workout_pk
)
elif
self
.
request
.
user
:
queryset
=
Comment
.
objects
.
filter
(
IsCommentVisibleToUser
.
has_object_permission
).
distinct
()
return
queryset
# Details of comment
class
CommentDetail
(
...
...
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