diff --git a/cps/admin.py b/cps/admin.py
index aee7fd096..6aca350a0 100644
--- a/cps/admin.py
+++ b/cps/admin.py
@@ -185,6 +185,8 @@ def view_configuration():
content.config_default_role = content.config_default_role + ub.ROLE_ADMIN
if "download_role" in to_save:
content.config_default_role = content.config_default_role + ub.ROLE_DOWNLOAD
+ if "viewer_role" in to_save:
+ content.config_default_role = content.config_default_role + ub.ROLE_VIEWER
if "upload_role" in to_save:
content.config_default_role = content.config_default_role + ub.ROLE_UPLOAD
if "edit_role" in to_save:
@@ -651,6 +653,11 @@ def edit_user(user_id):
elif "download_role" not in to_save and content.role_download():
content.role = content.role - ub.ROLE_DOWNLOAD
+ if "viewer_role" in to_save and not content.role_viewer():
+ content.role = content.role + ub.ROLE_VIEWER
+ elif "viewer_role" not in to_save and content.role_viewer():
+ content.role = content.role - ub.ROLE_VIEWER
+
if "upload_role" in to_save and not content.role_upload():
content.role = content.role + ub.ROLE_UPLOAD
elif "upload_role" not in to_save and content.role_upload():
diff --git a/cps/templates/admin.html b/cps/templates/admin.html
index 89c598a7f..ee92996e8 100644
--- a/cps/templates/admin.html
+++ b/cps/templates/admin.html
@@ -12,6 +12,7 @@
{{_('DLS')}} |
{{_('Admin')}} |
{{_('Download')}} |
+ {{_('View Ebooks')}} |
{{_('Upload')}} |
{{_('Edit')}} |
@@ -24,6 +25,7 @@
{{user.downloads.count()}} |
{% if user.role_admin() %}{% else %}{% endif %} |
{% if user.role_download() %}{% else %}{% endif %} |
+ {% if user.role_viewer() %}{% else %}{% endif %} |
{% if user.role_upload() %}{% else %}{% endif %} |
{% if user.role_edit() %}{% else %}{% endif %} |
diff --git a/cps/templates/config_view_edit.html b/cps/templates/config_view_edit.html
index a6601a58c..bc6defa40 100644
--- a/cps/templates/config_view_edit.html
+++ b/cps/templates/config_view_edit.html
@@ -84,6 +84,10 @@
+
+
+
+
diff --git a/cps/templates/detail.html b/cps/templates/detail.html
index 5fd0871ee..49869713a 100644
--- a/cps/templates/detail.html
+++ b/cps/templates/detail.html
@@ -53,7 +53,7 @@
{% endif %}
{% endif %}
- {% if reader_list %}
+ {% if reader_list and g.user.role_viewer() %}
+
+
+
+
diff --git a/cps/ub.py b/cps/ub.py
index ce389cb83..a37c10dfd 100644
--- a/cps/ub.py
+++ b/cps/ub.py
@@ -54,6 +54,7 @@ ROLE_PASSWD = 16
ROLE_ANONYMOUS = 32
ROLE_EDIT_SHELFS = 64
ROLE_DELETE_BOOKS = 128
+ROLE_VIEWER = 256
DETAIL_RANDOM = 1
@@ -202,6 +203,10 @@ class UserBase:
def role_delete_books(self):
return bool((self.role is not None)and(self.role & ROLE_DELETE_BOOKS == ROLE_DELETE_BOOKS))
+
+ def role_viewer(self):
+ return bool((self.role is not None)and(self.role & ROLE_VIEWER == ROLE_VIEWER))
+
@property
def is_active(self):
return True
@@ -549,6 +554,12 @@ class Config:
else:
return False
+ def role_viewer(self):
+ if self.config_default_role is not None:
+ return True if self.config_default_role & ROLE_VIEWER == ROLE_VIEWER else False
+ else:
+ return False
+
def role_upload(self):
if self.config_default_role is not None:
return True if self.config_default_role & ROLE_UPLOAD == ROLE_UPLOAD else False
@@ -853,7 +864,8 @@ def create_anonymous_user():
def create_admin_user():
user = User()
user.nickname = "admin"
- user.role = ROLE_USER + ROLE_ADMIN + ROLE_DOWNLOAD + ROLE_UPLOAD + ROLE_EDIT + ROLE_DELETE_BOOKS + ROLE_PASSWD
+ user.role = ROLE_USER + ROLE_ADMIN + ROLE_DOWNLOAD + ROLE_UPLOAD + ROLE_EDIT + ROLE_DELETE_BOOKS + ROLE_PASSWD +\
+ ROLE_VIEWER
user.sidebar_view = DETAIL_RANDOM + SIDEBAR_LANGUAGE + SIDEBAR_SERIES + SIDEBAR_CATEGORY + SIDEBAR_HOT + \
SIDEBAR_RANDOM + SIDEBAR_AUTHOR + SIDEBAR_BEST_RATED + SIDEBAR_READ_AND_UNREAD + SIDEBAR_RECENT + \
SIDEBAR_SORTED + MATURE_CONTENT + SIDEBAR_PUBLISHER + SIDEBAR_RATING + SIDEBAR_FORMAT
diff --git a/cps/web.py b/cps/web.py
index 7f4289b54..8084de9f3 100644
--- a/cps/web.py
+++ b/cps/web.py
@@ -203,6 +203,16 @@ def download_required(f):
return inner
+def viewer_required(f):
+ @wraps(f)
+ def inner(*args, **kwargs):
+ if current_user.role_viewer():
+ return f(*args, **kwargs)
+ abort(403)
+
+ return inner
+
+
def upload_required(f):
@wraps(f)
def inner(*args, **kwargs):
@@ -972,6 +982,7 @@ def get_cover(book_id):
@web.route("/show//")
@login_required_if_no_ano
+@viewer_required
def serve_book(book_id, book_format):
book_format = book_format.split(".")[0]
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
@@ -1276,6 +1287,7 @@ def profile():
@web.route("/read//")
@login_required_if_no_ano
+@viewer_required
def read_book(book_id, book_format):
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
if not book: