Добавил возможность админам редактировать и просматривать проекты пользователей
This commit is contained in:
parent
0c587d0eff
commit
15cf93cceb
22
main.py
22
main.py
@ -45,7 +45,6 @@ with open('incepted.config', 'r', encoding='utf-8') as file:
|
|||||||
file = loads(file)
|
file = loads(file)
|
||||||
key = file["encrypt_key"]
|
key = file["encrypt_key"]
|
||||||
app.config['SECRET_KEY'] = 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",
|
logging.basicConfig(level=logging.INFO, filename="logfiles/main.log", format="%(asctime)s %(levelname)s %(message)s",
|
||||||
encoding='utf-8')
|
encoding='utf-8')
|
||||||
csrf = CSRFProtect(app)
|
csrf = CSRFProtect(app)
|
||||||
@ -95,7 +94,7 @@ def admin_user(login_usr):
|
|||||||
user.email = form.email.data
|
user.email = form.email.data
|
||||||
data_session.commit()
|
data_session.commit()
|
||||||
return redirect(f'/admin/user/{str(login_usr)}')
|
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:
|
else:
|
||||||
abort(403)
|
abort(403)
|
||||||
abort(404)
|
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_project = data_session.query(Projects).filter(Projects.id == id_project).first()
|
||||||
current_task = data_session.query(Quests).filter(Quests.id == id_task).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 (
|
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()
|
form = Task()
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
form.name.data = current_task.name
|
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()
|
current_file = data_session.query(Files).filter(Files.id == id_file).first()
|
||||||
if current_project and current_file:
|
if current_project and current_file:
|
||||||
if current_user.id in map(lambda x: x[0], data_session.query(StaffProjects.user).filter(
|
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()
|
current_proof = data_session.query(FileProof).filter(FileProof.file == id_file).all()
|
||||||
os.remove(current_file.path)
|
os.remove(current_file.path)
|
||||||
data_session.delete(current_file)
|
data_session.delete(current_file)
|
||||||
@ -306,7 +307,7 @@ def task_project(id_project, id_task):
|
|||||||
data_session = db_session.create_session()
|
data_session = db_session.create_session()
|
||||||
current_project = data_session.query(Projects).filter(Projects.id == id_project).first()
|
current_project = data_session.query(Projects).filter(Projects.id == id_project).first()
|
||||||
current_task = data_session.query(Quests).filter(Quests.id == id_task).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()
|
form = AnswerTask()
|
||||||
current_answer = data_session.query(Answer).filter(Answer.quest == current_task.id).first()
|
current_answer = data_session.query(Answer).filter(Answer.quest == current_task.id).first()
|
||||||
list_files = None
|
list_files = None
|
||||||
@ -410,7 +411,7 @@ def edit_project(id_project):
|
|||||||
current_project = data_session.query(Projects).filter(Projects.id == id_project).first()
|
current_project = data_session.query(Projects).filter(Projects.id == id_project).first()
|
||||||
if current_project:
|
if current_project:
|
||||||
staff = data_session.query(StaffProjects).filter(StaffProjects.project == current_project.id).all()
|
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(
|
list_users = list(
|
||||||
map(lambda x: get_user_data(x),
|
map(lambda x: get_user_data(x),
|
||||||
data_session.query(User).filter(User.id != current_user.id, User.activated == 1).all()))
|
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()
|
current_project = data_session.query(Projects).filter(Projects.id == id_project).first()
|
||||||
if current_project:
|
if current_project:
|
||||||
staff = data_session.query(StaffProjects).filter(StaffProjects.project == current_project.id).all()
|
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(
|
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 []
|
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()
|
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()
|
user = data_session.query(User).filter(User.id == current_user.id).first()
|
||||||
if not user:
|
if not user:
|
||||||
return render_template('profile.html', title='Профиль', form=form,
|
return render_template('profile.html', title='Профиль', form=form,
|
||||||
message='Ошибка, пользователь ненайден', user=current_user)
|
message='Ошибка, пользователь ненайден', user=current_user, admin=False)
|
||||||
os.remove(current_user.photo)
|
os.remove(current_user.photo)
|
||||||
user.photo = 'static/images/none_logo.png'
|
user.photo = 'static/images/none_logo.png'
|
||||||
data_session.commit()
|
data_session.commit()
|
||||||
@ -693,7 +695,7 @@ def profile():
|
|||||||
user = data_session.query(User).filter(User.id == current_user.id).first()
|
user = data_session.query(User).filter(User.id == current_user.id).first()
|
||||||
if not user:
|
if not user:
|
||||||
return render_template('profile.html', title='Профиль', form=form,
|
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:
|
if form.email.data != current_user.email:
|
||||||
token = s.dumps(form.email.data)
|
token = s.dumps(form.email.data)
|
||||||
link_conf = url_for('confirmation', token=token, _external=True)
|
link_conf = url_for('confirmation', token=token, _external=True)
|
||||||
@ -711,7 +713,7 @@ def profile():
|
|||||||
user.birthday = form.birthday.data
|
user.birthday = form.birthday.data
|
||||||
data_session.commit()
|
data_session.commit()
|
||||||
return redirect('/profile')
|
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:
|
else:
|
||||||
return redirect('/login')
|
return redirect('/login')
|
||||||
|
|
||||||
|
|||||||
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
@ -92,6 +92,10 @@ form {
|
|||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
font-size: 1.5vw;
|
font-size: 1.5vw;
|
||||||
}
|
}
|
||||||
|
.profile_button:hover {
|
||||||
|
color: #ffffff;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
#delete_button {
|
#delete_button {
|
||||||
margin-top: 45px;
|
margin-top: 45px;
|
||||||
}
|
}
|
||||||
@ -167,3 +171,6 @@ form {
|
|||||||
.about {
|
.about {
|
||||||
border-radius: 2vw !important;
|
border-radius: 2vw !important;
|
||||||
}
|
}
|
||||||
|
.profile_button_text {
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
@ -218,3 +218,46 @@
|
|||||||
.link_to_user:hover {
|
.link_to_user:hover {
|
||||||
text-decoration: none;
|
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;
|
||||||
|
}
|
||||||
@ -77,11 +77,19 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form_data_button">
|
<div class="form_data_button">
|
||||||
{{ form.submit(type="submit", class="profile_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">
|
<a class="profile_button" id="logout_button" href="/logout">
|
||||||
<div class="profile_button_text">
|
<div class="profile_button_text">
|
||||||
<p>Выйти</p>
|
<p>Выйти</p>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="project_header">
|
<div class="project_header">
|
||||||
<div class="edit_block">
|
<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">
|
<div class="edit_button">
|
||||||
<a id="edit_button" class="edit_button_link" href="">
|
<a id="edit_button" class="edit_button_link" href="">
|
||||||
<p class="edit_button_text">Редактировать</p>
|
<p class="edit_button_text">Редактировать</p>
|
||||||
@ -110,7 +110,7 @@
|
|||||||
<p class="quest_solve_text">Решить</p>
|
<p class="quest_solve_text">Решить</p>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</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">
|
<div class="link_edit_block">
|
||||||
<a class="link_edit" href="{{ project.id }}/quest/{{ quest.id }}/edit">
|
<a class="link_edit" href="{{ project.id }}/quest/{{ quest.id }}/edit">
|
||||||
<p class="link_edit_text">Редактировать</p>
|
<p class="link_edit_text">Редактировать</p>
|
||||||
@ -177,7 +177,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="file_buttons">
|
<div class="file_buttons">
|
||||||
<div class="btn-group file_buttons_groud">
|
<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"
|
<a href="../project/{{ project.id }}/file/{{ item['object'].id }}/delete?from=project"
|
||||||
class="btn btn-primary file_delete"><p class="button_text">Удалить</p></a>
|
class="btn btn-primary file_delete"><p class="button_text">Удалить</p></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@ -76,6 +76,15 @@
|
|||||||
<p class="description_text">{{ project.description }}</p>
|
<p class="description_text">{{ project.description }}</p>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user