Добавил возможность админам редактировать и просматривать проекты пользователей

This commit is contained in:
Андрей Дувакин 2023-03-27 21:01:08 +05:00
parent 0c587d0eff
commit 15cf93cceb
7 changed files with 82 additions and 13 deletions

22
main.py
View File

@ -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')

Binary file not shown.

View File

@ -92,6 +92,10 @@ form {
vertical-align: middle;
font-size: 1.5vw;
}
.profile_button:hover {
color: #ffffff;
text-decoration: none;
}
#delete_button {
margin-top: 45px;
}
@ -166,4 +170,7 @@ form {
}
.about {
border-radius: 2vw !important;
}
.profile_button_text {
color: #ffffff;
}

View File

@ -217,4 +217,47 @@
}
.link_to_user:hover {
text-decoration: none;
}
.open_project_block {
width: 20%;
height: 90%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
flex-wrap: nowrap;
}
.open_button {
background-color: #ffffff;
color: #000000;
width: 15vw;
height: 4.5vw;
vertical-align: middle;
border-radius: 5vw;
display: flex;
align-items: center;
justify-content: center;
}
.open_button:hover {
text-decoration: none;
color: #000000;
}
.open_button_text {
font-size: 1.5vw;
margin-top: 15px;
display: flex;
align-items: center;
justify-content: center;
}
.open_button, .open_button_link {
display: flex;
align-items: center;
justify-content: center;
width: 15vw;
height: 4.5vw;
color: #000000;
}
.open_button_link:hover {
text-decoration: none;
color: #000000;
}

View File

@ -77,11 +77,19 @@
</div>
<div class="form_data_button">
{{ form.submit(type="submit", class="profile_button") }}
{% if admin %}
<a class="profile_button" href="/user/{{user.login}}">
<div class="profile_button_text" id="profile_button_text">
<p>Профиль</p>
</div>
</a>
{% else %}
<a class="profile_button" id="logout_button" href="/logout">
<div class="profile_button_text">
<p>Выйти</p>
</div>
</a>
{% endif %}
</div>
</form>
</div>

View File

@ -8,7 +8,7 @@
</div>
<div class="project_header">
<div class="edit_block">
{% if current_user.id == project.creator %}
{% if current_user.id == project.creator or current_user.role == 1 %}
<div class="edit_button">
<a id="edit_button" class="edit_button_link" href="">
<p class="edit_button_text">Редактировать</p>
@ -110,7 +110,7 @@
<p class="quest_solve_text">Решить</p>
</a>
</div>
{% 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 %}
<div class="link_edit_block">
<a class="link_edit" href="{{ project.id }}/quest/{{ quest.id }}/edit">
<p class="link_edit_text">Редактировать</p>
@ -177,7 +177,7 @@
</div>
<div class="file_buttons">
<div class="btn-group file_buttons_groud">
{% 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%}
<a href="../project/{{ project.id }}/file/{{ item['object'].id }}/delete?from=project"
class="btn btn-primary file_delete"><p class="button_text">Удалить</p></a>
{% endif %}

View File

@ -76,6 +76,15 @@
<p class="description_text">{{ project.description }}</p>
</div>
</div>
{% if current_user.role == 1 %}
<div class="open_project_block">
<div class="open_button">
<a class="open_button_link" href="/project/{{ project.id }}">
<p class="open_button_text">Открыть</p>
</a>
</div>
</div>
{% endif %}
</div>
</div>
</div>