Merge branch 'develop' into feature/documentation
# Conflicts: # main/extra_func.py
This commit is contained in:
commit
61fa8761eb
BIN
layouts/adm_layout/adm_layout.png
Normal file
BIN
layouts/adm_layout/adm_layout.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 73 KiB |
BIN
layouts/work/work.png
Normal file
BIN
layouts/work/work.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 44 KiB |
@ -6,65 +6,67 @@ from zenpy.lib.exception import APIException
|
||||
from main.models import UserProfile
|
||||
|
||||
|
||||
# Дополнительные функции
|
||||
class ZendeskAdmin:
|
||||
# Класс существует, чтобы в каждой фунциии отдельно не проверять аккаунт администратора
|
||||
credentials = {
|
||||
'subdomain': 'ngenix1612197338'
|
||||
}
|
||||
email = os.getenv('ACCESS_CONTROLLER_API_EMAIL')
|
||||
token = os.getenv('ACCESS_CONTROLLER_API_TOKEN')
|
||||
password = os.getenv('ACCESS_CONTROLLER_API_PASSWORD')
|
||||
|
||||
def set_and_get_name(user_profile: UserProfile):
|
||||
def __init__(self):
|
||||
self.create_admin()
|
||||
|
||||
def check_user(self, email: str) -> bool:
|
||||
return True if self.admin.search(email, type='user') else False
|
||||
|
||||
def get_user_name(self, email: str) -> str:
|
||||
user = self.admin.users.search(email).values[0]
|
||||
return user.name
|
||||
|
||||
def get_user_role(self, email: str) -> str:
|
||||
user = self.admin.users.search(email).values[0]
|
||||
return user.role
|
||||
|
||||
def get_user_id(self, email: str) -> str:
|
||||
user = self.admin.users.search(email).values[0]
|
||||
return user.id
|
||||
|
||||
def get_user_image(self, email: str) -> str:
|
||||
user = self.admin.users.search(email).values[0]
|
||||
return user.photo['content_url'] if user.photo else None
|
||||
|
||||
def create_admin(self) -> None:
|
||||
if self.email is None:
|
||||
raise ValueError('access_controller email not in env')
|
||||
self.credentials['email'] = os.getenv('ACCESS_CONTROLLER_API_EMAIL')
|
||||
|
||||
if self.token:
|
||||
self.credentials['token'] = self.token
|
||||
elif self.password:
|
||||
self.credentials['password'] = self.password
|
||||
else:
|
||||
raise ValueError('access_controller token or password not in env')
|
||||
self.admin = Zenpy(**self.credentials)
|
||||
try:
|
||||
self.admin.search(self.email, type='user')
|
||||
except APIException:
|
||||
raise ValueError('invalid access_controller`s login data')
|
||||
|
||||
|
||||
def update_profile(user_profile: UserProfile):
|
||||
"""
|
||||
Функция устанавливает поле :class:`username` текущим именем в Zendesk
|
||||
Функция обновляет профиль пользователя в соотвтетствии с текущим в Zendesk
|
||||
|
||||
.. TODO::
|
||||
Переделать функцию set_and_get_name с получением данных через API
|
||||
|
||||
:param UP: Объект профиля пользователя
|
||||
:type UP: :class:`main.models.UserProfile`
|
||||
:return: Имя пользователя
|
||||
:rtype: :class:`str`
|
||||
:param user_profile: Объект профиля пользователя
|
||||
:type user_profile: :class:`main.models.UserProfile`
|
||||
"""
|
||||
return user_profile.user.username
|
||||
|
||||
|
||||
def set_and_get_email(user_profile: UserProfile):
|
||||
"""
|
||||
Функция устанавливает поле :class:`user.email` текущей почтой в Zendesk
|
||||
|
||||
.. TODO::
|
||||
Переделать функцию set_and_get_email с получением данных через API
|
||||
|
||||
:param UP: Объект профиля пользователя
|
||||
:type UP: :class:`main.models.UserProfile`
|
||||
:return: Почта пользователя
|
||||
:rtype: :class:`str`
|
||||
"""
|
||||
return user_profile.user.email
|
||||
|
||||
|
||||
def set_and_get_role(user_profile: UserProfile):
|
||||
"""
|
||||
Функция устанавливает поле :class:`role` текущей ролью в Zendesk
|
||||
|
||||
.. TODO::
|
||||
Переделать функцию set_and_get_role с получением данных через API
|
||||
|
||||
:param UP: Объект профиля пользователя
|
||||
:type UP: :class:`main.models.UserProfile`
|
||||
:return: Роль пользователя
|
||||
:rtype: :class:`str`
|
||||
"""
|
||||
return user_profile.role
|
||||
|
||||
|
||||
def load_and_get_image(user_profile: UserProfile):
|
||||
"""
|
||||
Функция загружает и устанавливает изображение в поле :class:`image`
|
||||
|
||||
.. TODO::
|
||||
Переделать функцию load_and_get_image с получением изображения через API
|
||||
|
||||
:param UP: Объект профиля пользователя
|
||||
:type UP: :class:`main.models.UserProfile`
|
||||
:return: Название изображения
|
||||
:rtype: :class:`str`
|
||||
"""
|
||||
return user_profile.image.name
|
||||
user_profile.name = ZendeskAdmin().get_user_name(user_profile.user.email)
|
||||
user_profile.role = ZendeskAdmin().get_user_role(user_profile.user.email)
|
||||
user_profile.image = ZendeskAdmin().get_user_image(user_profile.user.email)
|
||||
user_profile.save()
|
||||
|
||||
|
||||
def check_user_exist(email: str) -> bool:
|
||||
@ -76,16 +78,7 @@ def check_user_exist(email: str) -> bool:
|
||||
:return: True, если существует, иначе False
|
||||
:rtype: :class:`bool`
|
||||
"""
|
||||
admin_creds = {
|
||||
'email': os.environ.get('Admin_email'),
|
||||
'subdomain': 'ngenix1612197338',
|
||||
'token': os.environ.get('Oauth_token'),
|
||||
}
|
||||
admin = Zenpy(**admin_creds)
|
||||
zenpy_user = admin.search(email, type='user')
|
||||
if zenpy_user:
|
||||
return True
|
||||
return False
|
||||
return ZendeskAdmin().check_user(email)
|
||||
|
||||
|
||||
def check_user_auth(email: str, password: str) -> bool:
|
||||
@ -97,15 +90,15 @@ def check_user_auth(email: str, password: str) -> bool:
|
||||
:param password: Пароль пользователя
|
||||
:type password: :class:`str`
|
||||
:return: True, если входные данные верны, иначе False
|
||||
:raise: :class:`APIException`: исключение, вызываемое если пользователь не аутентифицирован
|
||||
:raise :class:`APIException`: исключение, вызываемое если пользователь не аутентифицирован
|
||||
:rtype: :class:`bool`
|
||||
"""
|
||||
try:
|
||||
creds = {
|
||||
creds = {
|
||||
'email': email,
|
||||
'subdomain': 'ngenix1612197338',
|
||||
'password': password,
|
||||
'subdomain': 'ngenix1612197338',
|
||||
}
|
||||
try:
|
||||
user = Zenpy(**creds)
|
||||
user.search(email, type='user')
|
||||
except APIException:
|
||||
|
23
main/migrations/0003_auto_20210216_2222.py
Normal file
23
main/migrations/0003_auto_20210216_2222.py
Normal file
@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.1.6 on 2021-02-16 19:22
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0002_userprofile_name'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='userprofile',
|
||||
name='image',
|
||||
field=models.URLField(blank=True, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='userprofile',
|
||||
name='role',
|
||||
field=models.CharField(default='None', max_length=100),
|
||||
),
|
||||
]
|
27
main/migrations/0004_rolechangelogs.py
Normal file
27
main/migrations/0004_rolechangelogs.py
Normal file
@ -0,0 +1,27 @@
|
||||
# Generated by Django 3.1.6 on 2021-02-17 17:25
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('main', '0003_auto_20210216_2222'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='RoleChangeLogs',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.TextField()),
|
||||
('new_role', models.TextField()),
|
||||
('change_time', models.DateTimeField()),
|
||||
('changed_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='changed_by', to=settings.AUTH_USER_MODEL)),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
@ -1,7 +1,7 @@
|
||||
import os
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
|
||||
class UserProfile(models.Model):
|
||||
@ -18,6 +18,39 @@ class UserProfile(models.Model):
|
||||
"""
|
||||
|
||||
user = models.OneToOneField(to=User, on_delete=models.CASCADE)
|
||||
role = models.IntegerField()
|
||||
image = models.ImageField(upload_to='user_avatars')
|
||||
role = models.CharField(default='None', max_length=100)
|
||||
image = models.URLField(null=True, blank=True)
|
||||
name = models.CharField(default='None', max_length=100)
|
||||
|
||||
|
||||
@receiver(post_save, sender=User)
|
||||
def create_user_profile(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
UserProfile.objects.create(user=instance)
|
||||
|
||||
|
||||
@receiver(post_save, sender=User)
|
||||
def save_user_profile(sender, instance, **kwargs):
|
||||
instance.userprofile.save()
|
||||
|
||||
|
||||
class RoleChangeLogs(models.Model):
|
||||
"""
|
||||
Модель для логирования изменений ролей пользователя
|
||||
|
||||
:param user: Пользователь, которому присвоили другую роль,
|
||||
ForeignKey к модели :class:`django.contrib.auth.models.User`
|
||||
:param name: Имя пользователя
|
||||
:type name: :class:`str`
|
||||
:param new_role: Присвоенная роль
|
||||
:type new_role: :class:`str`
|
||||
:param change_time: Дата изменения роли`
|
||||
:type change_time: :class:`datetime.datetime`
|
||||
:param changed_by: Кем была изменена роль,
|
||||
ForeignKey к модели :class:`django.contrib.auth.models.User`
|
||||
"""
|
||||
user = models.ForeignKey(to=User, on_delete=models.CASCADE)
|
||||
name = models.TextField()
|
||||
new_role = models.TextField()
|
||||
change_time = models.DateTimeField()
|
||||
changed_by = models.ForeignKey(to=User, on_delete=models.CASCADE, related_name='changed_by')
|
||||
|
@ -14,8 +14,8 @@
|
||||
.img{
|
||||
width:auto;
|
||||
height:auto;
|
||||
max-width:300px!important;
|
||||
max-height:500px!important;
|
||||
max-width:100px!important;
|
||||
max-height:100px!important;
|
||||
}
|
||||
|
||||
|
||||
@ -28,8 +28,8 @@
|
||||
<div class="row">
|
||||
<div class="col-auto">
|
||||
<div class="container">
|
||||
{% if image_name %}
|
||||
<img src="{% static image_name %}" class="img img-thumbnail" alt="Аватар">
|
||||
{% if image_url %}
|
||||
<img src={{image_url}} class="img img-thumbnail" alt="Аватар">
|
||||
{% else %}
|
||||
<img src="{% static 'no_avatar.png' %}" class="img img-thumbnail" alt="Нет изображения">
|
||||
{% endif %}
|
||||
|
74
main/templates/pages/work.html
Normal file
74
main/templates/pages/work.html
Normal file
@ -0,0 +1,74 @@
|
||||
{% extends 'base/base.html' %}
|
||||
|
||||
{% load static %}
|
||||
|
||||
{% block title %}{{ pagename }}{% endblock %}
|
||||
|
||||
{% block heading %}Управление{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
<link rel="stylesheet" href="{% static 'main/css/work.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container-md">
|
||||
|
||||
<div class="new-section">
|
||||
<p class="row page-description">Основаная информация о странице</p>
|
||||
</div>
|
||||
|
||||
<div class="row justify-content-center new-section">
|
||||
<div class="col-10">
|
||||
<h6 class="table-title">Список сотрудников с правами инженера</h6>
|
||||
<table class="light-table">
|
||||
<thead>
|
||||
<th>ID</th>
|
||||
<th>email</th>
|
||||
<th>Expiration Date</th>
|
||||
<th>Name(link to profile)</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td>big_boss123@example.ru</td>
|
||||
<td>19:30 18.02.21</td>
|
||||
<td><a href="#">Иван Иванов</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>gachi_cool456@example.ru</td>
|
||||
<td>21:00 18.02.21</td>
|
||||
<td><a href="#">Пётр Петров</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row justify-content-center new-section">
|
||||
<div class="col-5">
|
||||
<div class="info">
|
||||
<div class="info-row">
|
||||
<div class="info-target">инженеров: </div>
|
||||
<div class="info-quantity">
|
||||
<div class="status-circle-small light-green"></div>
|
||||
<span class="info-quantity-value">13</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<div class="info-target">легких агентов:</div>
|
||||
<div class="info-quantity">
|
||||
<div class="status-circle-small light-yellow"></div>
|
||||
<span class="info-quantity-value">22</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-5">
|
||||
<button class="request-acess-button default-button">Получить права инженера</button>
|
||||
<button class="hand-over-acess-button default-button">Сдать права инженера</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
@ -1,8 +1,7 @@
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse_lazy
|
||||
|
||||
from main.extra_func import set_and_get_name, set_and_get_email, load_and_get_image, set_and_get_role, check_user_exist, \
|
||||
check_user_auth
|
||||
from main.extra_func import check_user_exist, check_user_auth, update_profile
|
||||
from main.models import UserProfile
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
@ -24,21 +23,15 @@ class CustomRegistrationView(RegistrationView):
|
||||
is_allowed = True
|
||||
|
||||
def register(self, form):
|
||||
self.is_allowed = True
|
||||
if check_user_exist(form.data['email']) and check_user_auth(form.data['email'], form.data['password_zen']):
|
||||
user = User.objects.create_user(
|
||||
username=form.data['username'],
|
||||
email=form.data['email'],
|
||||
password=form.data['password1']
|
||||
)
|
||||
profile = UserProfile(
|
||||
user=user,
|
||||
role=0,
|
||||
)
|
||||
set_and_get_name(profile)
|
||||
set_and_get_email(profile)
|
||||
set_and_get_role(profile)
|
||||
load_and_get_image(profile)
|
||||
profile.save()
|
||||
profile = user.userprofile
|
||||
update_profile(profile)
|
||||
else:
|
||||
self.is_allowed = False
|
||||
|
||||
@ -58,19 +51,18 @@ def profile_page(request):
|
||||
"""
|
||||
Отображение страницы профиля
|
||||
|
||||
|
||||
:param request: объект с деталями запроса
|
||||
:type request: :class:`django.http.HttpResponse`
|
||||
:return: объект ответа сервера с HTML-кодом внутри
|
||||
"""
|
||||
if request.user.is_authenticated:
|
||||
user_profile = request.user.userprofile
|
||||
user_profile = request.user.userprofile
|
||||
update_profile(user_profile)
|
||||
|
||||
context = {
|
||||
'name': set_and_get_name(user_profile),
|
||||
'email': set_and_get_email(user_profile),
|
||||
'role': set_and_get_role(user_profile),
|
||||
'image_name': load_and_get_image(user_profile),
|
||||
'email': user_profile.user.email,
|
||||
'name': user_profile.name,
|
||||
'role': user_profile.role,
|
||||
'image_url': user_profile.image,
|
||||
'pagename': 'Страница профиля'
|
||||
}
|
||||
return render(request, 'pages/profile.html', context)
|
||||
|
121
static/main/css/work.css
Normal file
121
static/main/css/work.css
Normal file
@ -0,0 +1,121 @@
|
||||
/* .all {
|
||||
display: flex;
|
||||
justify-content: start;
|
||||
} */
|
||||
|
||||
/* .menu {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
display: inline-flex;
|
||||
width: 150px;
|
||||
height: 100vh;
|
||||
background: #45729C;
|
||||
} */
|
||||
|
||||
.page-title {
|
||||
margin: auto;
|
||||
display: block;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.page-description {
|
||||
display: block;
|
||||
margin: auto;
|
||||
font-size: 1rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.new-section {
|
||||
margin-top: 50px;
|
||||
}
|
||||
|
||||
.table-title {
|
||||
text-align: center;
|
||||
margin: auto;
|
||||
font-size: 1.2rem;
|
||||
font-weight: bolder;
|
||||
}
|
||||
|
||||
.container {
|
||||
width: calc(100% - 150px);
|
||||
/* margin-left: calc(150px);
|
||||
margin-right: calc((100vw - 150px) / 2); */
|
||||
}
|
||||
|
||||
.light-table {
|
||||
font-weight: bold;
|
||||
margin: auto;
|
||||
margin-top: 10px;
|
||||
font-size: 1.2rem;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.light-table th {
|
||||
background: #515A63;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.light-table td {
|
||||
padding: 5px;
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
.light-table tr:nth-child(odd) {
|
||||
background: #93A2AF;
|
||||
}
|
||||
|
||||
.info-row {
|
||||
margin: 5px auto;
|
||||
height: 53px;
|
||||
}
|
||||
|
||||
.info-target {
|
||||
width: 200px;
|
||||
display: inline-block;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.info-quantity {
|
||||
max-width: 200px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
|
||||
.light-green {
|
||||
background: #83DC87;
|
||||
}
|
||||
|
||||
.light-yellow {
|
||||
background: #F3EB3C;
|
||||
}
|
||||
|
||||
.info-quantity-value {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
|
||||
.status-circle-small {
|
||||
margin: auto;
|
||||
display: inline-block;
|
||||
border-radius: 4px;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
}
|
||||
|
||||
.request-acess-button,
|
||||
.hand-over-acess-button {
|
||||
font-size: 1.2rem;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.default-button {
|
||||
border: none;
|
||||
display: block;
|
||||
margin: 5px auto;
|
||||
text-align: center;
|
||||
padding: 10px;
|
||||
background: #3B91D4;
|
||||
color: white;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user