From 15cf93ccebc6a916f4dfd0cf08a3b119b04f70b7 Mon Sep 17 00:00:00 2001 From: andre Date: Mon, 27 Mar 2023 21:01:08 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=20=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=D0=B0=D0=BC=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B8=20=D0=BF=D1=80=D0=BE=D1=81=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D1=80=D0=B8=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D1=8B=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 22 +++++++++++--------- requirements.txt | Bin 776 -> 826 bytes static/css/profile.css | 7 +++++++ static/css/user_view.css | 43 +++++++++++++++++++++++++++++++++++++++ templates/profile.html | 8 ++++++++ templates/project.html | 6 +++--- templates/user_view.html | 9 ++++++++ 7 files changed, 82 insertions(+), 13 deletions(-) diff --git a/main.py b/main.py index d645b40..46f0e08 100644 --- a/main.py +++ b/main.py @@ -45,7 +45,6 @@ with open('incepted.config', 'r', encoding='utf-8') as file: file = loads(file) key = file["encrypt_key"] app.config['SECRET_KEY'] = key -app.debug = True logging.basicConfig(level=logging.INFO, filename="logfiles/main.log", format="%(asctime)s %(levelname)s %(message)s", encoding='utf-8') csrf = CSRFProtect(app) @@ -95,7 +94,7 @@ def admin_user(login_usr): user.email = form.email.data data_session.commit() return redirect(f'/admin/user/{str(login_usr)}') - return render_template('profile.html', title=user.login, form=form, message='', user=user) + return render_template('profile.html', title=user.login, form=form, message='', user=user, admin=True) else: abort(403) abort(404) @@ -234,7 +233,8 @@ def edit_quest(id_project, id_task): current_project = data_session.query(Projects).filter(Projects.id == id_project).first() current_task = data_session.query(Quests).filter(Quests.id == id_task).first() if current_project and current_task and current_task.project == current_project.id and ( - current_task.creator == current_user.id or current_project.creator == current_user.id): + current_task.creator == current_user.id or current_project.creator == current_user.id) \ + or current_user.role == 1: form = Task() if request.method == 'GET': form.name.data = current_task.name @@ -276,7 +276,8 @@ def delete_file(id_project, id_file): current_file = data_session.query(Files).filter(Files.id == id_file).first() if current_project and current_file: if current_user.id in map(lambda x: x[0], data_session.query(StaffProjects.user).filter( - StaffProjects.project == current_project.id).all()) or current_user.id == current_project.creator: + StaffProjects.project == current_project.id).all()) or current_user.id == current_project.creator \ + or current_user.role == 1: current_proof = data_session.query(FileProof).filter(FileProof.file == id_file).all() os.remove(current_file.path) data_session.delete(current_file) @@ -306,7 +307,7 @@ def task_project(id_project, id_task): data_session = db_session.create_session() current_project = data_session.query(Projects).filter(Projects.id == id_project).first() current_task = data_session.query(Quests).filter(Quests.id == id_task).first() - if current_project and current_task and current_task.project == current_project.id: + if current_project and current_task and current_task.project == current_project.id or current_user.role == 1: form = AnswerTask() current_answer = data_session.query(Answer).filter(Answer.quest == current_task.id).first() list_files = None @@ -410,7 +411,7 @@ def edit_project(id_project): current_project = data_session.query(Projects).filter(Projects.id == id_project).first() if current_project: staff = data_session.query(StaffProjects).filter(StaffProjects.project == current_project.id).all() - if current_user.id == current_project.creator: + if current_user.id == current_project.creator or current_user.role == 1: list_users = list( map(lambda x: get_user_data(x), data_session.query(User).filter(User.id != current_user.id, User.activated == 1).all())) @@ -472,7 +473,8 @@ def project(id_project): current_project = data_session.query(Projects).filter(Projects.id == id_project).first() if current_project: staff = data_session.query(StaffProjects).filter(StaffProjects.project == current_project.id).all() - if current_user.id == current_project.creator or current_user.id in list(map(lambda x: x.user, staff)): + if current_user.id == current_project.creator or current_user.id in list( + map(lambda x: x.user, staff)) or current_user.role == 1: staff = list(map(lambda x: get_user_data(x), data_session.query(User).filter( User.id.in_(list(map(lambda x: x.user, staff)))).all())) if staff else [] quests = data_session.query(Quests).filter(Quests.project == current_project.id).all() @@ -685,7 +687,7 @@ def profile(): user = data_session.query(User).filter(User.id == current_user.id).first() if not user: return render_template('profile.html', title='Профиль', form=form, - message='Ошибка, пользователь ненайден', user=current_user) + message='Ошибка, пользователь ненайден', user=current_user, admin=False) os.remove(current_user.photo) user.photo = 'static/images/none_logo.png' data_session.commit() @@ -693,7 +695,7 @@ def profile(): user = data_session.query(User).filter(User.id == current_user.id).first() if not user: return render_template('profile.html', title='Профиль', form=form, - message='Ошибка, пользователь ненайден', user=current_user) + message='Ошибка, пользователь ненайден', user=current_user, admin=False) if form.email.data != current_user.email: token = s.dumps(form.email.data) link_conf = url_for('confirmation', token=token, _external=True) @@ -711,7 +713,7 @@ def profile(): user.birthday = form.birthday.data data_session.commit() return redirect('/profile') - return render_template('profile.html', title='Профиль', form=form, message='', user=current_user) + return render_template('profile.html', title='Профиль', form=form, message='', user=current_user, admin=False) else: return redirect('/login') diff --git a/requirements.txt b/requirements.txt index 9a2be68958574b37c82f85c6031cf10315e7bc81..a11b27644c8e2212aa4b72d9482dbac091b1a260 100644 GIT binary patch delta 105 zcmeBR+r>8F0Hg85gT;)7lT8^_8I2}KGv)%xw~XSGA24pQHDb_XFaTn623`g(h7yKK xh6096hCGIJhIoclh6
{{ form.submit(type="submit", class="profile_button") }} + {% if admin %} + +
+

Профиль

+
+
+ {% else %}

Выйти

+ {% endif %}
diff --git a/templates/project.html b/templates/project.html index 261dd93..9f0cb54 100644 --- a/templates/project.html +++ b/templates/project.html @@ -8,7 +8,7 @@
- {% if current_user.id == project.creator %} + {% if current_user.id == project.creator or current_user.role == 1 %} - {% if quest.creator == current_user.id or project.creator == current_user.id %} + {% if quest.creator == current_user.id or project.creator == current_user.id or current_user.role == 1 %}
- {% if current_user.id == project.creator or item['object'].user == current_user.id %} + {% if current_user.id == project.creator or item['object'].user == current_user.id or current_user.role == 1%}

Удалить

{% endif %} diff --git a/templates/user_view.html b/templates/user_view.html index ea8fba9..a067754 100644 --- a/templates/user_view.html +++ b/templates/user_view.html @@ -76,6 +76,15 @@

{{ project.description }}

+ {% if current_user.role == 1 %} + + {% endif %}