Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Ebooko
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
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TheJoeCoder
Ebooko
Commits
cd79b1b9
Verified
Commit
cd79b1b9
authored
11 months ago
by
TheJoeCoder
Browse files
Options
Downloads
Patches
Plain Diff
Add permissions for book view
parent
8611e9d2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
reader/views.py
+14
-0
14 additions, 0 deletions
reader/views.py
with
14 additions
and
0 deletions
reader/views.py
+
14
−
0
View file @
cd79b1b9
from
django.contrib.auth.decorators
import
login_required
from
django.core.exceptions
import
PermissionDenied
from
django.shortcuts
import
render
,
redirect
,
get_object_or_404
from
reader.forms
import
BookForm
...
...
@@ -54,6 +55,19 @@ def view_book(request, book_id):
# Get book
book
=
get_object_or_404
(
Book
,
id
=
book_id
)
# Check user has permission to access this book
has_permission
=
False
if
book
.
public
:
has_permission
=
True
elif
book
.
owner
==
request
.
user
:
has_permission
=
True
elif
request
.
user
.
is_authenticated
:
has_permission
=
(
request
.
user
.
has_perm
(
"
reader.book_view_others
"
,
book
)
or
request
.
user
.
has_perm
(
"
reader.book_view_others
"
))
if
not
has_permission
:
raise
PermissionDenied
# Get the user's book stats for this book
user_book_q
=
None
if
request
.
user
.
is_authenticated
:
...
...
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