Browse Source

feat: 提取ReadUserInfo检查

SongZihuan 3 years ago
parent
commit
e81b6d6466
6 changed files with 13 additions and 7 deletions
  1. 1 1
      templates/docx/article.html
  2. 2 2
      templates/index/index.html
  3. 1 1
      templates/msg/msg.html
  4. 2 1
      view/docx.py
  5. 5 1
      view/index.py
  6. 2 1
      view/msg.py

+ 1 - 1
templates/docx/article.html

@@ -83,7 +83,7 @@
                         <section class="col-12">
                             <div class="comment">
                                 <p class="comment-title h5">
-                                    {% if current_user.check_role("ReadUserInfo") %}  {# 判断是否可读取用户信息 #}
+                                    {% if show_email %}  {# 判断是否可读取用户信息 #}
                                         {{ comment.auth.email }}
                                     {% else %}
                                         {{ comment.auth.s_email }}

+ 2 - 2
templates/index/index.html

@@ -54,7 +54,7 @@
                     {% for msg in msg_list %}
                         <div class="msg mr-0 mr-lg-2">
                             <p class="msg-title h5">
-                                {% if current_user.check_role("ReadUserInfo") %}  {# 判断是否可读取用户信息 #}
+                                {% if show_email %}  {# 判断是否可读取用户信息 #}
                                     {{ msg.auth.email }}
                                 {% else %}
                                     {{ msg.auth.s_email }}
@@ -70,7 +70,7 @@
                     {% for msg in msg_list %}
                         <div class="msg">
                             <p class="msg-title h5">
-                                {% if current_user.check_role("ReadUserInfo") %}  {# 判断是否可读取用户信息 #}
+                                {% if show_email %}  {# 判断是否可读取用户信息 #}
                                     {{ msg.auth.email }}
                                 {% else %}
                                     {{ msg.auth.s_email }}

+ 1 - 1
templates/msg/msg.html

@@ -65,7 +65,7 @@
                             {% endif %}
 
                             <p class="msg-title h5">
-                                {% if current_user.check_role("ReadUserInfo") %}  {# 判断是否可读取用户信息 #}
+                                {% if show_email %}  {# 判断是否可读取用户信息 #}
                                     {{ msg.auth.email }}
                                 {% else %}
                                     {{ msg.auth.s_email }}

+ 2 - 1
view/docx.py

@@ -78,7 +78,8 @@ def article_page(blog_id: int):
                            article=article,
                            archive_list=article.archive,
                            form=WriteCommentForm(),
-                           show_delete=current_user.check_role("DeleteComment"))
+                           show_delete=current_user.check_role("DeleteComment"),
+                           show_email=current_user.check_role("ReadUserInfo"))
 
 
 @docx.route('/comment/<int:blog>', methods=["POST"])

+ 5 - 1
view/index.py

@@ -1,5 +1,6 @@
 from flask import Flask, Blueprint, render_template
 from typing import Optional
+from flask_login import current_user
 
 from configure import conf
 from view.base import App
@@ -19,7 +20,10 @@ def hello_page():
 def index_page():
     blog_list = BlogArticle.get_blog_list(limit=5, offset=0, not_top=True)
     msg_list = load_message_list(limit=6, offset=0, show_secret=False)
-    return render_template("index/index.html", blog_list=blog_list, msg_list=msg_list)
+    return render_template("index/index.html",
+                           blog_list=blog_list,
+                           msg_list=msg_list,
+                           show_email=current_user.check_role("ReadUserInfo"))
 
 
 @index.app_errorhandler(404)

+ 2 - 1
view/msg.py

@@ -38,7 +38,8 @@ def msg_page(page: int = 1):
                            page_list=page_list,
                            form=WriteForm(),
                            is_secret=DBBit.BIT_1,
-                           show_delete=current_user.check_role("DeleteMsg"))
+                           show_delete=current_user.check_role("DeleteMsg"),
+                           show_email=current_user.check_role("ReadUserInfo"))
 
 
 @msg.route('/write', methods=["POST"])