Merge branch 'develop' into feature/documentation
# Conflicts: # README.md # main/extra_func.py # main/forms.py # main/views.py
This commit is contained in:
commit
b5f5fdf9dc
29
.dockerignore
Normal file
29
.dockerignore
Normal file
@ -0,0 +1,29 @@
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.mo
|
||||
*.db
|
||||
*.css.map
|
||||
*.egg-info
|
||||
*.sql.gz
|
||||
*.sqlite3
|
||||
.cache
|
||||
.env
|
||||
.project
|
||||
.idea
|
||||
.pydevproject
|
||||
.idea/workspace.xml
|
||||
.DS_Store
|
||||
.git/
|
||||
.sass-cache
|
||||
.vagrant/
|
||||
__pycache__
|
||||
dist
|
||||
docs
|
||||
env
|
||||
logs
|
||||
src/{{ project_name }}/settings/local.py
|
||||
src/node_modules
|
||||
web/media
|
||||
web/static/CACHE
|
||||
stats
|
||||
Dockerfile
|
25
.env.example
Normal file
25
.env.example
Normal file
@ -0,0 +1,25 @@
|
||||
ACTRL_DEBUG=1
|
||||
|
||||
ACTRL_SECRET_KEY="v1i_fb\$_jf2#1v_lcsbu&eon4u-os0^px=s^iycegdycqy&5)6"
|
||||
ACTRL_HOST="actrl.example.com"
|
||||
|
||||
ACTRL_EMAIL_HOST="smtp.mail.ru"
|
||||
ACTRL_EMAIL_PORT=2525
|
||||
ACTRL_EMAIL_TLS=1
|
||||
ACTRL_EMAIL_HOST_USER="djgr.02@mail.ru"
|
||||
ACTRL_EMAIL_HOST_PASSWORD="djangogroup02"
|
||||
ACTRL_FROM_EMAIL="djgr.02@mail.ru"
|
||||
ACTRL_SERVER_EMAIL="djgr.02@mail.ru"
|
||||
|
||||
ENG_CROLE_ID=360005209000
|
||||
LA_CROLE_ID=360005208980
|
||||
EMPL_GROUP="Поддержка"
|
||||
BUF_GROUP="Сменная группа"
|
||||
ST_EMAIL="d.krikov@ngenix.net"
|
||||
LICENSE_NO=3
|
||||
SHIFTH=12
|
||||
|
||||
ACTRL_ZENDESK_SUBDOMAIN="ngenix1612197338"
|
||||
ACTRL_API_EMAIL="email@example.com"
|
||||
ACTRL_API_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
ACTRL_API_PASSWORD=""
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -11,7 +11,9 @@ __pycache__/
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
db/
|
||||
media/
|
||||
logs/
|
||||
|
||||
# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
|
||||
# in your Git repository. Update and uncomment the following line accordingly.
|
||||
|
10
Dockerfile
Normal file
10
Dockerfile
Normal file
@ -0,0 +1,10 @@
|
||||
FROM python:3.6
|
||||
COPY ./ /access_controller
|
||||
WORKDIR /access_controller/
|
||||
RUN pip install -r requirements/prod.txt
|
||||
RUN python manage.py makemigrations
|
||||
EXPOSE 8000
|
||||
COPY start.sh /var/
|
||||
CMD bash /var/start.sh
|
||||
|
||||
|
214
README.md
214
README.md
@ -1,133 +1,153 @@
|
||||
*************************
|
||||
ZenDesk Access Controller
|
||||
*************************
|
||||
# ZenDesk Access Controller
|
||||
|
||||
******************************
|
||||
Управление правами доступа
|
||||
******************************
|
||||
## Управление правами доступа
|
||||
|
||||
**Идея** - Web приложение, выдает права пользователям системы по запросу самого пользователя. Например, из 12 человек 3
|
||||
сейчас работают с правами админа, по окончании рабочей смены они сдают свои права (освобождают места) и другие
|
||||
пользователи могут права запросить.
|
||||
Идея - написать программу(Web приложение), которая будет выдавать права пользователям системы по запросу самого
|
||||
пользователя. Например, из 12 человек 3 сейчас работают с правами админа, по окончании рабочей смены они сдают
|
||||
свои права (освобождают места) и другие пользователи могут запросить эти права в свое пользование.
|
||||
|
||||
Оставшиеся 9 человек получают права легкого агента - без прав редактирования, только чтение.
|
||||
Оставшиеся 9 человек получают права легкого агента - без прав редактирования, а только чтение.
|
||||
|
||||
Технологически приложение взаимодействует с **api** системы **Zendesk** (система обращений клиентов - жалобы),
|
||||
проверяет авторизованного пользователя на права с возможностью менять права напрямую из Zendesk (синхронизация
|
||||
с приоритетом у Zendesk).
|
||||
Из технологий - программа должна взаимодействовать с api системы Zendesk(система обращений клиентов - жалобы),
|
||||
проверять авторизованного пользователя на права(будет возможность менять права напрямую из Zendesk - нужна
|
||||
синхронизация прав с приоритетом у Zendesk).
|
||||
|
||||
Присутствует проверка, регистрации пользователя сайта на сайте Zendesk (по токену).
|
||||
Если руками в самом Zendesk права у пользователя отобрали или наоборот
|
||||
присвоили, то наша программа обновляет статус пользователя в соответствии с данными синхронизации
|
||||
(например, раз в минуту).
|
||||
|
||||
Так же в идеале должна быть проверка, что пользователь сайта существует на сайте Zendesk(по токену).
|
||||
|
||||
Сэндбокс Zendesk нам предоставит моя компания, библиотеку для работы с api уже подсказали.
|
||||
Сама программа (наша) будет обладать админскими правами и реализовывать контроль и выдачу прав другим пользователям.
|
||||
|
||||
*Итого:*
|
||||
1. Реализовать авторизацию пользователей с проверкой по API на существование такого пользователя
|
||||
2. Реализовать интерфейс со статистикой рабочих мест(занято, свободно, кто занимает)
|
||||
3. Реализовать логгирование действий(когда взял права, когда отдал - запись в файл и БД)
|
||||
4. Реализовать передачу прав приложением по запросу от пользователя и замену прав пользователя у которого права отбираются внутри Zendesk (на легкий агент)
|
||||
3. Реализовать логирование действий(когда взял права, когда отдал - запись в файл и БД)
|
||||
4. Реализовать передачу прав приложением по запросу от пользователя и замену прав пользователя
|
||||
у которого права отбираются внутри Zendesk (на легкий агент)
|
||||
5. Реализовать синхронизацию по API на проверку прав(не менялись ли в системе Zendesk)
|
||||
6. Реализовать возможность добавить большее количество админских прав
|
||||
7. Реализовать возможность добавления легких агентов(права только на просмотр)
|
||||
8. Реализовать на общей странице текущую информацию о пользователе - текущие права, карточка пользователя
|
||||
|
||||
************************
|
||||
Технологический стек:
|
||||
************************
|
||||
|
||||
## Технологический стек:
|
||||
- Python 3
|
||||
- Django 3
|
||||
|
||||
**************
|
||||
Quickstart
|
||||
**************
|
||||
``sudo apt install make``
|
||||
|
||||
``pip install --upgrade pip``
|
||||
## Quickstart
|
||||
```bash
|
||||
sudo apt install make
|
||||
pip install --upgrade pip
|
||||
pip install -r requirements/dev.txt
|
||||
./manage.py migrate
|
||||
./manage.py loaddata data.json
|
||||
./manage.py runserver
|
||||
```
|
||||
|
||||
``pip install -r requirements.txt``
|
||||
## ZenDesk Access Controller instruction for eng
|
||||
|
||||
``./manage.py migrate``
|
||||
## Перед запуском для тестирования:
|
||||
|
||||
``./manage.py loaddata data.json``
|
||||
|
||||
``./manage.py runserver``
|
||||
|
||||
**********************************
|
||||
Перед запуском для тестирования:
|
||||
**********************************
|
||||
|
||||
* убедитесь, что вы зарегистрированы в песочнице ZenDesk, у вас назначена организация (SYSTEM)
|
||||
* для админов ZenDesk дополнительно - создайте токен доступа в ZenDesk
|
||||
* при запуске в Docker убедитесь что папка, которая будет служить хранилищем для БД, открыта на запись и чтение
|
||||
|
||||
*****************************
|
||||
Запуск на локальной машине:
|
||||
*****************************
|
||||
|
||||
* скопировать репозиторий на локальную машину
|
||||
* перейти в папку приложения
|
||||
* активировать виртуальное окружение
|
||||
* выполнить команду **pip install -r requirements.txt**
|
||||
* в виртуальное окружение добавить следующие переменные:
|
||||
Убедитесь, что вы зарегистрированы в песочнице ZenDesk, у вас назначена организация `SYSTEM`
|
||||
Для админов ZenDesk дополнительно - создайте токен доступа в ZenDesk
|
||||
При запуске в Docker убедитесь что папка, которая будет служить хранилищем для БД, открыта на запись и чтение
|
||||
|
||||
|
||||
| *ACCESS_CONTROLLER_API_EMAIL={EMAIL}* - почта админа в ZenDesk
|
||||
| *ACCESS_CONTROLLER_API_PASSWORD={PASSWORD}* - пароль админа ZenDesk
|
||||
| *ACCESS_CONTROLLER_API_TOKEN={API_TOKEN}* - API токен ZenDesk
|
||||
| *ZD_DOMAIN={DOMAIN}* - домен ZenDesk
|
||||
| *ENG_CROLE_ID={ENGINEER_CUSTOM_ROLE_ID}* - id роли инженера( custom_role_id сотрудника смены)
|
||||
| *LA_CROLE_ID={LIGHT_AGENT_CUSTOM_ROLE_ID}* - id роли легкого агента (custom_role_id роли -легкий агент)
|
||||
| *EMPL_GROUP={EMPLOYEE_GROUP_NAME}* - имя группы которой принадлежат сотрудники ССКС
|
||||
| *BUF_GROUP={BUFFER_GROUP_NAME}* - имя буферной группы для передачи смен(через нее происходит управление тикетами)
|
||||
| *ST_EMAIL={SOLVED_TICKETS_EMAIL}* - почта на которую будут переназначатся закрытые тикеты
|
||||
| *LICENSE_NO={LICENSE_NO}* - количество лицензий, отображаемых как доступные в приложении
|
||||
| *SHIFTH={SHIFT_HOURS}* - количество часов в рабочей смене (нужно для статистики, пока не реализовано но требует указания значения)
|
||||
## Запуск на локальной машине:
|
||||
- Скопировать репозиторий на локальную машину
|
||||
- Перейти в папку приложения
|
||||
- Активировать виртуальное окружение
|
||||
- Выполнить команду `pip install -r requirements/dev.txt`
|
||||
- В виртуальное окружение добавить следующие переменные:
|
||||
|
||||
|
||||
* выполнить команду **python manage.py makemigrations**
|
||||
* выполнить команду **python manage.py migrate**
|
||||
* запустить приложение командой **python manage.py runserver** (можно указать в параметрах для файла manage.py)
|
||||
* перейти по ссылке в консоли (вероятнее всего откроется по адресу http://127.0.0.1:8000/)
|
||||
```
|
||||
ACTRL_DEBUG={0/1} - включить режим дебага
|
||||
ACTRL_HOST={HOSTNAME} - при запуске без дебага, надо указать домен на котором будет работать приложение
|
||||
ACTRL_SECRET_KEY={DJANGO_SECRET_KEY} - секретный ключ сгенерированый Django
|
||||
|
||||
******************
|
||||
Запуск в Docker:
|
||||
******************
|
||||
ACTRL_EMAIL_HOST={SMTP_HOST} - домен почтового сервера через который приложение будет отправлять письма, например "smtp.gmail.com"
|
||||
ACTRL_EMAIL_PORT={SMTP_PORT} - порт для почтового сервера, например 587, 465 , 2525
|
||||
ACTRL_EMAIL_TLS={USE_TLS} - использовать TLS для подключения к почтовому серверу, 0 или 1
|
||||
ACTRL_EMAIL_HOST_USER={USERNAME} - логин с которым приложение входит на почтовый сервер
|
||||
ACTRL_EMAIL_HOST_PASSWORD={PASSWORD} - пароль/ключ с которым приложение входит на почтовый сервер
|
||||
ACTRL_FROM_EMAIL={EMAIL} - адрес с которого приложение отправляет письма
|
||||
ACTRL_SERVER_EMAIL={EMAIL} - адрес на который отвечают пользователя
|
||||
|
||||
ACTRL_API_EMAIL={EMAIL} - почта админа в ZenDesk
|
||||
ACTRL_API_PASSWORD={PASSWORD} - пароль админа ZenDesk
|
||||
ACTRL_API_TOKEN={API_TOKEN} - API токен зендеск
|
||||
ACTRL_ZENDESK_SUBDOMAIN={DOMAIN} - домен ZenDesk
|
||||
|
||||
ENG_CROLE_ID={ENGINEER_CUSTOM_ROLE_ID} - id роли инженера( custom_role_id сотрдника смены)
|
||||
LA_CROLE_ID={LIGHT_AGENT_CUSTOM_ROLE_ID} - id роли легкого агента (custom_role_id роли -легкий агент)
|
||||
EMPL_GROUP={EMPLOYEE_GROUP_NAME} - имя группы которой принадлежат сотрудники ССКС
|
||||
BUF_GROUP={BUFFER_GROUP_NAME} - имя буферной группы для передачи смен(через нее происходит управление тикетами)
|
||||
ST_EMAIL={SOLVED_TICKETS_EMAIL} - почта на которую будут переназначятся закрытые тикеты
|
||||
LICENSE_NO={LICENSE_NO} - количество лицензий, отображаемых как доступные в приложении
|
||||
SHIFTH={SHIFT_HOURS} - количество часов в рабочей смене (нужно для статистики, пока не реализовано но требует указания значения)
|
||||
```
|
||||
|
||||
- Выполнить команду `python manage.py migrate`
|
||||
- Запустить приложение командой `python manage.py runserver` (можно указать в параметрах для файла manage.py)
|
||||
- Перейти по ссылке в консоли (вероятнее всего откроется по адресу http://127.0.0.1:8000/)
|
||||
|
||||
|
||||
## Запуск в Docker:
|
||||
Требуется установленный и настроенный Docker
|
||||
|
||||
* скопировать репозиторий на локальную машину
|
||||
* в командной строке перейти в папку проекта
|
||||
* выполнить команду **docker build**.
|
||||
* выполнить команду **docker images** (нам нужен id созданного образа)
|
||||
* выполнить команду **docker run -d -p 8000:8000 -e ACCESS_CONTROLLER_API_EMAIL={EMAIL} -e ACCESS_CONTROLLER_API_PASSWORD={PASSWORD}**...(перечисляем все параметры виртуального окружения, разделяя их -e) -v {абсолютный путь к папке, в которой будет размещена база}:/zendesk-access-controller/db {id образа докера}
|
||||
* открыть запущенный контейнер в браузере (можно перейти по ссылке http://localhost:8000/)
|
||||
- Скопировать репозиторий на локальную машину
|
||||
- В командной строке перейти в папку проекта
|
||||
- Выполнить команду `docker build --tag access_controller:latest .`
|
||||
- Выполнить команду
|
||||
```bash
|
||||
docker run -d -p 8000:8000 \
|
||||
ACTRL_DEBUG={0/1} \
|
||||
ACTRL_HOST={HOSTNAME} \
|
||||
ACTRL_SECRET_KEY={DJANGO_SECRET_KEY} \
|
||||
ACTRL_EMAIL_HOST={SMTP_HOST} \
|
||||
ACTRL_EMAIL_PORT={SMTP_PORT} \
|
||||
ACTRL_EMAIL_TLS={USE_TLS} \
|
||||
ACTRL_EMAIL_HOST_USER={USERNAME} \
|
||||
ACTRL_EMAIL_HOST_PASSWORD={PASSWORD} \
|
||||
ACTRL_FROM_EMAIL={EMAIL} \
|
||||
ACTRL_SERVER_EMAIL={EMAIL} \
|
||||
ACTRL_API_EMAIL={EMAIL} \
|
||||
ACTRL_API_PASSWORD={PASSWORD} \
|
||||
ACTRL_API_TOKEN={API_TOKEN} \
|
||||
ACTRL_ZENDESK_SUBDOMAIN={DOMAIN} \
|
||||
ENG_CROLE_ID={ENGINEER_CUSTOM_ROLE_ID} \
|
||||
LA_CROLE_ID={LIGHT_AGENT_CUSTOM_ROLE_ID} \
|
||||
EMPL_GROUP={EMPLOYEE_GROUP_NAME} \
|
||||
BUF_GROUP={BUFFER_GROUP_NAME} \
|
||||
ST_EMAIL={SOLVED_TICKETS_EMAIL} \
|
||||
LICENSE_NO={LICENSE_NO} \
|
||||
SHIFTH={SHIFT_HOURS} \
|
||||
-v {ABSOLUTE_PATH_TO_DB}:/zendesk-access-controller/db \
|
||||
access_controller:latest
|
||||
```
|
||||
- открываем запущеный контейнер в браузере (можно перейти по ссылке http://localhost:8000/)
|
||||
|
||||
*****************************
|
||||
Запуск с тестовыми юзерами:
|
||||
*****************************
|
||||
|
||||
| На локальной машине - перед запуском команды **python manage.py runserver** выполнить команду **python manage.py loaddata data.json**.
|
||||
| Это создаст тестового админа и тестового пользователя в приложении для песочницы ZenDesk.
|
||||
| **Админ - admin@gmail.com / zendeskadmin** ,
|
||||
| **пользователь - 123@test.ru / zendeskuser** .
|
||||
| Не сработает если домен песочницы отличается от ngenix1612197338 (на другом домене нужно будет создать сначала пользователей в песочнице с правами админа и легкого агента
|
||||
| с этими же почтами, назначить им организацию (SYSTEM))
|
||||
## Запуск с тестовыми юзерами:
|
||||
На локальной машине - перед запуском команды `python manage.py runserver` выполнить команду `python manage.py loaddata data.json`
|
||||
Это создаст тестового админа и тестового пользователя в приложении для песочницы ZenDesk.
|
||||
|
||||
*******************************
|
||||
Параметры тестовой песочницы:
|
||||
*******************************
|
||||
- Админ - `admin@gmail.com` / `zendeskadmin`
|
||||
- Пользователь - `123@test.ru` / `zendeskuser`
|
||||
|
||||
| *ACCESS_CONTROLLER_API_EMAIL={EMAIL}* - почта админа в ZenDesk - взять у роководителя(если вы не админ)
|
||||
| *ACCESS_CONTROLLER_API_PASSWORD={PASSWORD}* - пароль админа ZenDesk - взять у роководителя(если вы не админ)
|
||||
| *ACCESS_CONTROLLER_API_TOKEN={API_TOKEN}* - API токен зендеск - взять у роководителя(если вы не админ)
|
||||
| *ZD_DOMAIN* =ngenix1612197338
|
||||
| *ENG_CROLE_ID* =360005209000
|
||||
| *LA_CROLE_ID* =360005208980
|
||||
| *EMPL_GROUP* =Поддержка
|
||||
| *BUF_GROUP* =Сменная группа
|
||||
| *ST_EMAIL* =d.krikov@ngenix.net
|
||||
| *LICENSE_NO* =3
|
||||
| *SHIFTH* =12
|
||||
Не сработает если домен песочницы отличается от `ngenix1612197338` (на другом домене нужно будет создать сначала пользователей в песочнице с правами админа и легкого агента
|
||||
с этими же почтами, назначить им организацию `SYSTEM`)
|
||||
|
||||
************
|
||||
Read more
|
||||
************
|
||||
|
||||
## Параметры тестовой песочницы:
|
||||
Пример полной конфигурации можно найти в [.env.example](.env.example). Почту и токен админа ZenDesk взять у руководителя (если вы не админ).
|
||||
|
||||
|
||||
## Read more
|
||||
- Zenpy: [http://docs.facetoe.com.au](http://docs.facetoe.com.au)
|
||||
- Zendesk API: [https://developer.zendesk.com/rest_api/docs/](https://developer.zendesk.com/rest_api/docs/)
|
||||
|
@ -19,12 +19,16 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'v1i_fb$_jf2#1v_lcsbu&eon4u-os0^px=s^iycegdycqy&5)6'
|
||||
SECRET_KEY = os.getenv('ACTRL_SECRET_KEY','empty')
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
DEBUG = bool(int(os.getenv('ACTRL_DEBUG',1)))
|
||||
|
||||
ALLOWED_HOSTS = ['127.0.0.1']
|
||||
ALLOWED_HOSTS = [
|
||||
'127.0.0.1',
|
||||
'localhost',
|
||||
os.getenv('ACTRL_HOST'),
|
||||
]
|
||||
|
||||
# Application definition
|
||||
|
||||
@ -53,13 +57,13 @@ MIDDLEWARE = [
|
||||
ROOT_URLCONF = 'access_controller.urls'
|
||||
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
EMAIL_HOST = 'smtp.mail.ru'
|
||||
EMAIL_PORT = 2525
|
||||
EMAIL_USE_TLS = True
|
||||
EMAIL_HOST_USER = 'djgr.02@mail.ru'
|
||||
EMAIL_HOST_PASSWORD = 'djangogroup02'
|
||||
SERVER_EMAIL = EMAIL_HOST_USER
|
||||
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
|
||||
EMAIL_HOST = os.getenv('ACTRL_EMAIL_HOST','smtp.gmail.com')
|
||||
EMAIL_PORT = int(os.getenv('ACTRL_EMAIL_PORT',587))
|
||||
EMAIL_USE_TLS = bool(int(os.getenv('ACTRL_EMAIL_TLS',1)))
|
||||
EMAIL_HOST_USER = os.getenv('ACTRL_EMAIL_HOST_USER','group02django@gmail.com')
|
||||
EMAIL_HOST_PASSWORD = os.getenv('ACTRL_EMAIL_HOST_PASSWORD','djangogroup02')
|
||||
DEFAULT_FROM_EMAIL = os.getenv('ACTRL_FROM_EMAIL',EMAIL_HOST_USER)
|
||||
SERVER_EMAIL = os.getenv('ACTRL_SERVER_EMAIL',EMAIL_HOST_USER)
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
@ -87,7 +91,7 @@ WSGI_APPLICATION = 'access_controller.wsgi.application'
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
'NAME': BASE_DIR / 'db' / 'zd_db.sqlite3'
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,55 +147,21 @@ AUTHENTICATION_BACKENDS = [
|
||||
|
||||
# Logging system
|
||||
# https://docs.djangoproject.com/en/3.1/topics/logging/
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'formatters': {
|
||||
'verbose': {
|
||||
'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
|
||||
'style': '{',
|
||||
},
|
||||
'simple': {
|
||||
'format': '{levelname} {message}',
|
||||
'style': '{',
|
||||
},
|
||||
},
|
||||
'handlers': {
|
||||
'console': {
|
||||
'level': 'INFO',
|
||||
'class': 'logging.StreamHandler',
|
||||
'formatter': 'simple'
|
||||
},
|
||||
'mail_admins': {
|
||||
'level': 'ERROR',
|
||||
'class': 'django.utils.log.AdminEmailHandler',
|
||||
}
|
||||
},
|
||||
'loggers': {
|
||||
'django': {
|
||||
'handlers': ['console'],
|
||||
'propagate': True,
|
||||
},
|
||||
'main.index': {
|
||||
'handlers': ['console'],
|
||||
'level': 'INFO',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ZENDESK_ROLES = {
|
||||
'engineer': 360005209000,
|
||||
'light_agent': 360005208980,
|
||||
'engineer': int(os.getenv('ENG_CROLE_ID',0)),
|
||||
'light_agent': int(os.getenv('LA_CROLE_ID',0)),
|
||||
}
|
||||
|
||||
ZENDESK_GROUPS = {
|
||||
'employees': 'Поддержка',
|
||||
'buffer': 'Сменная группа',
|
||||
'employees': os.getenv('EMPL_GROUP'),
|
||||
'buffer': os.getenv('BUF_GROUP'),
|
||||
}
|
||||
|
||||
SOLVED_TICKETS_EMAIL = 'd.krikov@ngenix.net'
|
||||
SOLVED_TICKETS_EMAIL = os.getenv('ST_EMAIL')
|
||||
|
||||
ZENDESK_MAX_AGENTS = 3
|
||||
ZENDESK_MAX_AGENTS = int(os.getenv('LICENSE_NO',0))
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
# Use Django's standard `django.contrib.auth` permissions,
|
||||
@ -201,4 +171,9 @@ REST_FRAMEWORK = {
|
||||
]
|
||||
}
|
||||
|
||||
ONE_DAY = 12 # Количество часов в 1 рабочем дне
|
||||
ONE_DAY = int(os.getenv('SHIFTH',0)) # Количество часов в 1 рабочем дне
|
||||
|
||||
ACTRL_ZENDESK_SUBDOMAIN = os.getenv('ACTRL_ZENDESK_SUBDOMAIN') or os.getenv('ZD_DOMAIN')
|
||||
ACTRL_API_EMAIL = os.getenv('ACTRL_API_EMAIL') or os.getenv('ACCESS_CONTROLLER_API_EMAIL')
|
||||
ACTRL_API_TOKEN = os.getenv('ACTRL_API_TOKEN') or os.getenv('ACCESS_CONTROLLER_API_TOKEN')
|
||||
ACTRL_API_PASSWORD = os.getenv('ACTRL_API_PASSWORD') or os.getenv('ACCESS_CONTROLLER_API_PASSWORD')
|
||||
|
@ -14,54 +14,30 @@ Including another URLconf
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth import views as auth_views
|
||||
from django.urls import path, include
|
||||
|
||||
from main.views import main_page, profile_page, CustomRegistrationView, CustomLoginView
|
||||
from main.views import work_page, work_hand_over, work_become_engineer, \
|
||||
from main.views import main_page, profile_page, CustomRegistrationView, CustomLoginView, registration_error
|
||||
from main.views import work_page, work_hand_over, work_become_engineer, work_get_tickets, \
|
||||
AdminPageView, statistic_page
|
||||
from main.urls import router
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls, name='admin'),
|
||||
path('', main_page, name='index'),
|
||||
path('accounts/profile/', profile_page, name='profile'),
|
||||
path('accounts/register/', CustomRegistrationView.as_view(), name='registration'),
|
||||
path('accounts/register/error/', registration_error, name='registration_email_error'),
|
||||
path('accounts/login/', CustomLoginView.as_view(), name='login'),
|
||||
path('accounts/', include('django.contrib.auth.urls')),
|
||||
path('accounts/', include('django_registration.backends.one_step.urls')),
|
||||
path('work/<int:id>', work_page, name="work"),
|
||||
path('work/hand_over/', work_hand_over, name="work_hand_over"),
|
||||
path('work/become_engineer/', work_become_engineer, name="work_become_engineer"),
|
||||
path('work/get_tickets', work_get_tickets, name='work_get_tickets'),
|
||||
path('accounts/', include('django_registration.backends.activation.urls')),
|
||||
path('accounts/login/', include('django.contrib.auth.urls')),
|
||||
path('control/', AdminPageView.as_view(), name='control'),
|
||||
path('statistic/', statistic_page, name='statistic')
|
||||
path('statistic/', statistic_page, name='statistic'),
|
||||
]
|
||||
|
||||
urlpatterns += [
|
||||
path(
|
||||
'password_reset/',
|
||||
auth_views.PasswordResetView.as_view(),
|
||||
name='password_reset'
|
||||
),
|
||||
path(
|
||||
'password-reset/done/',
|
||||
auth_views.PasswordResetDoneView.as_view(),
|
||||
name='password_reset_done'
|
||||
),
|
||||
path(
|
||||
'reset/<uidb64>/<token>/',
|
||||
auth_views.PasswordResetConfirmView.as_view(),
|
||||
name='password_reset_confirm'
|
||||
),
|
||||
path(
|
||||
'reset/done/',
|
||||
auth_views.PasswordResetCompleteView.as_view(),
|
||||
name='password_reset_complete'
|
||||
),
|
||||
]
|
||||
|
||||
# Django REST
|
||||
urlpatterns += [
|
||||
|
12
data.json
12
data.json
@ -1,7 +1,7 @@
|
||||
[
|
||||
{
|
||||
"model": "auth.user",
|
||||
"pk": 3,
|
||||
"pk": 1,
|
||||
"fields": {
|
||||
"password": "pbkdf2_sha256$216000$gHBBCr1jBELf$ZkEDW3IEd8Wij7u8vkv+0Eze32CS01bcaYWhcD9OIC4=",
|
||||
"last_login": null,
|
||||
@ -19,16 +19,16 @@
|
||||
},
|
||||
{
|
||||
"model": "main.userprofile",
|
||||
"pk": 3,
|
||||
"pk": 1,
|
||||
"fields": {
|
||||
"name": "ZendeskAdmin",
|
||||
"user": 3,
|
||||
"user": 1,
|
||||
"role": "admin"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "auth.user",
|
||||
"pk": 4,
|
||||
"pk": 2,
|
||||
"fields": {
|
||||
"password": "pbkdf2_sha256$216000$5qLJgrm2Quq9$KDBNNymVZXkUx0HKBPFst2m83kLe0egPBnkW7KnkORU=",
|
||||
"last_login": null,
|
||||
@ -46,10 +46,10 @@
|
||||
},
|
||||
{
|
||||
"model": "main.userprofile",
|
||||
"pk": 4,
|
||||
"pk": 2,
|
||||
"fields": {
|
||||
"name": "UserForAccessTest",
|
||||
"user": 4,
|
||||
"user": 2,
|
||||
"role": "agent",
|
||||
"custom_role_id": "360005209000"
|
||||
}
|
||||
|
0
db/.gitkeep
Normal file
0
db/.gitkeep
Normal file
@ -134,6 +134,7 @@ extensions = {
|
||||
'sphinx.ext.autodoc',
|
||||
'sphinx.ext.intersphinx',
|
||||
'sphinx.ext.viewcode',
|
||||
'sphinx.ext.napoleon',
|
||||
'sphinx_rtd_theme',
|
||||
'sphinx.ext.graphviz',
|
||||
'sphinx.ext.inheritance_diagram',
|
||||
@ -208,3 +209,5 @@ set_type_checking_flag = True
|
||||
typehints_fully_qualified = True
|
||||
always_document_param_types = True
|
||||
typehints_document_rtype = True
|
||||
|
||||
napoleon_attr_annotations = True
|
||||
|
0
logs/.gitkeep
Normal file
0
logs/.gitkeep
Normal file
@ -3,6 +3,8 @@ import os
|
||||
from zenpy import Zenpy
|
||||
from zenpy.lib.api_objects import User as ZenpyUser
|
||||
|
||||
from access_controller.settings import ACTRL_ZENDESK_SUBDOMAIN, ACTRL_API_EMAIL, ACTRL_API_TOKEN, ACTRL_API_PASSWORD
|
||||
|
||||
|
||||
def api_auth() -> dict:
|
||||
"""
|
||||
@ -15,15 +17,15 @@ def api_auth() -> dict:
|
||||
:return: данные пользователя
|
||||
"""
|
||||
credentials = {
|
||||
'subdomain': 'ngenix1612197338'
|
||||
'subdomain': ACTRL_ZENDESK_SUBDOMAIN
|
||||
}
|
||||
email = os.getenv('ACCESS_CONTROLLER_API_EMAIL')
|
||||
token = os.getenv('ACCESS_CONTROLLER_API_TOKEN')
|
||||
password = os.getenv('ACCESS_CONTROLLER_API_PASSWORD')
|
||||
email = ACTRL_API_EMAIL
|
||||
token = ACTRL_API_TOKEN
|
||||
password = ACTRL_API_PASSWORD
|
||||
|
||||
if email is None:
|
||||
raise ValueError('access_controller email not in env')
|
||||
credentials['email'] = os.getenv('ACCESS_CONTROLLER_API_EMAIL')
|
||||
credentials['email'] = email
|
||||
|
||||
# prefer token, use password if token not provided
|
||||
if token:
|
||||
|
@ -1,150 +1,21 @@
|
||||
import os
|
||||
import logging
|
||||
from datetime import timedelta, datetime, date
|
||||
from typing import Optional
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.shortcuts import redirect
|
||||
from django.utils import timezone
|
||||
from zenpy import Zenpy
|
||||
from zenpy.lib.exception import APIException
|
||||
from zenpy.lib.api_objects import User as ZenpyUser, Ticket as ZenpyTicket
|
||||
|
||||
from access_controller.settings import ZENDESK_ROLES as ROLES, ONE_DAY, ZENDESK_GROUPS, SOLVED_TICKETS_EMAIL
|
||||
from access_controller.settings import ZENDESK_ROLES as ROLES, ONE_DAY, ACTRL_ZENDESK_SUBDOMAIN
|
||||
from main.models import UserProfile, RoleChangeLogs, UnassignedTicket, UnassignedTicketStatus
|
||||
from main.zendesk_admin import zenpy
|
||||
|
||||
|
||||
class ZendeskAdmin:
|
||||
"""
|
||||
Класс **ZendeskAdmin** существует, чтобы в каждой функции отдельно не проверять аккаунт администратора.
|
||||
|
||||
:param credentials: Полномочия (первым указывается учетная запись организации в Zendesk)
|
||||
:type credentials: :class:`dict`
|
||||
:param email: Email администратора, указанный в env
|
||||
:type email: :class:`str`
|
||||
:param token: Токен администратора (формируется в Zendesk, указывается в env)
|
||||
:type token: :class:`str`
|
||||
:param password: Пароль администратора, указанный в env
|
||||
:type password: :class:`str`
|
||||
|
||||
"""
|
||||
|
||||
credentials: dict = {
|
||||
'subdomain': 'ngenix1612197338'
|
||||
}
|
||||
email: str = os.getenv('ACCESS_CONTROLLER_API_EMAIL')
|
||||
token: str = os.getenv('ACCESS_CONTROLLER_API_TOKEN')
|
||||
password: str = os.getenv('ACCESS_CONTROLLER_API_PASSWORD')
|
||||
|
||||
def __init__(self):
|
||||
self.create_admin()
|
||||
|
||||
def check_user(self, email: str) -> bool:
|
||||
"""
|
||||
Функция осуществляет проверку существования пользователя в Zendesk по email.
|
||||
|
||||
:param email: Email пользователя
|
||||
:return: Является ли зарегистрированным
|
||||
"""
|
||||
return True if self.admin.search(email, type='user') else False
|
||||
|
||||
def get_user_name(self, email: str) -> str:
|
||||
"""
|
||||
Функция **get_user_name** возвращает имя пользователя по его email.
|
||||
|
||||
:param email: Email пользователя
|
||||
:return: Имя пользователя
|
||||
"""
|
||||
user = self.admin.users.search(email).values[0]
|
||||
return user.name
|
||||
|
||||
def get_user_role(self, email: str) -> str:
|
||||
"""
|
||||
Функция возвращает роль пользователя по его email.
|
||||
|
||||
:param email: Email пользователя
|
||||
:return: Роль пользователя
|
||||
"""
|
||||
user = self.admin.users.search(email).values[0]
|
||||
return user.role
|
||||
|
||||
def get_user_id(self, email: str) -> str:
|
||||
"""
|
||||
Функция возвращает id пользователя по его email
|
||||
|
||||
:param email: Email пользователя
|
||||
:return: ID пользователя
|
||||
"""
|
||||
user = self.admin.users.search(email).values[0]
|
||||
return user.id
|
||||
|
||||
def get_user_image(self, email: str) -> Optional[str]:
|
||||
"""
|
||||
Функция возвращает url-ссылку на аватар пользователя по его email.
|
||||
|
||||
:param email: Email пользователя
|
||||
:return: Аватар пользователя
|
||||
"""
|
||||
user = self.admin.users.search(email).values[0]
|
||||
return user.photo['content_url'] if user.photo else None
|
||||
|
||||
def get_user(self, email: str):
|
||||
"""
|
||||
Функция возвращает пользователя (объект) по его email.
|
||||
|
||||
:param email: Email пользователя
|
||||
:return: Объект пользователя, найденного в БД
|
||||
"""
|
||||
return self.admin.users.search(email).values[0]
|
||||
|
||||
def get_group(self, name: str) -> Optional[str]:
|
||||
"""
|
||||
Функция возвращает группу, к которой принадлежит пользователь.
|
||||
|
||||
:param name: Имя пользователя
|
||||
:return: Группы пользователя (в случае отсутствия None)
|
||||
"""
|
||||
groups = self.admin.search(name)
|
||||
for group in groups:
|
||||
return group
|
||||
return None
|
||||
|
||||
def get_user_org(self, email: str) -> Optional[str]:
|
||||
"""
|
||||
Функция возвращает организацию, к которой относится пользователь по его email.
|
||||
|
||||
:param email: Email пользователя
|
||||
:return: Организация пользователя
|
||||
"""
|
||||
user = self.admin.users.search(email).values[0]
|
||||
return user.organization.name if user.organization else None
|
||||
|
||||
def create_admin(self) -> Zenpy:
|
||||
"""
|
||||
Функция создает администратора, проверяя наличие вводимых данных в env.
|
||||
|
||||
:param credentials: В список полномочий администратора вносятся email, token, password из env
|
||||
:type credentials: :class:`dict`
|
||||
:raise: :class:`ValueError`: исключение, вызываемое если email не введен в env
|
||||
:raise: :class:`APIException`: исключение, вызываемое если пользователя с таким email не существует в Zendesk
|
||||
"""
|
||||
|
||||
if self.email is None:
|
||||
raise ValueError('access_controller email not in env')
|
||||
self.credentials['email'] = self.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_role(user_profile: UserProfile, role: str) -> UserProfile:
|
||||
def update_role(user_profile: UserProfile, role: int) -> None:
|
||||
"""
|
||||
Функция меняет роль пользователя.
|
||||
|
||||
@ -152,7 +23,7 @@ def update_role(user_profile: UserProfile, role: str) -> UserProfile:
|
||||
:param role: Новая роль
|
||||
:return: Пользователь с обновленной ролью
|
||||
"""
|
||||
zendesk = ZendeskAdmin()
|
||||
zendesk = zenpy
|
||||
user = zendesk.get_user(user_profile.user.email)
|
||||
user.custom_role_id = role
|
||||
user_profile.custom_role_id = role
|
||||
@ -160,23 +31,17 @@ def update_role(user_profile: UserProfile, role: str) -> UserProfile:
|
||||
zendesk.admin.users.update(user)
|
||||
|
||||
|
||||
def make_engineer(user_profile: UserProfile, who_changes: User) -> UserProfile:
|
||||
def make_engineer(user_profile: UserProfile, who_changes: User) -> None:
|
||||
"""
|
||||
Функция устанавливает пользователю роль инженера.
|
||||
|
||||
:param user_profile: Профиль пользователя
|
||||
:return: Вызов функции **update_role** с параметрами: профиль пользователя, роль "engineer"
|
||||
"""
|
||||
RoleChangeLogs.objects.create(
|
||||
user=user_profile.user,
|
||||
old_role=user_profile.custom_role_id,
|
||||
new_role=ROLES['engineer'],
|
||||
changed_by=who_changes
|
||||
)
|
||||
update_role(user_profile, ROLES['engineer'])
|
||||
|
||||
|
||||
def make_light_agent(user_profile: UserProfile, who_changes: User) -> UserProfile:
|
||||
def make_light_agent(user_profile: UserProfile, who_changes: User) -> None:
|
||||
"""
|
||||
Функция устанавливает пользователю роль легкого агента.
|
||||
|
||||
@ -184,6 +49,7 @@ def make_light_agent(user_profile: UserProfile, who_changes: User) -> UserProfil
|
||||
:return: Вызов функции **update_role** с параметрами: профиль пользователя, роль "light_agent"
|
||||
"""
|
||||
tickets = get_tickets_list(user_profile.user.email)
|
||||
ticket: ZenpyTicket
|
||||
for ticket in tickets:
|
||||
UnassignedTicket.objects.create(
|
||||
assignee=user_profile.user,
|
||||
@ -191,26 +57,29 @@ def make_light_agent(user_profile: UserProfile, who_changes: User) -> UserProfil
|
||||
status=UnassignedTicketStatus.SOLVED if ticket.status == 'solved' else UnassignedTicketStatus.UNASSIGNED
|
||||
)
|
||||
if ticket.status == 'solved':
|
||||
ticket.assignee = ZendeskAdmin().get_user(SOLVED_TICKETS_EMAIL)
|
||||
ticket.assignee_id = zenpy.solved_tickets_user_id
|
||||
else:
|
||||
ticket.assignee = None
|
||||
ticket.group = ZendeskAdmin().get_group(ZENDESK_GROUPS['buffer'])
|
||||
ZendeskAdmin().admin.tickets.update(ticket)
|
||||
ticket.group_id = zenpy.buffer_group_id
|
||||
|
||||
RoleChangeLogs.objects.create(
|
||||
user=user_profile.user,
|
||||
old_role=user_profile.custom_role_id,
|
||||
new_role=ROLES['light_agent'],
|
||||
changed_by=who_changes
|
||||
)
|
||||
update_role(user_profile, ROLES['light_agent'])
|
||||
zenpy.admin.tickets.update(tickets.values)
|
||||
|
||||
attempts, success = 5, False
|
||||
while not success and attempts != 0:
|
||||
try:
|
||||
update_role(user_profile, ROLES['light_agent'])
|
||||
success = True
|
||||
except APIException as e:
|
||||
attempts -= 1
|
||||
if attempts == 0:
|
||||
raise e
|
||||
|
||||
|
||||
def get_users_list() -> list:
|
||||
"""
|
||||
Функция **get_users_list** возвращает список пользователей Zendesk, относящихся к организации SYSTEM.
|
||||
Функция **get_users_list** возвращает список пользователей Zendesk, относящихся к организации SYSTEM.
|
||||
"""
|
||||
zendesk = ZendeskAdmin()
|
||||
zendesk = zenpy
|
||||
|
||||
# У пользователей должна быть организация SYSTEM
|
||||
org = next(zendesk.admin.search(type='organization', name='SYSTEM'))
|
||||
@ -218,24 +87,21 @@ def get_users_list() -> list:
|
||||
return users
|
||||
|
||||
|
||||
def get_tickets_list(email: str) -> list:
|
||||
def get_tickets_list(email):
|
||||
"""
|
||||
Функция возвращает список тикетов пользователя Zendesk.
|
||||
|
||||
:param email: Email пользователя
|
||||
:return: Список тикетов пользователя
|
||||
Функция возвращает список тикетов пользователя Zendesk
|
||||
"""
|
||||
return ZendeskAdmin().admin.search(assignee=email, type='ticket')
|
||||
return zenpy.admin.search(assignee=email, type='ticket')
|
||||
|
||||
|
||||
def update_profile(user_profile: UserProfile) -> UserProfile:
|
||||
def update_profile(user_profile: UserProfile):
|
||||
"""
|
||||
Функция обновляет профиль пользователя в соответствии с текущим в Zendesk.
|
||||
|
||||
:param user_profile: Профиль пользователя
|
||||
:return: Обновленный, в соответствие с текущими данными в Zendesk, профиль пользователя
|
||||
"""
|
||||
user = ZendeskAdmin().get_user(user_profile.user.email)
|
||||
user = zenpy.get_user(user_profile.user.email)
|
||||
user_profile.name = user.name
|
||||
user_profile.role = user.role
|
||||
user_profile.custom_role_id = user.custom_role_id if user.custom_role_id else 0
|
||||
@ -250,7 +116,7 @@ def check_user_exist(email: str) -> bool:
|
||||
:param email: Email пользователя
|
||||
:return: Зарегистрирован ли пользователь в Zendesk
|
||||
"""
|
||||
return ZendeskAdmin().check_user(email)
|
||||
return zenpy.check_user(email)
|
||||
|
||||
|
||||
def get_user_organization(email: str) -> str:
|
||||
@ -260,21 +126,19 @@ def get_user_organization(email: str) -> str:
|
||||
:param email: Email пользователя
|
||||
:return: Организация пользователя
|
||||
"""
|
||||
return ZendeskAdmin().get_user_org(email)
|
||||
return zenpy.get_user_org(email)
|
||||
|
||||
|
||||
def check_user_auth(email: str, password: str) -> bool:
|
||||
"""
|
||||
Функция проверяет, верны ли входные данные.
|
||||
|
||||
:param email: Email пользователя
|
||||
:param password: Пароль пользователя
|
||||
:raise: :class:`APIException`: исключение, вызываемое если пользователь не аутентифицирован
|
||||
"""
|
||||
creds = {
|
||||
'email': email,
|
||||
'password': password,
|
||||
'subdomain': 'ngenix1612197338',
|
||||
'subdomain': ACTRL_ZENDESK_SUBDOMAIN,
|
||||
}
|
||||
try:
|
||||
user = Zenpy(**creds)
|
||||
@ -284,7 +148,7 @@ def check_user_auth(email: str, password: str) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def update_user_in_model(profile: UserProfile, zendesk_user: User) -> UserProfile:
|
||||
def update_user_in_model(profile: UserProfile, zendesk_user: ZenpyUser):
|
||||
"""
|
||||
Функция обновляет профиль пользователя при изменении данных пользователя на Zendesk.
|
||||
|
||||
@ -302,7 +166,7 @@ def update_user_in_model(profile: UserProfile, zendesk_user: User) -> UserProfil
|
||||
|
||||
def count_users(users) -> tuple:
|
||||
"""
|
||||
Функция подсчета количества сотрудников с ролями engineer и light_agent
|
||||
Функция подсчета количества сотрудников с ролями engineer и light_agent
|
||||
"""
|
||||
engineers, light_agents = 0, 0
|
||||
for user in users:
|
||||
@ -313,9 +177,9 @@ def count_users(users) -> tuple:
|
||||
return engineers, light_agents
|
||||
|
||||
|
||||
def update_users_in_model() -> list:
|
||||
def update_users_in_model():
|
||||
"""
|
||||
Функция обновляет пользователей в модели UserProfile по списку пользователей в организации
|
||||
Обновляет пользователей в модели UserProfile по списку пользователей в организации
|
||||
"""
|
||||
users = get_users_list()
|
||||
for user in users:
|
||||
@ -327,7 +191,7 @@ def update_users_in_model() -> list:
|
||||
return users
|
||||
|
||||
|
||||
def daterange(start_date: date, end_date: date) -> list:
|
||||
def daterange(start_date, end_date) -> list:
|
||||
"""
|
||||
Функция возвращает список дней с start_date по end_date, исключая правую границу.
|
||||
|
||||
@ -341,7 +205,7 @@ def daterange(start_date: date, end_date: date) -> list:
|
||||
return dates
|
||||
|
||||
|
||||
def get_timedelta(log: RoleChangeLogs, time: datetime =None) -> timedelta:
|
||||
def get_timedelta(log, time=None) -> timedelta:
|
||||
"""
|
||||
Функция возвращает объект класса timedelta, который хранит промежуток времени от начала суток до момента,
|
||||
который находится в log (объект класса RoleChangeLogs) или в time(datetime.time), если введён.
|
||||
@ -408,7 +272,7 @@ class StatisticData:
|
||||
else:
|
||||
self.statistic = stat
|
||||
|
||||
def get_statistic(self) -> Optional[dict]:
|
||||
def get_statistic(self) -> dict:
|
||||
"""
|
||||
Функция возвращает статистику работы пользователя.
|
||||
|
||||
@ -456,7 +320,7 @@ class StatisticData:
|
||||
self.display = display_format
|
||||
return True
|
||||
|
||||
def get_data(self) -> Optional[list]:
|
||||
def get_data(self) -> Optional[dict]:
|
||||
"""
|
||||
Функция возвращает данные - список объектов RoleChangeLogs.
|
||||
"""
|
||||
@ -524,7 +388,7 @@ class StatisticData:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _init_data(self) -> Optional[list]:
|
||||
def _init_data(self):
|
||||
"""
|
||||
Функция возвращает логи в диапазоне дат start_date - end_date для пользователя с указанным email.
|
||||
|
||||
@ -541,7 +405,7 @@ class StatisticData:
|
||||
except User.DoesNotExist:
|
||||
self.errors += ['Пользователь не найден']
|
||||
|
||||
def _init_statistic(self) -> Optional[dict]:
|
||||
def _init_statistic(self) -> dict:
|
||||
"""
|
||||
Функция заполняет словарь, в котором ключ - дата, значение - кол-во проработанных в этот день секунд.
|
||||
|
||||
@ -563,7 +427,7 @@ class StatisticData:
|
||||
if self.data[log_index].new_role == ROLES['engineer']:
|
||||
self.engineer_logic(log_index)
|
||||
|
||||
def engineer_logic(self, log_index: int) -> dict:
|
||||
def engineer_logic(self, log_index):
|
||||
"""
|
||||
Функция обрабатывает основную часть работы инженера
|
||||
"""
|
||||
@ -577,9 +441,9 @@ class StatisticData:
|
||||
elapsed_time = next_log.change_time - current_log.change_time
|
||||
self.statistic[current_log.change_time.date()] += elapsed_time.total_seconds()
|
||||
|
||||
def post_engineer_logic(self, last_log: RoleChangeLogs):
|
||||
def post_engineer_logic(self, last_log):
|
||||
"""
|
||||
Функция обрабатывает случай, когда нам известно что инженер работал и после диапазона
|
||||
Функция обрабатывает случай, когда нам изветсно что инженер работал и после диапазона
|
||||
"""
|
||||
self.fill_daterange(last_log.change_time.date() + timedelta(days=1), self.end_date + timedelta(days=1))
|
||||
if last_log.change_time.date() == timezone.now().date():
|
||||
@ -592,9 +456,9 @@ class StatisticData:
|
||||
if self.end_date == timezone.now().date():
|
||||
self.statistic[self.end_date] = get_timedelta(None, timezone.now().time()).total_seconds()
|
||||
|
||||
def prev_engineer_logic(self, first_log: RoleChangeLogs) ->dict:
|
||||
def prev_engineer_logic(self, first_log):
|
||||
"""
|
||||
Функция обрабатывает случай, когда нам известно что инженер начал работу до диапазона
|
||||
Функция обрабатывает случай, когда нам изветсно что инженер начал работу до диапазона
|
||||
"""
|
||||
self.fill_daterange(max(User.objects.get(email=self.email).date_joined.date(), self.start_date),
|
||||
first_log.change_time.date())
|
||||
@ -617,3 +481,82 @@ class StatisticData:
|
||||
"""
|
||||
self.statistic.clear()
|
||||
self.fill_daterange(self.start_date, self.end_date + timedelta(days=1), 0)
|
||||
|
||||
|
||||
class DatabaseHandler(logging.Handler):
|
||||
def __init__(self):
|
||||
logging.Handler.__init__(self)
|
||||
|
||||
def emit(self, record):
|
||||
database = RoleChangeLogs()
|
||||
users = record.msg
|
||||
if users[1]:
|
||||
user = users[0]
|
||||
admin = users[1]
|
||||
elif not users[1]:
|
||||
user = users[0]
|
||||
admin = users[0]
|
||||
database.name = user.name
|
||||
database.user = user.user
|
||||
database.changed_by = admin.user
|
||||
if user.custom_role_id == ROLES['engineer']:
|
||||
database.old_role = ROLES['light_agent']
|
||||
elif user.custom_role_id == ROLES['light_agent']:
|
||||
database.old_role = ROLES['engineer']
|
||||
database.new_role = user.custom_role_id
|
||||
database.save()
|
||||
|
||||
|
||||
class CsvFormatter(logging.Formatter):
|
||||
def __init__(self):
|
||||
logging.Formatter.__init__(self)
|
||||
|
||||
def format(self, record):
|
||||
users = record.msg
|
||||
if users[1]:
|
||||
user = users[0]
|
||||
admin = users[1]
|
||||
elif not users[1]:
|
||||
user = users[0]
|
||||
admin = users[0]
|
||||
msg = ''
|
||||
msg += user.name
|
||||
if user.custom_role_id == ROLES['engineer']:
|
||||
msg += ',engineer,'
|
||||
elif user.custom_role_id == ROLES['light_agent']:
|
||||
msg += ',light_agent,'
|
||||
time = str(timezone.now().today())
|
||||
msg += time[:16]
|
||||
msg += ','
|
||||
msg += admin.name
|
||||
return msg
|
||||
|
||||
|
||||
def log(user, admin=0):
|
||||
"""
|
||||
Осуществляет запись логов в базу данных и csv файл
|
||||
:param admin:
|
||||
:param user:
|
||||
:return:
|
||||
"""
|
||||
users = [user, admin]
|
||||
logger = logging.getLogger('MY_LOGGER')
|
||||
if not logger.hasHandlers():
|
||||
dbhandler = DatabaseHandler()
|
||||
csvformatter = CsvFormatter()
|
||||
csvhandler = logging.FileHandler('logs/logs.csv', "a")
|
||||
csvhandler.setFormatter(csvformatter)
|
||||
logger.addHandler(dbhandler)
|
||||
logger.addHandler(csvhandler)
|
||||
logger.setLevel('INFO')
|
||||
logger.info(users)
|
||||
|
||||
|
||||
def set_session_params_for_work_page(request, count=None, is_confirm=True):
|
||||
"""
|
||||
Функция для страницы получения прав
|
||||
Устанавливает данные сессии о успешности запроса и количестве назначенных тикетов
|
||||
"""
|
||||
request.session['is_confirm'] = is_confirm
|
||||
request.session['count_tickets'] = count
|
||||
return redirect('work', request.user.id)
|
||||
|
@ -12,10 +12,9 @@ class CustomRegistrationForm(RegistrationFormUniqueEmail):
|
||||
|
||||
:param visible_fields.email: Поле для ввода email, зарегистрированного на Zendesk
|
||||
:type visible_fields.email: :class:`django_registration.forms.RegistrationFormUniqueEmail`
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs) -> RegistrationFormUniqueEmail:
|
||||
def __init__(self, *args, **kwargs) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
for visible in self.visible_fields():
|
||||
if visible.field.widget.attrs.get('class', False):
|
||||
@ -96,13 +95,12 @@ class StatisticForm(forms.Form):
|
||||
:param range_end: Дата и время окончания работы
|
||||
:type range_end: :class:`django.forms.fields.DateField`
|
||||
"""
|
||||
email: str = forms.EmailField(
|
||||
label='Электроная почта',
|
||||
email = forms.EmailField(
|
||||
label='Электронная почта',
|
||||
widget=forms.EmailInput(
|
||||
attrs={
|
||||
'placeholder': 'example@ngenix.ru',
|
||||
'class': 'form-control',
|
||||
'style': 'background-color:#f2f2f2;'
|
||||
}
|
||||
),
|
||||
)
|
||||
|
26
main/migrations/0017_auto_20210408_1943.py
Normal file
26
main/migrations/0017_auto_20210408_1943.py
Normal file
@ -0,0 +1,26 @@
|
||||
# Generated by Django 3.1.7 on 2021-04-08 16:43
|
||||
|
||||
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', '0016_merge_20210330_0043'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='unassignedticket',
|
||||
name='assignee',
|
||||
field=models.ForeignKey(help_text='Пользователь, с которого снят тикет', on_delete=django.db.models.deletion.CASCADE, related_name='tickets', to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='unassignedticket',
|
||||
name='status',
|
||||
field=models.IntegerField(choices=[(0, 'Снят с пользователя, перенесён в буферную группу'), (1, 'Авторство восстановлено'), (2, 'Пока нас не было, тикет испарился из буферной группы. Дополнительные действия не требуются'), (3, 'Тикет уже был закрыт. Дополнительные действия не требуются'), (4, 'Тикет решён. Записан на пользователя с почтой SOLVED_TICKETS_EMAIL')], default=0, help_text='Статус тикета'),
|
||||
),
|
||||
]
|
@ -80,3 +80,4 @@ class UnassignedTicket(models.Model):
|
||||
assignee = models.ForeignKey(to=User, on_delete=models.CASCADE, related_name='tickets', help_text='Пользователь, с которого снят тикет')
|
||||
ticket_id = models.IntegerField(help_text='Номер тикера, для которого сняли ответственного')
|
||||
status = models.IntegerField(choices=UnassignedTicketStatus.choices, default=UnassignedTicketStatus.UNASSIGNED, help_text='Статус тикета')
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
from django.contrib.auth.models import User
|
||||
from rest_framework import serializers
|
||||
from main.models import UserProfile
|
||||
from access_controller.settings import ZENDESK_ROLES
|
||||
|
||||
|
||||
class UserSerializer(serializers.HyperlinkedModelSerializer):
|
||||
@ -13,9 +14,25 @@ class UserSerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
|
||||
class ProfileSerializer(serializers.HyperlinkedModelSerializer):
|
||||
"""Сериализатор для модели профиля пользователя"""
|
||||
"""Класс serializer для модели профиля пользователя"""
|
||||
user = UserSerializer()
|
||||
|
||||
class Meta:
|
||||
model = UserProfile
|
||||
fields = ['user', 'id', 'name', 'zendesk_role']
|
||||
|
||||
|
||||
class ZendeskUserSerializer(serializers.Serializer):
|
||||
"""Класс serializer для объектов пользователей из zenpy"""
|
||||
name = serializers.CharField()
|
||||
zendesk_role = serializers.SerializerMethodField('get_zendesk_role')
|
||||
email = serializers.EmailField()
|
||||
|
||||
@staticmethod
|
||||
def get_zendesk_role(obj):
|
||||
if obj.custom_role_id == ZENDESK_ROLES['engineer']:
|
||||
return 'engineer'
|
||||
elif obj.custom_role_id == ZENDESK_ROLES['light_agent']:
|
||||
return 'light_agent'
|
||||
else:
|
||||
return "empty"
|
||||
|
@ -5,23 +5,54 @@
|
||||
|
||||
<nav class="navbar navbar-light" style="background-color: #113A60;">
|
||||
<a class="navbar-brand" href="{% url 'index' %}">
|
||||
<img src="{% static 'main/img/logo_real.png' %}" width="107" height="22" class="d-inline-block align-top" alt="" loading="lazy">
|
||||
<img src="{% static 'main/img/logo_real.png' %}" width="107" height="22" class="d-inline-block align-top" style="margin-left: 15px" alt="" loading="lazy">
|
||||
<t style="color:#FFFFFF">Access Controller</t>
|
||||
</a>
|
||||
{% if request.user.is_authenticated %}
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-secondary" href="{% url 'profile' %}">Профиль</a>
|
||||
<div class="btn-group" role="group" aria-label="Basic example" style="margin-right: 9px">
|
||||
<a {% if profile_lit %}
|
||||
class="btn btn-primary"
|
||||
{% else %}
|
||||
class="btn btn-secondary"
|
||||
{% endif %}
|
||||
href="{% url 'profile' %}">Профиль</a>
|
||||
{% if perms.main.has_control_access %}
|
||||
<a class="btn btn-secondary" href="{% url 'control' %}">Управление</a>
|
||||
<a {% if control_lit %}
|
||||
class="btn btn-primary"
|
||||
{% else %}
|
||||
class="btn btn-secondary"
|
||||
{% endif %}
|
||||
href="{% url 'control' %}">Управление</a>
|
||||
<a {% if stats_lit %}
|
||||
class="btn btn-primary"
|
||||
{% else %}
|
||||
class="btn btn-secondary"
|
||||
{% endif %}
|
||||
href="{% url 'statistic' %}">Статистика</a>
|
||||
{% else %}
|
||||
<a class="btn btn-secondary" href="{% url 'work' request.user.id %}">Запрос прав</a>
|
||||
<a {% if work_lit %}
|
||||
class="btn btn-primary"
|
||||
{% else %}
|
||||
class="btn btn-secondary"
|
||||
{% endif %}
|
||||
href="{% url 'work' request.user.id %}">Запрос прав</a>
|
||||
{% endif %}
|
||||
<a class="btn btn-secondary" href="{% url 'logout' %}">Выйти</a>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-secondary" href="/accounts/login">Войти</a>
|
||||
<a class="btn btn-secondary" href="/accounts/register">Зарегистрироваться</a>
|
||||
<div class="btn-group" role="group" aria-label="Basic example" style="margin-right: 9px">
|
||||
<a {% if login_lit %}
|
||||
class="btn btn-primary"
|
||||
{% else %}
|
||||
class="btn btn-secondary"
|
||||
{% endif %}
|
||||
href="/accounts/login">Войти</a>
|
||||
<a {% if registration_lit %}
|
||||
class="btn btn-primary"
|
||||
{% else %}
|
||||
class="btn btn-secondary"
|
||||
{% endif %}
|
||||
href="/accounts/register">Зарегистрироваться</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</nav>
|
||||
|
@ -1,14 +0,0 @@
|
||||
<div class="mt-5">
|
||||
{% for message in messages %}
|
||||
<div
|
||||
class="alert alert-{{ message.tags }} alert-dismissible fade show p-2"
|
||||
role="alert"
|
||||
style="display: flex; align-items: center; justify-content: space-between;"
|
||||
>
|
||||
{{ message }}
|
||||
<div>
|
||||
<button type="button" class="btn btn-light p-2" data-bs-dismiss="alert" aria-label="Close">X</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
15
main/templates/django_registration/registration_error.html
Normal file
15
main/templates/django_registration/registration_error.html
Normal file
@ -0,0 +1,15 @@
|
||||
{% extends 'base/base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}
|
||||
Регистрация завершена
|
||||
{% endblock %}
|
||||
|
||||
{% block heading %}
|
||||
Регистрация
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<br>
|
||||
<h4> Произошла ошибка при отправке электронного сообщения.</h4>
|
||||
{% endblock %}
|
@ -7,7 +7,8 @@
|
||||
{% block heading %}Управление{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
<link rel="stylesheet" href="{% static 'main/css/work.css' %}"/>
|
||||
<link rel="stylesheet" href="{% static 'main/css/work.css' %}" xmlns="http://www.w3.org/1999/html">
|
||||
<link rel="stylesheet" href="{% static 'modules/notifications/dist/notifications.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_scripts %}
|
||||
@ -15,15 +16,22 @@
|
||||
<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js" crossorigin></script>
|
||||
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
||||
{% endblock%}
|
||||
|
||||
<script src="{% static 'modules/notifications/dist/notifications.js' %}"></script>
|
||||
<script src="{% static 'main/js/control.js'%}" type="text/babel"></script>
|
||||
<script src="{% static 'main/js/notifications.js' %}"></script>
|
||||
{% endblock%}
|
||||
{% block content %}
|
||||
<div class="container-md">
|
||||
|
||||
<div class="new-section">
|
||||
<p class="row page-description">Свободных Мест: {{ licences_remaining }}</p>
|
||||
<p class="row page-description" id="licences_remaining">Свободных Мест:</p>
|
||||
</div>
|
||||
|
||||
{% for message in messages %}
|
||||
<script>create_notification('{{message}}','','{{message.tags}}',5000)</script>
|
||||
{% endfor %}
|
||||
|
||||
{% block form %}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
@ -34,16 +42,22 @@
|
||||
<h6 class="table-title">Список сотрудников</h6>
|
||||
|
||||
{% block table %}
|
||||
<table class="light-table">
|
||||
<table class="table table-dark light-table">
|
||||
|
||||
<thead>
|
||||
<th>
|
||||
<input
|
||||
type="checkbox"
|
||||
class="form-check-input"
|
||||
id="head-checkbox"
|
||||
/>
|
||||
</th>
|
||||
<th>Name</th>
|
||||
<th>Email</th>
|
||||
<th>Role</th>
|
||||
<th>Checked</th>
|
||||
</thead>
|
||||
<tbody id="tbody">
|
||||
</tbody>
|
||||
<tbody id="tbody"></tbody>
|
||||
|
||||
</table>
|
||||
<p id="loading">Данные загружаются...</p>
|
||||
{% endblock %}
|
||||
@ -93,9 +107,6 @@
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
{% include 'base/success_messages.html' %}
|
||||
</div>
|
||||
|
||||
<script src="{% static 'main/js/control.js'%}" type="text/babel"></script>
|
||||
|
||||
{% endblock %}
|
||||
|
@ -26,7 +26,7 @@
|
||||
<div class="col-auto">
|
||||
{% for radio in form.interval%}
|
||||
{{ radio.tag }}
|
||||
<label class="btn btn-secondary text-primary bg-white" for="{{ radio.id_for_label }}">
|
||||
<label class="btn btn-outline-secondary" for="{{ radio.id_for_label }}">
|
||||
{{ radio.choice_label }}
|
||||
</label>
|
||||
{% endfor %}
|
||||
@ -39,7 +39,7 @@
|
||||
<div class="col-auto">
|
||||
{% for radio in form.display_format%}
|
||||
{{ radio.tag }}
|
||||
<label class="btn btn-secondary text-primary bg-white" for="{{ radio.id_for_label }}">
|
||||
<label class="btn btn-outline-secondary" for="{{ radio.id_for_label }}">
|
||||
{{ radio.choice_label }}
|
||||
</label>
|
||||
{% endfor %}
|
||||
@ -67,7 +67,7 @@
|
||||
</div>
|
||||
<div class="form-row text-center">
|
||||
<div class="col-12">
|
||||
<button type="submit" class="btn btn-primary bg-white text-primary">Посмотреть статистику</button>
|
||||
<button type="submit" class="btn btn-outline-primary">Посмотреть статистику</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@ -86,9 +86,9 @@
|
||||
<table class="table table-bordered text-center text-secondary mt-5" style="background-color:#f2f2f2;">
|
||||
<thead>
|
||||
<tr>
|
||||
<td scope="col">Пользователи/Даты</td>
|
||||
<td scope="col"> </td>
|
||||
{% for date in log_stats.keys %}
|
||||
<td scope="col">{{date}}</td>
|
||||
<td scope="col">{{ date | date:'d.m' }}</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
@ -96,7 +96,7 @@
|
||||
<tr>
|
||||
<td>{{ form.email.value }}</td>
|
||||
{% for time in log_stats.values %}
|
||||
<td>{{time}}</td>
|
||||
<td>{{ time | floatformat:2 }}</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -7,7 +7,12 @@
|
||||
{% block heading %}Управление правами{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
<link rel="stylesheet" href="{% static 'main/css/work.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'main/css/work.css' %}" xmlns="http://www.w3.org/1999/html">
|
||||
<link rel="stylesheet" href="{% static 'modules/notifications/dist/notifications.css' %}">
|
||||
{% endblock %}
|
||||
{% block extra_scripts %}
|
||||
<script src="{% static 'modules/notifications/dist/notifications.js' %}"></script>
|
||||
<script src="{% static 'main/js/notifications.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
@ -60,8 +65,16 @@
|
||||
<a href="/work/become_engineer" class="request-acess-button default-button">Получить права инженера</a>
|
||||
<a href="/work/hand_over" class="hand-over-acess-button default-button">Сдать права инженера</a>
|
||||
</div>
|
||||
<div class="col-10">
|
||||
<form method="GET" action="/work/get_tickets">
|
||||
<input class="form-control mb-3" type="number" min="1" value="1" name="count_tickets">
|
||||
<button type="submit" class="default-button">Взять тикеты в работу</button>
|
||||
</form>
|
||||
</div>
|
||||
{% for message in messages %}
|
||||
<script>create_notification('{{message}}','','{{message.tags}}',5000)</script>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% include 'base/success_messages.html' %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
256
main/views.py
256
main/views.py
@ -1,48 +1,55 @@
|
||||
import logging
|
||||
import os
|
||||
from datetime import datetime
|
||||
from typing import Union, Tuple
|
||||
from smtplib import SMTPException
|
||||
from typing import Dict, Any
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.forms import PasswordResetForm
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
|
||||
from django.contrib.auth.models import User, Permission
|
||||
from django.contrib.auth.tokens import default_token_generator
|
||||
from django.contrib.auth.forms import PasswordResetForm
|
||||
from django.contrib.auth.views import LoginView
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.core.handlers.wsgi import WSGIRequest
|
||||
from django.http import HttpResponseRedirect, HttpResponse
|
||||
from django.shortcuts import render, get_list_or_404, redirect
|
||||
from django.shortcuts import render, redirect
|
||||
from django.urls import reverse_lazy, reverse
|
||||
from django.views.generic import FormView
|
||||
from django_registration.views import RegistrationView
|
||||
from django.contrib import messages
|
||||
import django.utils
|
||||
|
||||
# Django REST
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.response import Response
|
||||
|
||||
from zenpy.lib.api_objects import User as ZenpyUser
|
||||
|
||||
from access_controller.settings import EMAIL_HOST_USER, ZENDESK_ROLES, ZENDESK_MAX_AGENTS
|
||||
from main.extra_func import ZendeskAdmin
|
||||
from access_controller.settings import DEFAULT_FROM_EMAIL, ZENDESK_ROLES, ZENDESK_MAX_AGENTS
|
||||
from main.extra_func import check_user_exist, update_profile, get_user_organization, \
|
||||
make_engineer, make_light_agent, get_users_list, update_users_in_model, count_users, \
|
||||
StatisticData
|
||||
StatisticData, log, set_session_params_for_work_page
|
||||
from main.zendesk_admin import zenpy
|
||||
from main.forms import AdminPageUsers, CustomRegistrationForm, CustomAuthenticationForm, StatisticForm
|
||||
from main.serializers import ProfileSerializer
|
||||
from main.serializers import ProfileSerializer, ZendeskUserSerializer
|
||||
from .models import UserProfile
|
||||
|
||||
|
||||
def setup_context(profile_lit: bool = False, control_lit: bool = False, work_lit: bool = False,
|
||||
registration_lit: bool = False, login_lit: bool = False, stats_lit: bool = False) -> Dict[str, Any]:
|
||||
|
||||
context = {
|
||||
'profile_lit': profile_lit,
|
||||
'control_lit': control_lit,
|
||||
'work_lit': work_lit,
|
||||
'registration_lit': registration_lit,
|
||||
'login_lit': login_lit,
|
||||
'stats_lit': stats_lit,
|
||||
}
|
||||
return context
|
||||
|
||||
|
||||
class CustomRegistrationView(RegistrationView):
|
||||
"""
|
||||
Отображение и логика работы страницы регистрации пользователя.
|
||||
|
||||
:param form_class: Форма, которую необходимо заполнить для регистрации
|
||||
:type form_class: :class:`main.forms.CustomRegistrationForm`
|
||||
:type form_class: :class:`forms.CustomRegistrationForm`
|
||||
:param template_name: Указание пути к html-странице django регистрации
|
||||
:type template_name: :class:`str`
|
||||
:param success_url: Указание пути к html-странице завершения регистрации
|
||||
@ -50,12 +57,17 @@ class CustomRegistrationView(RegistrationView):
|
||||
:param is_allowed: Определение зарегистрирован ли пользователь с введенным email на Zendesk и принадлежит ли он к организации SYSTEM
|
||||
:type is_allowed: :class:`bool`
|
||||
"""
|
||||
form_class: CustomRegistrationForm = CustomRegistrationForm
|
||||
template_name: str = 'django_registration/registration_form.html'
|
||||
success_url: str = reverse_lazy('django_registration_complete')
|
||||
is_allowed: bool = True
|
||||
extra_context = setup_context(registration_lit=True)
|
||||
form_class = CustomRegistrationForm
|
||||
template_name = 'django_registration/registration_form.html'
|
||||
urls = {
|
||||
'done': reverse_lazy('password_reset_done'),
|
||||
'invalid_zendesk_email': reverse_lazy('django_registration_disallowed'),
|
||||
'email_sending_error': reverse_lazy('registration_email_error'),
|
||||
}
|
||||
redirect_url = 'done'
|
||||
|
||||
def register(self, form: CustomRegistrationForm) -> Union[User, bool]:
|
||||
def register(self, form: CustomRegistrationForm) -> User:
|
||||
"""
|
||||
Функция регистрации пользователя.
|
||||
1. Ввод email пользователя, указанный на Zendesk
|
||||
@ -66,14 +78,14 @@ class CustomRegistrationView(RegistrationView):
|
||||
:param form: Email пользователя на Zendesk
|
||||
:return: user
|
||||
"""
|
||||
self.is_allowed = True
|
||||
self.redirect_url = 'done'
|
||||
if check_user_exist(form.data['email']) and get_user_organization(form.data['email']) == 'SYSTEM':
|
||||
forms = PasswordResetForm(self.request.POST)
|
||||
if forms.is_valid():
|
||||
opts = {
|
||||
'use_https': self.request.is_secure(),
|
||||
'token_generator': default_token_generator,
|
||||
'from_email': EMAIL_HOST_USER,
|
||||
'from_email': DEFAULT_FROM_EMAIL,
|
||||
'email_template_name': 'registration/password_reset_email.html',
|
||||
'subject_template_name': 'registration/password_reset_subject.txt',
|
||||
'request': self.request,
|
||||
@ -85,17 +97,20 @@ class CustomRegistrationView(RegistrationView):
|
||||
email=form.data['email'],
|
||||
password=User.objects.make_random_password(length=50)
|
||||
)
|
||||
forms.save(**opts)
|
||||
update_profile(user.userprofile)
|
||||
self.set_permission(user)
|
||||
return user
|
||||
try:
|
||||
update_profile(user.userprofile)
|
||||
self.set_permission(user)
|
||||
forms.save(**opts)
|
||||
return user
|
||||
except SMTPException:
|
||||
self.redirect_url = 'email_sending_error'
|
||||
else:
|
||||
raise ValueError('Непредвиденная ошибка')
|
||||
else:
|
||||
self.is_allowed = False
|
||||
self.redirect_url = 'invalid_zendesk_email'
|
||||
|
||||
@staticmethod
|
||||
def set_permission(user: User) -> User:
|
||||
def set_permission(user: User) -> None:
|
||||
"""
|
||||
Функция дает разрешение на просмотр страница администратора, если пользователь имеет роль admin.
|
||||
|
||||
@ -109,7 +124,7 @@ class CustomRegistrationView(RegistrationView):
|
||||
)
|
||||
user.user_permissions.add(permission)
|
||||
|
||||
def get_success_url(self, user: User = None) -> success_url:
|
||||
def get_success_url(self, user: User = None):
|
||||
"""
|
||||
Функция возвращает url-адрес страницы, куда нужно перейти после успешной/не успешной регистрации.
|
||||
Используется самой django-registration.
|
||||
@ -117,10 +132,11 @@ class CustomRegistrationView(RegistrationView):
|
||||
:param user: пользователь, пытающийся зарегистрироваться
|
||||
:return: адресация на страницу успешной регистрации
|
||||
"""
|
||||
if self.is_allowed:
|
||||
return reverse_lazy('password_reset_done')
|
||||
else:
|
||||
return reverse_lazy('django_registration_disallowed')
|
||||
return self.urls[self.redirect_url]
|
||||
|
||||
|
||||
def registration_error(request):
|
||||
return render(request, 'django_registration/registration_error.html')
|
||||
|
||||
|
||||
@login_required()
|
||||
@ -133,26 +149,15 @@ def profile_page(request: WSGIRequest) -> HttpResponse:
|
||||
"""
|
||||
user_profile: UserProfile = request.user.userprofile
|
||||
update_profile(user_profile)
|
||||
context = {
|
||||
context = setup_context(profile_lit=True)
|
||||
context.update({
|
||||
'profile': user_profile,
|
||||
'pagename': 'Страница профиля',
|
||||
'ZENDESK_ROLES': ZENDESK_ROLES,
|
||||
}
|
||||
})
|
||||
return render(request, 'pages/profile.html', context)
|
||||
|
||||
|
||||
def auth_user(request: WSGIRequest) -> Tuple:
|
||||
"""
|
||||
Функция возвращает профиль пользователя на Zendesk.
|
||||
|
||||
:param request: email, subdomain и token пользователя
|
||||
:return: объект пользователя Zendesk
|
||||
"""
|
||||
admin = ZendeskAdmin().admin
|
||||
zenpy_user: ZenpyUser = admin.users.search(request.user.email).values[0]
|
||||
return zenpy_user, admin
|
||||
|
||||
|
||||
@login_required()
|
||||
def work_page(request: WSGIRequest, id: int) -> HttpResponse:
|
||||
"""
|
||||
@ -164,71 +169,75 @@ def work_page(request: WSGIRequest, id: int) -> HttpResponse:
|
||||
"""
|
||||
users = get_users_list()
|
||||
if request.user.id == id:
|
||||
if request.session.get('is_confirm', None):
|
||||
messages.success(request, 'Изменения были применены')
|
||||
elif request.session.get('is_confirm', None) is not None:
|
||||
messages.error(request, 'Изменения не были применены')
|
||||
count = request.session.get('count_tickets', None)
|
||||
if count is not None:
|
||||
messages.success(request, f'{count} тикетов назначено')
|
||||
request.session['is_confirm'] = None
|
||||
request.session['count_tickets'] = None
|
||||
|
||||
engineers = []
|
||||
light_agents = []
|
||||
for user in users:
|
||||
|
||||
if user.custom_role_id == ZENDESK_ROLES['engineer']:
|
||||
engineers.append(user)
|
||||
elif user.custom_role_id == ZENDESK_ROLES['light_agent']:
|
||||
light_agents.append(user)
|
||||
|
||||
context = {
|
||||
context = setup_context(work_lit=True)
|
||||
context.update({
|
||||
'engineers': engineers,
|
||||
'agents': light_agents,
|
||||
'messages': messages.get_messages(request),
|
||||
'licences_remaining': max(0, ZENDESK_MAX_AGENTS - len(engineers)),
|
||||
'pagename': 'Управление правами'
|
||||
}
|
||||
'pagename': 'Управление правами',
|
||||
})
|
||||
return render(request, 'pages/work.html', context)
|
||||
return redirect("login")
|
||||
|
||||
|
||||
def user_update(zenpy_user: User, admin: User, request: WSGIRequest) -> UserProfile:
|
||||
"""
|
||||
Функция устанавливает пользователю роль "agent" (изменяет профиль).
|
||||
|
||||
:param zenpy_user: Пользователь Zendesk
|
||||
:param admin: Пользователь
|
||||
:param request: Запрос установки роли "agent" в Userprofile
|
||||
:return: Обновленный профиль пользователя
|
||||
"""
|
||||
|
||||
admin.users.update(zenpy_user)
|
||||
request.user.userprofile.role = "agent"
|
||||
request.user.userprofile.save()
|
||||
messages.success(request, "Права были изменены")
|
||||
|
||||
|
||||
@login_required()
|
||||
def work_hand_over(request: WSGIRequest) -> HttpResponseRedirect:
|
||||
def work_hand_over(request: WSGIRequest):
|
||||
"""
|
||||
Функция позволяет текущему пользователю (login_required) сдать права, а именно сменить в Zendesk роль с "engineer" на "light agent"
|
||||
и установить роль "agent" в БД. Действия выполняются, если исходная роль пользователя "engineer".
|
||||
Функция позволяет текущему пользователю сдать права, а именно сменить в Zendesk роль с "engineer" на "light_agent"
|
||||
|
||||
:param request: данные текущего пользователя (login_required)
|
||||
:return: перезагрузка текущей страницы после выполнения смены роли
|
||||
"""
|
||||
zenpy_user, admin = auth_user(request)
|
||||
if zenpy_user.custom_role_id == ZENDESK_ROLES['engineer']:
|
||||
zenpy_user.custom_role_id = ZENDESK_ROLES['light_agent']
|
||||
user_update(zenpy_user, admin, request)
|
||||
return HttpResponseRedirect(reverse('work', args=(request.user.id,)))
|
||||
make_light_agent(request.user.userprofile, request.user)
|
||||
return set_session_params_for_work_page(request)
|
||||
|
||||
|
||||
@login_required()
|
||||
def work_become_engineer(request: WSGIRequest) -> HttpResponseRedirect:
|
||||
"""
|
||||
Функция меняет роль пользователя в Zendesk на "engineer" и присваивает роль "agent" в БД (в случае, если исходная роль пользователя была "light_agent").
|
||||
Функция позволяет текущему пользователю получить права, а именно сменить в Zendesk роль с "light_agent" на "engineer"
|
||||
|
||||
:param request: данные текущего пользователя (login_required)
|
||||
:return: перезагрузка текущей страницы после выполнения смены роли
|
||||
"""
|
||||
zenpy_user, admin = auth_user(request)
|
||||
if zenpy_user.custom_role_id == ZENDESK_ROLES['light_agent']:
|
||||
zenpy_user.custom_role_id = ZENDESK_ROLES['engineer']
|
||||
user_update(zenpy_user, admin, request)
|
||||
return HttpResponseRedirect(reverse('work', args=(request.user.id,)))
|
||||
|
||||
make_engineer(request.user.userprofile, request.user)
|
||||
return set_session_params_for_work_page(request)
|
||||
|
||||
|
||||
@login_required()
|
||||
def work_get_tickets(request):
|
||||
zenpy_user = zenpy.get_user(request.user.email)
|
||||
if zenpy_user.role == 'admin' or zenpy_user.custom_role_id == ZENDESK_ROLES['engineer']:
|
||||
tickets = [ticket for ticket in zenpy.admin.search(type="ticket") if
|
||||
ticket.group.name == 'Сменная группа' and ticket.assignee is None]
|
||||
count = 0
|
||||
for i in range(len(tickets)):
|
||||
if i == int(request.GET.get('count_tickets')):
|
||||
return set_session_params_for_work_page(request, count)
|
||||
tickets[i].assignee = zenpy_user
|
||||
zenpy.admin.tickets.update(tickets[i])
|
||||
count += 1
|
||||
return set_session_params_for_work_page(request, count)
|
||||
return set_session_params_for_work_page(request, is_confirm=False)
|
||||
|
||||
|
||||
def main_page(request: WSGIRequest) -> HttpResponse:
|
||||
@ -238,7 +247,7 @@ def main_page(request: WSGIRequest) -> HttpResponse:
|
||||
return render(request, 'pages/index.html')
|
||||
|
||||
|
||||
class AdminPageView(LoginRequiredMixin, PermissionRequiredMixin,SuccessMessageMixin, FormView):
|
||||
class AdminPageView(LoginRequiredMixin, PermissionRequiredMixin, SuccessMessageMixin, FormView):
|
||||
"""
|
||||
Класс отображения страницы администратора.
|
||||
|
||||
@ -271,7 +280,7 @@ class AdminPageView(LoginRequiredMixin, PermissionRequiredMixin,SuccessMessageMi
|
||||
self.make_light_agents(users)
|
||||
return super().form_valid(form)
|
||||
|
||||
def make_engineers(self, users: list) -> list:
|
||||
def make_engineers(self, users):
|
||||
"""
|
||||
Функция проходит по списку пользователей, проставляя статус "engineer".
|
||||
|
||||
@ -280,8 +289,9 @@ class AdminPageView(LoginRequiredMixin, PermissionRequiredMixin,SuccessMessageMi
|
||||
"""
|
||||
for user in users:
|
||||
make_engineer(user, self.request.user)
|
||||
log(user, self.request.user.userprofile)
|
||||
|
||||
def make_light_agents(self, users: list) -> list:
|
||||
def make_light_agents(self, users):
|
||||
"""
|
||||
Функция проходит по списку пользователей, проставляя статус "light agent".
|
||||
|
||||
@ -290,21 +300,14 @@ class AdminPageView(LoginRequiredMixin, PermissionRequiredMixin,SuccessMessageMi
|
||||
"""
|
||||
for user in users:
|
||||
make_light_agent(user, self.request.user)
|
||||
|
||||
def get_context_data(self, **kwargs) -> dict:
|
||||
"""
|
||||
Функция формирования контента страницы администратора (с проверкой прав доступа)
|
||||
"""
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['engineers'], context['light_agents'] = count_users(get_users_list())
|
||||
context['licences_remaining'] = max(0, ZENDESK_MAX_AGENTS - context['engineers'])
|
||||
return context
|
||||
log(user, self.request.user.userprofile)
|
||||
|
||||
|
||||
class CustomLoginView(LoginView):
|
||||
"""
|
||||
Отображение страницы авторизации пользователя
|
||||
"""
|
||||
extra_context = setup_context(login_lit=True)
|
||||
form_class = CustomAuthenticationForm
|
||||
|
||||
|
||||
@ -316,16 +319,35 @@ class UsersViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
serializer_class = ProfileSerializer
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
users = update_users_in_model().values
|
||||
count = count_users(users)
|
||||
users = update_users_in_model()
|
||||
count = count_users(users.values)
|
||||
profiles = UserProfile.objects.filter(role='agent')
|
||||
serializer = self.get_serializer(profiles, many=True)
|
||||
return Response({
|
||||
res = {
|
||||
'users': serializer.data,
|
||||
'engineers': count[0],
|
||||
'light_agents': count[1]
|
||||
})
|
||||
'light_agents': count[1],
|
||||
'zendesk_users': self.get_zendesk_users(self.choose_users(users.values, profiles)),
|
||||
'max_agents': ZENDESK_MAX_AGENTS
|
||||
}
|
||||
return Response(res)
|
||||
|
||||
@staticmethod
|
||||
def choose_users(zendesk, model):
|
||||
users = []
|
||||
for zendesk_user in zendesk:
|
||||
if zendesk_user.name not in [user.name for user in model]:
|
||||
users.append(zendesk_user)
|
||||
return users
|
||||
|
||||
@staticmethod
|
||||
def get_zendesk_users(users):
|
||||
zendesk_users = ZendeskUserSerializer(
|
||||
data=[user for user in users if user.role != 'admin'],
|
||||
many=True
|
||||
)
|
||||
zendesk_users.is_valid()
|
||||
return zendesk_users.data
|
||||
|
||||
|
||||
@login_required()
|
||||
@ -336,27 +358,33 @@ def statistic_page(request: WSGIRequest) -> HttpResponse:
|
||||
:param request: данные о пользователе: email, время и интервал работы. Данные получаем через forms.StatisticForm
|
||||
:return: адресация на страницу статистики
|
||||
"""
|
||||
if not request.user.has_perm('main.has_control_access'):
|
||||
return PermissionDenied
|
||||
context = {
|
||||
|
||||
# if not request.user.has_perm('main.has_control_access'):
|
||||
# raise PermissionDenied
|
||||
# context = {
|
||||
|
||||
if not request.user.has_perm("main.has_control_access"):
|
||||
return redirect('index')
|
||||
context = setup_context(stats_lit=True)
|
||||
context.update({
|
||||
'pagename': 'страница статистики',
|
||||
'errors': list(),
|
||||
}
|
||||
})
|
||||
if request.method == "POST":
|
||||
form = StatisticForm(request.POST)
|
||||
if form.is_valid():
|
||||
start_date, end_date = form.cleaned_data['range_start'], form.cleaned_data['range_end']
|
||||
interval, show = form.cleaned_data['interval'], form.cleaned_data['display_format']
|
||||
Data = StatisticData(start_date, end_date, form.cleaned_data['email'])
|
||||
Data.set_display(show)
|
||||
Data.set_interval(interval)
|
||||
stats = Data.get_statistic()
|
||||
if Data.errors:
|
||||
context['errors'] = Data.errors
|
||||
if Data.warnings:
|
||||
context['warnings'] = Data.warnings
|
||||
data = StatisticData(start_date, end_date, form.cleaned_data['email'])
|
||||
data.set_display(show)
|
||||
data.set_interval(interval)
|
||||
stats = data.get_statistic()
|
||||
if data.errors:
|
||||
context['errors'] = data.errors
|
||||
if data.warnings:
|
||||
context['warnings'] = data.warnings
|
||||
context['log_stats'] = stats if not context['errors'] else None
|
||||
if request.method == 'GET':
|
||||
elif request.method == 'GET':
|
||||
form = StatisticForm()
|
||||
context['form'] = form
|
||||
return render(request, 'pages/statistic.html', context)
|
||||
|
93
main/zendesk_admin.py
Normal file
93
main/zendesk_admin.py
Normal file
@ -0,0 +1,93 @@
|
||||
from typing import Optional, Dict
|
||||
|
||||
from zenpy import Zenpy
|
||||
from zenpy.lib.api_objects import User as ZenpyUser, Group as ZenpyGroup
|
||||
from zenpy.lib.exception import APIException
|
||||
|
||||
from access_controller.settings import ACTRL_ZENDESK_SUBDOMAIN, ACTRL_API_EMAIL, ACTRL_API_TOKEN, ACTRL_API_PASSWORD, \
|
||||
ZENDESK_GROUPS, SOLVED_TICKETS_EMAIL
|
||||
|
||||
|
||||
class ZendeskAdmin:
|
||||
"""
|
||||
Класс **ZendeskAdmin** существует, чтобы в каждой функции отдельно не проверять аккаунт администратора.
|
||||
|
||||
:param credentials: Полномочия (первым указывается учетная запись организации в Zendesk)
|
||||
:type credentials: :class:`Dict[str, str]`
|
||||
"""
|
||||
|
||||
def __init__(self, credentials: Dict[str, str]):
|
||||
self.credentials = credentials
|
||||
self.admin = self.create_admin()
|
||||
self.buffer_group_id: int = self.get_group(ZENDESK_GROUPS['buffer']).id
|
||||
self.solved_tickets_user_id: int = self.get_user(SOLVED_TICKETS_EMAIL).id
|
||||
|
||||
def check_user(self, email: str) -> bool:
|
||||
"""
|
||||
Функция осуществляет проверку существования пользователя в Zendesk по email.
|
||||
|
||||
:param email: Email пользователя
|
||||
:return: Является ли зарегистрированным
|
||||
"""
|
||||
return True if self.admin.search(email, type='user') else False
|
||||
|
||||
def get_user(self, email: str) -> ZenpyUser:
|
||||
"""
|
||||
Функция возвращает пользователя (объект) по его email.
|
||||
|
||||
:param email: Email пользователя
|
||||
:return: Объект пользователя, найденного в БД
|
||||
"""
|
||||
return self.admin.users.search(email).values[0]
|
||||
|
||||
def get_group(self, name: str) -> Optional[ZenpyGroup]:
|
||||
"""
|
||||
Функция возвращает группу по названию
|
||||
|
||||
:param name: Имя пользователя
|
||||
:return: Группы пользователя (в случае отсутствия None)
|
||||
"""
|
||||
groups = self.admin.search(name, type='group')
|
||||
for group in groups:
|
||||
return group
|
||||
return None
|
||||
|
||||
def get_user_org(self, email: str) -> str:
|
||||
"""
|
||||
Функция возвращает организацию, к которой относится пользователь по его email.
|
||||
|
||||
:param email: Email пользователя
|
||||
:return: Организация пользователя
|
||||
"""
|
||||
user = self.admin.users.search(email).values[0]
|
||||
return user.organization.name if user.organization else None
|
||||
|
||||
def create_admin(self) -> Zenpy:
|
||||
"""
|
||||
Функция создает администратора, проверяя наличие вводимых данных в env.
|
||||
|
||||
:raise: :class:`ValueError`: исключение, вызываемое если email не введен в env
|
||||
:raise: :class:`APIException`: исключение, вызываемое если пользователя с таким email не существует в Zendesk
|
||||
"""
|
||||
|
||||
if self.credentials.get('email') is None:
|
||||
raise ValueError('access_controller email not in env')
|
||||
|
||||
if self.credentials.get('token') is None and self.credentials.get('password') is None:
|
||||
raise ValueError('access_controller token or password not in env')
|
||||
|
||||
admin = Zenpy(**self.credentials)
|
||||
try:
|
||||
admin.search(self.credentials['email'], type='user')
|
||||
except APIException:
|
||||
raise ValueError('invalid access_controller`s login data')
|
||||
|
||||
return admin
|
||||
|
||||
|
||||
zenpy = ZendeskAdmin({
|
||||
'subdomain': ACTRL_ZENDESK_SUBDOMAIN,
|
||||
'email': ACTRL_API_EMAIL,
|
||||
'token': ACTRL_API_TOKEN,
|
||||
'password': ACTRL_API_PASSWORD,
|
||||
})
|
@ -6,7 +6,8 @@ import sys
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'access_controller.settings')
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
|
||||
'access_controller.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
|
@ -1,15 +1 @@
|
||||
# Engine
|
||||
Django==3.1.6
|
||||
Pillow==8.1.0
|
||||
zenpy~=2.0.24
|
||||
django_registration==3.1.1
|
||||
djangorestframework==3.12.2
|
||||
daphne==3.0.1
|
||||
|
||||
|
||||
# Documentation
|
||||
Sphinx==3.4.3
|
||||
sphinx-rtd-theme==0.5.1
|
||||
sphinx-autodoc-typehints==1.11.1
|
||||
pyenchant==3.2.0
|
||||
sphinxcontrib-spelling==7.1.0
|
||||
-r requirements/dev.txt
|
||||
|
16
requirements/common.txt
Normal file
16
requirements/common.txt
Normal file
@ -0,0 +1,16 @@
|
||||
# Contains requirements common to all environments
|
||||
|
||||
# Engine
|
||||
Django==3.1.6
|
||||
Pillow==8.1.0
|
||||
zenpy~=2.0.24
|
||||
django_registration==3.1.1
|
||||
djangorestframework==3.12.2
|
||||
|
||||
|
||||
# Documentation
|
||||
Sphinx==3.4.3
|
||||
sphinx-rtd-theme==0.5.1
|
||||
sphinx-autodoc-typehints==1.11.1
|
||||
pyenchant==3.2.0
|
||||
sphinxcontrib-spelling==7.1.0
|
3
requirements/dev.txt
Normal file
3
requirements/dev.txt
Normal file
@ -0,0 +1,3 @@
|
||||
# Development specific dependencies
|
||||
-r common.txt
|
||||
|
5
requirements/prod.txt
Normal file
5
requirements/prod.txt
Normal file
@ -0,0 +1,5 @@
|
||||
# Production specific dependencies
|
||||
-r common.txt
|
||||
|
||||
daphne==3.0.1
|
||||
Twisted[tls,http2]==21.2.0
|
6
start.sh
Normal file
6
start.sh
Normal file
@ -0,0 +1,6 @@
|
||||
cd /access_controller/
|
||||
|
||||
python manage.py migrate
|
||||
|
||||
python manage.py collectstatic --noinput
|
||||
daphne -b 0.0.0.0 access_controller.asgi:application
|
@ -124,4 +124,7 @@
|
||||
padding: 10px;
|
||||
background: #3B91D4;
|
||||
color: white;
|
||||
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
function head_checkbox() {
|
||||
let head_checkbox = document.getElementById("head-checkbox");
|
||||
head_checkbox.addEventListener("click", () => {
|
||||
let checkboxes = document.getElementsByName("users");
|
||||
for (let checkbox of checkboxes) checkbox.click();
|
||||
});
|
||||
}
|
||||
|
||||
// React
|
||||
class TableRow extends React.Component {
|
||||
class ModelUserTableRow extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<tr>
|
||||
<td>
|
||||
<a href="#">{this.props.user.name}</a>
|
||||
</td>
|
||||
<td>{this.props.user.user.email}</td>
|
||||
<td>{this.props.user.zendesk_role}</td>
|
||||
<tr className={"table-dark"}>
|
||||
<td>
|
||||
<input
|
||||
type="checkbox"
|
||||
@ -18,11 +21,53 @@ class TableRow extends React.Component {
|
||||
name="users"
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<a href="#">{this.props.user.name}</a>
|
||||
</td>
|
||||
<td>{this.props.user.user.email}</td>
|
||||
<td>{this.props.user.zendesk_role}</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ModelUserTableRows extends React.Component {
|
||||
render() {
|
||||
return ReactDOM.createPortal(
|
||||
this.props.users.map((user, key) => (
|
||||
<ModelUserTableRow user={user} key={key} />
|
||||
)),
|
||||
document.getElementById("tbody")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ZendeskUserTableRow extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<tr className={"table-secondary"}>
|
||||
<td></td>
|
||||
<td>
|
||||
<a href="#">{this.props.user.name}</a>
|
||||
</td>
|
||||
<td>{this.props.user.email}</td>
|
||||
<td>{this.props.user.zendesk_role}</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ZendeskUserTableRows extends React.Component {
|
||||
render() {
|
||||
return ReactDOM.createPortal(
|
||||
this.props.users.map((user, key) => (
|
||||
<ZendeskUserTableRow user={user} key={key} />
|
||||
)),
|
||||
document.getElementById("tbody")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TableBody extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@ -30,20 +75,34 @@ class TableBody extends React.Component {
|
||||
users: [],
|
||||
engineers: 0,
|
||||
light_agents: 0,
|
||||
zendesk_users: [],
|
||||
max_agents: 3,
|
||||
};
|
||||
}
|
||||
|
||||
change_elemnts_html() {
|
||||
let elements = document.querySelectorAll(".info-quantity-value");
|
||||
let licences = document.getElementById("licences_remaining");
|
||||
elements[0].innerHTML = this.state.engineers;
|
||||
elements[1].innerHTML = this.state.light_agents;
|
||||
let max_licences = Math.max(
|
||||
this.state.max_agents - this.state.engineers,
|
||||
0
|
||||
);
|
||||
licences.innerHTML = "Свободных мест: " + max_licences;
|
||||
}
|
||||
|
||||
async get_users() {
|
||||
await axios.get("/api/users").then((response) => {
|
||||
this.setState({
|
||||
users: response.data.users,
|
||||
engineers: response.data.engineers,
|
||||
light_agents: response.data.light_agents,
|
||||
zendesk_users: response.data.zendesk_users,
|
||||
max_agents: response.data.max_agents,
|
||||
});
|
||||
let elements = document.querySelectorAll(".info-quantity-value");
|
||||
elements[0].innerHTML = this.state.engineers;
|
||||
elements[1].innerHTML = this.state.light_agents;
|
||||
});
|
||||
this.change_elemnts_html();
|
||||
}
|
||||
|
||||
delete_pretext() {
|
||||
@ -62,10 +121,14 @@ class TableBody extends React.Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
return this.state.users.map((user, key) => (
|
||||
<TableRow user={user} key={key} />
|
||||
));
|
||||
return (
|
||||
<tr>
|
||||
<ModelUserTableRows users={this.state.users} />
|
||||
<ZendeskUserTableRows users={this.state.zendesk_users} />
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ReactDOM.render(<TableBody />, document.getElementById("tbody"));
|
||||
head_checkbox();
|
||||
|
14
static/main/js/notifications.js
Normal file
14
static/main/js/notifications.js
Normal file
@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
function create_notification(title,description,theme,time){
|
||||
const myNotification = window.createNotification({
|
||||
closeOnClick: true,
|
||||
displayCloseButton: true,
|
||||
positionClass: 'nfc-top-right',
|
||||
theme: theme,
|
||||
showDuration: Number(time),
|
||||
});
|
||||
myNotification({
|
||||
title: title,
|
||||
message: description
|
||||
});
|
||||
};
|
3
static/modules/notifications/.babelrc
Normal file
3
static/modules/notifications/.babelrc
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"presets": ["es2015"]
|
||||
}
|
31
static/modules/notifications/.eslintrc.js
Normal file
31
static/modules/notifications/.eslintrc.js
Normal file
@ -0,0 +1,31 @@
|
||||
module.exports = {
|
||||
"env": {
|
||||
"browser": true,
|
||||
"commonjs": true,
|
||||
"es6": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"parserOptions": {
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"indent": [
|
||||
"error",
|
||||
"tab"
|
||||
],
|
||||
"linebreak-style": [
|
||||
"error",
|
||||
"windows"
|
||||
],
|
||||
"quotes": [
|
||||
"error",
|
||||
"single"
|
||||
],
|
||||
"semi": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"no-console": 0,
|
||||
"no-undef": 0
|
||||
}
|
||||
};
|
30
static/modules/notifications/.gitignore
vendored
Normal file
30
static/modules/notifications/.gitignore
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
# IDE files
|
||||
.idea/
|
||||
.DS_Store
|
||||
|
||||
# Build directories
|
||||
build/
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Lock files
|
||||
yarn.lock
|
||||
package-lock.json
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
3
static/modules/notifications/.travis.yml
Normal file
3
static/modules/notifications/.travis.yml
Normal file
@ -0,0 +1,3 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "7"
|
7
static/modules/notifications/LICENSE.md
Normal file
7
static/modules/notifications/LICENSE.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Notifications license
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
104
static/modules/notifications/__tests__/helpers.test.js
Normal file
104
static/modules/notifications/__tests__/helpers.test.js
Normal file
@ -0,0 +1,104 @@
|
||||
const { partial, append, isString, createElement, createParagraph } = require('../src/helpers');
|
||||
|
||||
const addNumbers = (x, y) => x + y;
|
||||
|
||||
const sum = (...numbers) => numbers.reduce((total, current) => total + current, 0);
|
||||
|
||||
describe('Helpers', () => {
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
describe('Partial', () => {
|
||||
it('should return a partially applied function', () => {
|
||||
expect(typeof partial(addNumbers, 10)).toEqual('function');
|
||||
});
|
||||
|
||||
it('should execute function when partially applied function is called', () => {
|
||||
expect(partial(addNumbers, 20)(10)).toEqual(30);
|
||||
});
|
||||
|
||||
it('should gather argument', () => {
|
||||
expect(partial(sum, 5, 10)(15, 20, 25)).toEqual(75);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Append', () => {
|
||||
const container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
|
||||
const elementToAppend = document.createElement('h1');
|
||||
elementToAppend.classList.add('heading');
|
||||
elementToAppend.innerText = 'working';
|
||||
|
||||
append(container, elementToAppend);
|
||||
|
||||
const element = document.querySelector('.heading');
|
||||
expect(element);
|
||||
|
||||
expect(element.innerText).toEqual('working');
|
||||
});
|
||||
|
||||
describe('Is string', () => {
|
||||
expect(isString(1)).toEqual(false);
|
||||
expect(isString(null)).toEqual(false);
|
||||
expect(isString(undefined)).toEqual(false);
|
||||
expect(isString({})).toEqual(false);
|
||||
|
||||
expect(isString('')).toEqual(true);
|
||||
expect(isString('a')).toEqual(true);
|
||||
expect(isString('1')).toEqual(true);
|
||||
expect(isString('some string')).toEqual(true);
|
||||
});
|
||||
|
||||
describe('Create element', () => {
|
||||
it('should create an element', () => {
|
||||
expect(createElement('p')).toEqual(document.createElement('p'));
|
||||
expect(createElement('h1')).toEqual(document.createElement('h1'));
|
||||
expect(createElement('ul')).toEqual(document.createElement('ul'));
|
||||
expect(createElement('li')).toEqual(document.createElement('li'));
|
||||
expect(createElement('div')).toEqual(document.createElement('div'));
|
||||
expect(createElement('span')).toEqual(document.createElement('span'));
|
||||
});
|
||||
|
||||
it('should add class names', () => {
|
||||
expect(createElement('div', 'someclass1', 'someclass2').classList.contains('someclass2'));
|
||||
expect(createElement('p', 'para', 'test').classList.contains('para'));
|
||||
|
||||
const mockUl = document.createElement('ul');
|
||||
mockUl.classList.add('nav');
|
||||
mockUl.classList.add('foo');
|
||||
|
||||
expect(createElement('ul', 'nav', 'foo').classList).toEqual(mockUl.classList);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Create paragraph', () => {
|
||||
it('should create a paragraph', () => {
|
||||
const p = document.createElement('p');
|
||||
p.innerText = 'Some text';
|
||||
expect(createParagraph()('Some text')).toEqual(p);
|
||||
});
|
||||
|
||||
it('should add class names', () => {
|
||||
const p = document.createElement('p');
|
||||
p.classList.add('body-text');
|
||||
p.classList.add('para');
|
||||
|
||||
expect(createParagraph('body-text', 'para')('')).toEqual(p);
|
||||
});
|
||||
|
||||
it('should set inner text', () => {
|
||||
const p = document.createElement('p');
|
||||
p.innerText = 'Hello world!';
|
||||
p.classList.add('text');
|
||||
|
||||
expect(createParagraph('text')('Hello world!')).toEqual(p);
|
||||
});
|
||||
|
||||
it('should append to DOM', () => {
|
||||
append(document.body, createParagraph('text')('hello'));
|
||||
expect(document.querySelector('.text').innerText).toEqual('hello');
|
||||
});
|
||||
});
|
||||
});
|
144
static/modules/notifications/__tests__/index.tests.js
Normal file
144
static/modules/notifications/__tests__/index.tests.js
Normal file
@ -0,0 +1,144 @@
|
||||
require('../src/index');
|
||||
|
||||
describe('Notifications', () => {
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
it('should display a console warning if no title or message is passed', () => {
|
||||
jest.spyOn(global.console, 'warn');
|
||||
window.createNotification()();
|
||||
expect(console.warn).toBeCalled();
|
||||
});
|
||||
|
||||
it('should render a default notification', () => {
|
||||
const notification = window.createNotification();
|
||||
|
||||
const title = 'I am a title';
|
||||
|
||||
// Should initially not contain any notifications
|
||||
expect(document.querySelectorAll('.ncf').length).toEqual(0);
|
||||
|
||||
// Create a notification instance with a title
|
||||
notification({ title });
|
||||
|
||||
// Should be one notification with the title passed in
|
||||
expect(document.querySelectorAll('.ncf').length).toEqual(1);
|
||||
expect(document.querySelector('.ncf-title').innerText).toEqual(title);
|
||||
|
||||
// Create a second instance so there should now be two instances
|
||||
notification({ title });
|
||||
expect(document.querySelectorAll('.ncf').length).toEqual(2);
|
||||
});
|
||||
|
||||
it('should close on click if the option is enabled', () => {
|
||||
const notification = window.createNotification({
|
||||
closeOnClick: true
|
||||
});
|
||||
|
||||
// Create a notification with a generic body
|
||||
notification({ message: 'some text' });
|
||||
|
||||
// Should be one notification instance
|
||||
expect(document.querySelectorAll('.ncf').length).toEqual(1);
|
||||
|
||||
// Click the notification
|
||||
document.querySelector('.ncf').click();
|
||||
|
||||
expect(document.querySelectorAll('.ncf').length).toEqual(0);
|
||||
});
|
||||
|
||||
it('should not close on click if the option is disabled', () => {
|
||||
const notification = window.createNotification({
|
||||
closeOnClick: false
|
||||
});
|
||||
|
||||
// Create a notification with a generic body
|
||||
notification({ message: 'some text' });
|
||||
|
||||
// Should be one notification instance
|
||||
expect(document.querySelectorAll('.ncf').length).toEqual(1);
|
||||
|
||||
// Click the notification
|
||||
document.querySelector('.ncf').click();
|
||||
|
||||
expect(document.querySelectorAll('.ncf').length).toEqual(1);
|
||||
});
|
||||
|
||||
it('should set position class if valid', () => {
|
||||
const validPositions = [
|
||||
'nfc-top-left',
|
||||
'nfc-top-right',
|
||||
'nfc-bottom-left',
|
||||
'nfc-bottom-right'
|
||||
];
|
||||
|
||||
validPositions.forEach(position => {
|
||||
const notification = window.createNotification({
|
||||
positionClass: position
|
||||
});
|
||||
|
||||
notification({ title: 'title here' });
|
||||
|
||||
const className = `.${position}`;
|
||||
|
||||
expect(document.querySelectorAll(className).length).toEqual(1);
|
||||
|
||||
const container = document.querySelector(className);
|
||||
expect(container.querySelectorAll('.ncf').length).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should revert to default to default position and warn if class is invalid', () => {
|
||||
const notification = window.createNotification({
|
||||
positionClass: 'invalid-name'
|
||||
});
|
||||
|
||||
jest.spyOn(global.console, 'warn');
|
||||
|
||||
notification({ message: 'test' });
|
||||
|
||||
expect(console.warn).toBeCalled();
|
||||
|
||||
expect(document.querySelectorAll('.nfc-top-right').length).toEqual(1);
|
||||
});
|
||||
|
||||
it('should allow a custom onclick callback', () => {
|
||||
let a = 'not clicked';
|
||||
|
||||
const notification = window.createNotification({
|
||||
onclick: () => {
|
||||
a = 'clicked';
|
||||
}
|
||||
});
|
||||
|
||||
notification({ message: 'click test' });
|
||||
|
||||
expect(a).toEqual('not clicked');
|
||||
|
||||
// Click the notification
|
||||
document.querySelector('.ncf').click();
|
||||
|
||||
expect(a).toEqual('clicked');
|
||||
});
|
||||
|
||||
it('should show for correct duration', () => {
|
||||
const notification = window.createNotification({
|
||||
showDuration: 500
|
||||
});
|
||||
|
||||
notification({ message: 'test' });
|
||||
|
||||
expect(document.querySelectorAll('.ncf').length).toEqual(1);
|
||||
|
||||
// Should exist after 400ms
|
||||
setTimeout(() => {
|
||||
expect(document.querySelectorAll('.ncf').length).toEqual(1);
|
||||
}, 400);
|
||||
|
||||
// Should delete after 500ms
|
||||
setTimeout(() => {
|
||||
expect(document.querySelectorAll('.ncf').length).toEqual(0);
|
||||
});
|
||||
}, 501);
|
||||
});
|
34
static/modules/notifications/demo/demo.js
Normal file
34
static/modules/notifications/demo/demo.js
Normal file
@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
// Written using ES5 JS for browser support
|
||||
window.addEventListener('DOMContentLoaded', function () {
|
||||
var form = document.querySelector('form');
|
||||
|
||||
form.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Form elements
|
||||
var title = form.querySelector('#title').value;
|
||||
var message = form.querySelector('#message').value;
|
||||
var position = form.querySelector('#position').value;
|
||||
var duration = form.querySelector('#duration').value;
|
||||
var theme = form.querySelector('#theme').value;
|
||||
var closeOnClick = form.querySelector('#close').checked;
|
||||
var displayClose = form.querySelector('#closeButton').checked;
|
||||
|
||||
if(!message) {
|
||||
message = 'You did not enter a message...';
|
||||
}
|
||||
|
||||
window.createNotification({
|
||||
closeOnClick: closeOnClick,
|
||||
displayCloseButton: displayClose,
|
||||
positionClass: position,
|
||||
showDuration: duration,
|
||||
theme: theme
|
||||
})({
|
||||
title: title,
|
||||
message: message
|
||||
});
|
||||
});
|
||||
});
|
101
static/modules/notifications/demo/index.html
Normal file
101
static/modules/notifications/demo/index.html
Normal file
@ -0,0 +1,101 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
</hea>
|
||||
<meta charset="UTF-8">
|
||||
<title>Notifications</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<style>
|
||||
body {
|
||||
background-color: floralwhite;
|
||||
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
|
||||
text-align: center;
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
form {
|
||||
text-align: left;
|
||||
max-width: 600px;
|
||||
width: 100%;
|
||||
margin: 0 auto;
|
||||
display: block;
|
||||
}
|
||||
|
||||
input, select {
|
||||
width: 100%;
|
||||
margin-top: 5px;
|
||||
margin-bottom: 20px;
|
||||
padding: 5px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
input[type=checkbox] {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
input[type=submit] {
|
||||
background: #2f96b4;
|
||||
border: 0;
|
||||
color: #fff;
|
||||
margin-bottom: 0;
|
||||
padding: 10px 5px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<!-- Notifications styling -->
|
||||
<link rel="stylesheet" href="../dist/notifications.css" type="text/css">
|
||||
<head>
|
||||
<body>
|
||||
<h1>Notifications</h1>
|
||||
<form>
|
||||
<label for="title">Title (optional)</label>
|
||||
<br/>
|
||||
<input type="text" id="title" placeholder="Enter a title..." value="Notification">
|
||||
|
||||
<label for="message">Message</label>
|
||||
<br/>
|
||||
<input type="text" id="message" placeholder="Enter a message..." value="I am a default message">
|
||||
|
||||
<label for="position">Notification position:</label>
|
||||
<br/>
|
||||
<select id="position">
|
||||
<option value="nfc-top-right">Top Right</option>
|
||||
<option value="nfc-bottom-right">Bottom Right</option>
|
||||
<option value="nfc-top-left">Top Left</option>
|
||||
<option value="nfc-bottom-left">Bottom Left</option>
|
||||
</select>
|
||||
|
||||
<label for="duration">Show Duration (ms)</label>
|
||||
<br/>
|
||||
<input id="duration" type="number" value="3000"/>
|
||||
|
||||
<label for="theme">Theme</label>
|
||||
<br/>
|
||||
<select id="theme">
|
||||
<option value="success">Success</option>
|
||||
<option value="info">Information</option>
|
||||
<option value="warning">Warning</option>
|
||||
<option value="error">Error</option>
|
||||
<option value="none">None</option>
|
||||
</select>
|
||||
|
||||
<label for="close">Close on click</label>
|
||||
<input id="close" type="checkbox" value="Close on click" checked>
|
||||
|
||||
<br/>
|
||||
|
||||
<label for="closeButton">Display a close button</label>
|
||||
<input id="closeButton" type="checkbox" value="Display close button">
|
||||
|
||||
<input type="submit" value="Display notification">
|
||||
</form>
|
||||
|
||||
<script src="../dist/notifications.js" type="text/javascript"></script>
|
||||
<script src="./demo.js" type="text/javascript"></script>
|
||||
</body>
|
||||
</html>
|
58
static/modules/notifications/package.json
Normal file
58
static/modules/notifications/package.json
Normal file
@ -0,0 +1,58 @@
|
||||
{
|
||||
"name": "styled-notifications",
|
||||
"version": "1.0.1",
|
||||
"description": "A simple JavaScript notifications library",
|
||||
"main": "dist/notifications.js",
|
||||
"scripts": {
|
||||
"start": "webpack --watch",
|
||||
"build": "webpack -p",
|
||||
"test": "jest",
|
||||
"prepare": "yarn run test && yarn run build"
|
||||
},
|
||||
"pre-commit": [
|
||||
"prepare"
|
||||
],
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/JamieLivingstone/Notifications.git"
|
||||
},
|
||||
"keywords": [
|
||||
"notification",
|
||||
"popup",
|
||||
"alert",
|
||||
"toast"
|
||||
],
|
||||
"author": "Jamie Livingstone",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Jamie Livingstone (https://github.com/JamieLivingstone)"
|
||||
},
|
||||
{
|
||||
"name": "cavebeavis (https://github.com/cavebeavis)"
|
||||
}
|
||||
],
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/JamieLivingstone/Notifications/issues"
|
||||
},
|
||||
"homepage": "https://github.com/JamieLivingstone/Notifications#readme",
|
||||
"devDependencies": {
|
||||
"babel-core": "^6.26.0",
|
||||
"babel-jest": "^21.0.2",
|
||||
"babel-loader": "^7.1.2",
|
||||
"babel-preset-es2015": "^6.24.1",
|
||||
"babel-preset-es2015-ie": "^6.7.0",
|
||||
"css-loader": "^0.28.7",
|
||||
"eslint": "^4.6.1",
|
||||
"extract-text-webpack-plugin": "^3.0.0",
|
||||
"jest": "^21.0.2",
|
||||
"node-sass": "^4.5.3",
|
||||
"pre-commit": "^1.2.2",
|
||||
"sass-loader": "^6.0.6",
|
||||
"style-loader": "^0.18.2",
|
||||
"webpack": "^3.5.6"
|
||||
}
|
||||
}
|
82
static/modules/notifications/readme.md
Normal file
82
static/modules/notifications/readme.md
Normal file
@ -0,0 +1,82 @@
|
||||
[](https://travis-ci.org/JamieLivingstone/Notifications)
|
||||
|
||||
# Notifications
|
||||
**Notifications** is a Javascript library for notifications heavily inspired by toastr but does not require any dependencies such as jQuery.
|
||||
|
||||
Works on browsers: IE9+, Safari, Chrome, FireFox, opera, edge
|
||||
|
||||
## npm Installation
|
||||
Do either
|
||||
```
|
||||
npm i styled-notifications
|
||||
```
|
||||
or add the following to your `package.json`:
|
||||
```
|
||||
"dependencies": {
|
||||
"styled-notifications": "^1.0.1"
|
||||
},
|
||||
```
|
||||
|
||||
## Installation
|
||||
Download files from the dist folder and then:
|
||||
1. Link to notifications.css `<link href="notifications.css" rel="stylesheet"/>`
|
||||
|
||||
2. Link to notifications.js `<script src="notifications.js"></script>`
|
||||
|
||||
## Usage
|
||||
### Custom options
|
||||
- closeOnClick <bool> - Close the notification dialog when a click is invoked.
|
||||
- displayCloseButton <bool> - Display a close button in the top right hand corner of the notification.
|
||||
- positionClass <string> - Set the position of the notification dialog. Accepted positions: ('nfc-top-right', 'nfc-bottom-right', 'nfc-bottom-left', 'nfc-top-left').
|
||||
- onClick <function(event)> - Call a callback function when a click is invoked on a notification.
|
||||
- showDuration <integer> - Milliseconds the notification should be visible (0 for a notification that will remain open until clicked)
|
||||
- theme <string> - Set the position of the notification dialog. Accepted positions: ('success', 'info', 'warning', 'error', 'A custom clasName').
|
||||
```
|
||||
const defaultOptions = {
|
||||
closeOnClick: true,
|
||||
displayCloseButton: false,
|
||||
positionClass: 'nfc-top-right',
|
||||
onclick: false,
|
||||
showDuration: 3500,
|
||||
theme: 'success'
|
||||
};
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
### Success notification
|
||||
```
|
||||
// Create a success notification instance
|
||||
const successNotification = window.createNotification({
|
||||
theme: 'success',
|
||||
showDuration: 5000
|
||||
});
|
||||
|
||||
// Invoke success notification
|
||||
successNotification({
|
||||
message: 'Simple success notification'
|
||||
});
|
||||
|
||||
// Use the same instance but pass a title
|
||||
successNotification({
|
||||
title: 'Working',
|
||||
message: 'Simple success notification'
|
||||
});
|
||||
```
|
||||
|
||||
### Information notification
|
||||
```
|
||||
// Only running it once? Invoke immediately like this
|
||||
window.createNotification({
|
||||
theme: 'success',
|
||||
showDuration: 5000
|
||||
})({
|
||||
message: 'I have some information for you...'
|
||||
});
|
||||
```
|
||||
|
||||
### Todo
|
||||
~~1. Add to NPM~~
|
||||
2. Improve documentation
|
||||
3. Further device testing
|
||||
4. Add contributor instructions
|
24
static/modules/notifications/src/helpers.js
Normal file
24
static/modules/notifications/src/helpers.js
Normal file
@ -0,0 +1,24 @@
|
||||
export const partial = (fn, ...presetArgs) => (...laterArgs) => fn(...presetArgs, ...laterArgs);
|
||||
|
||||
export const append = (el, ...children) => children.forEach(child => el.appendChild(child));
|
||||
|
||||
export const isString = input => typeof input === 'string';
|
||||
|
||||
export const createElement = (elementType, ...classNames) => {
|
||||
const element = document.createElement(elementType);
|
||||
|
||||
if(classNames.length) {
|
||||
classNames.forEach(currentClass => element.classList.add(currentClass));
|
||||
}
|
||||
|
||||
return element;
|
||||
};
|
||||
|
||||
const setInnerText = (element, text) => {
|
||||
element.innerText = text;
|
||||
return element;
|
||||
};
|
||||
|
||||
const createTextElement = (elementType, ...classNames) => partial(setInnerText, createElement(elementType, ...classNames));
|
||||
|
||||
export const createParagraph = (...classNames) => createTextElement('p', ...classNames);
|
148
static/modules/notifications/src/index.js
Normal file
148
static/modules/notifications/src/index.js
Normal file
@ -0,0 +1,148 @@
|
||||
'use strict';
|
||||
|
||||
// Polyfills
|
||||
import './polyfills/classList';
|
||||
|
||||
import {
|
||||
append,
|
||||
createElement,
|
||||
createParagraph,
|
||||
isString
|
||||
} from './helpers';
|
||||
|
||||
(function Notifications(window) {
|
||||
// Default notification options
|
||||
const defaultOptions = {
|
||||
closeOnClick: true,
|
||||
displayCloseButton: false,
|
||||
positionClass: 'nfc-top-right',
|
||||
onclick: false,
|
||||
showDuration: 3500,
|
||||
theme: 'success'
|
||||
};
|
||||
|
||||
function configureOptions(options) {
|
||||
// Create a copy of options and merge with defaults
|
||||
options = Object.assign({}, defaultOptions, options);
|
||||
|
||||
// Validate position class
|
||||
function validatePositionClass(className) {
|
||||
const validPositions = [
|
||||
'nfc-top-left',
|
||||
'nfc-top-right',
|
||||
'nfc-bottom-left',
|
||||
'nfc-bottom-right'
|
||||
];
|
||||
|
||||
return validPositions.indexOf(className) > -1;
|
||||
}
|
||||
|
||||
// Verify position, if invalid reset to default
|
||||
if (!validatePositionClass(options.positionClass)) {
|
||||
console.warn('An invalid notification position class has been specified.');
|
||||
options.positionClass = defaultOptions.positionClass;
|
||||
}
|
||||
|
||||
// Verify onClick is a function
|
||||
if (options.onclick && typeof options.onclick !== 'function') {
|
||||
console.warn('Notification on click must be a function.');
|
||||
options.onclick = defaultOptions.onclick;
|
||||
}
|
||||
|
||||
// Verify show duration
|
||||
if(typeof options.showDuration !== 'number') {
|
||||
options.showDuration = defaultOptions.showDuration;
|
||||
}
|
||||
|
||||
// Verify theme
|
||||
if(!isString(options.theme) || options.theme.length === 0) {
|
||||
console.warn('Notification theme must be a string with length');
|
||||
options.theme = defaultOptions.theme;
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
// Create a new notification instance
|
||||
function createNotification(options) {
|
||||
// Validate options and set defaults
|
||||
options = configureOptions(options);
|
||||
|
||||
// Return a notification function
|
||||
return function notification({ title, message } = {}) {
|
||||
const container = createNotificationContainer(options.positionClass);
|
||||
|
||||
if(!title && !message) {
|
||||
return console.warn('Notification must contain a title or a message!');
|
||||
}
|
||||
|
||||
// Create the notification wrapper
|
||||
const notificationEl = createElement('div', 'ncf', options.theme);
|
||||
|
||||
// Close on click
|
||||
if(options.closeOnClick === true) {
|
||||
notificationEl.addEventListener('click', () => container.removeChild(notificationEl));
|
||||
}
|
||||
|
||||
// Custom click callback
|
||||
if(options.onclick) {
|
||||
notificationEl.addEventListener('click', (e) => options.onclick(e));
|
||||
}
|
||||
|
||||
// Display close button
|
||||
if(options.displayCloseButton) {
|
||||
const closeButton = createElement('button');
|
||||
closeButton.innerText = 'X';
|
||||
|
||||
// Use the wrappers close on click to avoid useless event listeners
|
||||
if(options.closeOnClick === false){
|
||||
closeButton.addEventListener('click', () =>container.removeChild(notificationEl));
|
||||
}
|
||||
|
||||
append(notificationEl, closeButton);
|
||||
}
|
||||
|
||||
// Append title and message
|
||||
isString(title) && title.length && append(notificationEl, createParagraph('ncf-title')(title));
|
||||
isString(message) && message.length && append(notificationEl, createParagraph('nfc-message')(message));
|
||||
|
||||
// Append to container
|
||||
append(container, notificationEl);
|
||||
|
||||
// Remove element after duration
|
||||
if(options.showDuration && options.showDuration > 0) {
|
||||
const timeout = setTimeout(() => {
|
||||
container.removeChild(notificationEl);
|
||||
|
||||
// Remove container if empty
|
||||
if(container.querySelectorAll('.ncf').length === 0) {
|
||||
document.body.removeChild(container);
|
||||
}
|
||||
}, options.showDuration);
|
||||
|
||||
// If close on click is enabled and the user clicks, cancel timeout
|
||||
if(options.closeOnClick || options.displayCloseButton) {
|
||||
notificationEl.addEventListener('click', () => clearTimeout(timeout));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function createNotificationContainer(position) {
|
||||
let container = document.querySelector(`.${position}`);
|
||||
|
||||
if(!container) {
|
||||
container = createElement('div', 'ncf-container', position);
|
||||
append(document.body, container);
|
||||
}
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
// Add Notifications to window to make globally accessible
|
||||
if (window.createNotification) {
|
||||
console.warn('Window already contains a create notification function. Have you included the script twice?');
|
||||
} else {
|
||||
window.createNotification = createNotification;
|
||||
}
|
||||
})(window);
|
68
static/modules/notifications/src/polyfills/classList.js
Normal file
68
static/modules/notifications/src/polyfills/classList.js
Normal file
@ -0,0 +1,68 @@
|
||||
(function () {
|
||||
if (typeof window.Element === 'undefined' || 'classList' in document.documentElement) return;
|
||||
|
||||
var prototype = Array.prototype,
|
||||
push = prototype.push,
|
||||
splice = prototype.splice,
|
||||
join = prototype.join;
|
||||
|
||||
function DOMTokenList(el) {
|
||||
this.el = el;
|
||||
// The className needs to be trimmed and split on whitespace
|
||||
// to retrieve a list of classes.
|
||||
var classes = el.className.replace(/^\s+|\s+$/g,'').split(/\s+/);
|
||||
for (var i = 0; i < classes.length; i++) {
|
||||
push.call(this, classes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
DOMTokenList.prototype = {
|
||||
add: function(token) {
|
||||
if(this.contains(token)) return;
|
||||
push.call(this, token);
|
||||
this.el.className = this.toString();
|
||||
},
|
||||
contains: function(token) {
|
||||
return this.el.className.indexOf(token) != -1;
|
||||
},
|
||||
item: function(index) {
|
||||
return this[index] || null;
|
||||
},
|
||||
remove: function(token) {
|
||||
if (!this.contains(token)) return;
|
||||
for (var i = 0; i < this.length; i++) {
|
||||
if (this[i] == token) break;
|
||||
}
|
||||
splice.call(this, i, 1);
|
||||
this.el.className = this.toString();
|
||||
},
|
||||
toString: function() {
|
||||
return join.call(this, ' ');
|
||||
},
|
||||
toggle: function(token) {
|
||||
if (!this.contains(token)) {
|
||||
this.add(token);
|
||||
} else {
|
||||
this.remove(token);
|
||||
}
|
||||
|
||||
return this.contains(token);
|
||||
}
|
||||
};
|
||||
|
||||
window.DOMTokenList = DOMTokenList;
|
||||
|
||||
function defineElementGetter (obj, prop, getter) {
|
||||
if (Object.defineProperty) {
|
||||
Object.defineProperty(obj, prop,{
|
||||
get : getter
|
||||
});
|
||||
} else {
|
||||
obj.__defineGetter__(prop, getter);
|
||||
}
|
||||
}
|
||||
|
||||
defineElementGetter(Element.prototype, 'classList', function () {
|
||||
return new DOMTokenList(this);
|
||||
});
|
||||
})();
|
134
static/modules/notifications/src/style.scss
Normal file
134
static/modules/notifications/src/style.scss
Normal file
@ -0,0 +1,134 @@
|
||||
// Base colors
|
||||
$success: #51A351;
|
||||
$info: #2F96B4;
|
||||
$warning: #f87400;
|
||||
$error: #BD362F;
|
||||
$grey: #999999;
|
||||
|
||||
.ncf-container {
|
||||
font-size: 14px;
|
||||
box-sizing: border-box;
|
||||
position: fixed;
|
||||
z-index: 999999;
|
||||
|
||||
&.nfc-top-left {
|
||||
top: 12px;
|
||||
left: 12px;
|
||||
}
|
||||
|
||||
&.nfc-top-right {
|
||||
top: 12px;
|
||||
right: 12px;
|
||||
}
|
||||
|
||||
&.nfc-bottom-right {
|
||||
bottom: 12px;
|
||||
right: 12px;
|
||||
}
|
||||
|
||||
&.nfc-bottom-left {
|
||||
bottom: 12px;
|
||||
left: 12px;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
.ncf {
|
||||
background: #ffffff;
|
||||
transition: .3s ease;
|
||||
position: relative;
|
||||
pointer-events: auto;
|
||||
overflow: hidden;
|
||||
margin: 0 0 6px;
|
||||
padding: 30px;
|
||||
width: 300px;
|
||||
border-radius: 3px 3px 3px 3px;
|
||||
box-shadow: 0 0 12px $grey;
|
||||
color: #000000;
|
||||
opacity: 0.9;
|
||||
-ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=90);
|
||||
filter: alpha(opacity=90);
|
||||
background-position: 15px center !important;
|
||||
background-repeat: no-repeat !important;
|
||||
|
||||
// Prevent annoying text selection
|
||||
-webkit-user-select: none; /* Chrome all / Safari all */
|
||||
-moz-user-select: none; /* Firefox all */
|
||||
-ms-user-select: none; /* IE 10+ */
|
||||
user-select: none; /* Likely future */
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 0 12px #000000;
|
||||
opacity: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.ncf-title {
|
||||
font-weight: bold;
|
||||
font-size: 16px;
|
||||
text-align: left;
|
||||
margin-top: 0;
|
||||
margin-bottom: 6px;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.nfc-message {
|
||||
margin: 0;
|
||||
text-align: left;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
}
|
||||
|
||||
// Themes
|
||||
.success {
|
||||
background: $success;
|
||||
color: #ffffff;
|
||||
padding: 15px 15px 15px 50px;
|
||||
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADsSURBVEhLY2AYBfQMgf///3P8+/evAIgvA/FsIF+BavYDDWMBGroaSMMBiE8VC7AZDrIFaMFnii3AZTjUgsUUWUDA8OdAH6iQbQEhw4HyGsPEcKBXBIC4ARhex4G4BsjmweU1soIFaGg/WtoFZRIZdEvIMhxkCCjXIVsATV6gFGACs4Rsw0EGgIIH3QJYJgHSARQZDrWAB+jawzgs+Q2UO49D7jnRSRGoEFRILcdmEMWGI0cm0JJ2QpYA1RDvcmzJEWhABhD/pqrL0S0CWuABKgnRki9lLseS7g2AlqwHWQSKH4oKLrILpRGhEQCw2LiRUIa4lwAAAABJRU5ErkJggg==");
|
||||
}
|
||||
|
||||
.info {
|
||||
background: $info;
|
||||
color: #ffffff;
|
||||
padding: 15px 15px 15px 50px;
|
||||
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAGwSURBVEhLtZa9SgNBEMc9sUxxRcoUKSzSWIhXpFMhhYWFhaBg4yPYiWCXZxBLERsLRS3EQkEfwCKdjWJAwSKCgoKCcudv4O5YLrt7EzgXhiU3/4+b2ckmwVjJSpKkQ6wAi4gwhT+z3wRBcEz0yjSseUTrcRyfsHsXmD0AmbHOC9Ii8VImnuXBPglHpQ5wwSVM7sNnTG7Za4JwDdCjxyAiH3nyA2mtaTJufiDZ5dCaqlItILh1NHatfN5skvjx9Z38m69CgzuXmZgVrPIGE763Jx9qKsRozWYw6xOHdER+nn2KkO+Bb+UV5CBN6WC6QtBgbRVozrahAbmm6HtUsgtPC19tFdxXZYBOfkbmFJ1VaHA1VAHjd0pp70oTZzvR+EVrx2Ygfdsq6eu55BHYR8hlcki+n+kERUFG8BrA0BwjeAv2M8WLQBtcy+SD6fNsmnB3AlBLrgTtVW1c2QN4bVWLATaIS60J2Du5y1TiJgjSBvFVZgTmwCU+dAZFoPxGEEs8nyHC9Bwe2GvEJv2WXZb0vjdyFT4Cxk3e/kIqlOGoVLwwPevpYHT+00T+hWwXDf4AJAOUqWcDhbwAAAAASUVORK5CYII=");
|
||||
}
|
||||
|
||||
.warning {
|
||||
background: $warning;
|
||||
color: #ffffff;
|
||||
padding: 15px 15px 15px 50px;
|
||||
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAGYSURBVEhL5ZSvTsNQFMbXZGICMYGYmJhAQIJAICYQPAACiSDB8AiICQQJT4CqQEwgJvYASAQCiZiYmJhAIBATCARJy+9rTsldd8sKu1M0+dLb057v6/lbq/2rK0mS/TRNj9cWNAKPYIJII7gIxCcQ51cvqID+GIEX8ASG4B1bK5gIZFeQfoJdEXOfgX4QAQg7kH2A65yQ87lyxb27sggkAzAuFhbbg1K2kgCkB1bVwyIR9m2L7PRPIhDUIXgGtyKw575yz3lTNs6X4JXnjV+LKM/m3MydnTbtOKIjtz6VhCBq4vSm3ncdrD2lk0VgUXSVKjVDJXJzijW1RQdsU7F77He8u68koNZTz8Oz5yGa6J3H3lZ0xYgXBK2QymlWWA+RWnYhskLBv2vmE+hBMCtbA7KX5drWyRT/2JsqZ2IvfB9Y4bWDNMFbJRFmC9E74SoS0CqulwjkC0+5bpcV1CZ8NMej4pjy0U+doDQsGyo1hzVJttIjhQ7GnBtRFN1UarUlH8F3xict+HY07rEzoUGPlWcjRFRr4/gChZgc3ZL2d8oAAAAASUVORK5CYII=");
|
||||
}
|
||||
|
||||
.error {
|
||||
background: $error;
|
||||
color: #ffffff;
|
||||
padding: 15px 15px 15px 50px;
|
||||
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAHOSURBVEhLrZa/SgNBEMZzh0WKCClSCKaIYOED+AAKeQQLG8HWztLCImBrYadgIdY+gIKNYkBFSwu7CAoqCgkkoGBI/E28PdbLZmeDLgzZzcx83/zZ2SSXC1j9fr+I1Hq93g2yxH4iwM1vkoBWAdxCmpzTxfkN2RcyZNaHFIkSo10+8kgxkXIURV5HGxTmFuc75B2RfQkpxHG8aAgaAFa0tAHqYFfQ7Iwe2yhODk8+J4C7yAoRTWI3w/4klGRgR4lO7Rpn9+gvMyWp+uxFh8+H+ARlgN1nJuJuQAYvNkEnwGFck18Er4q3egEc/oO+mhLdKgRyhdNFiacC0rlOCbhNVz4H9FnAYgDBvU3QIioZlJFLJtsoHYRDfiZoUyIxqCtRpVlANq0EU4dApjrtgezPFad5S19Wgjkc0hNVnuF4HjVA6C7QrSIbylB+oZe3aHgBsqlNqKYH48jXyJKMuAbiyVJ8KzaB3eRc0pg9VwQ4niFryI68qiOi3AbjwdsfnAtk0bCjTLJKr6mrD9g8iq/S/B81hguOMlQTnVyG40wAcjnmgsCNESDrjme7wfftP4P7SP4N3CJZdvzoNyGq2c/HWOXJGsvVg+RA/k2MC/wN6I2YA2Pt8GkAAAAASUVORK5CYII=") !important;
|
||||
}
|
||||
|
||||
button {
|
||||
position: relative;
|
||||
right: -0.3em;
|
||||
top: -0.3em;
|
||||
float: right;
|
||||
font-weight: bold;
|
||||
color: #FFFFFF;
|
||||
text-shadow: 0 1px 0 #ffffff;
|
||||
opacity: 0.8;
|
||||
line-height: 1;
|
||||
font-size: 16px;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
41
static/modules/notifications/webpack.config.js
Normal file
41
static/modules/notifications/webpack.config.js
Normal file
@ -0,0 +1,41 @@
|
||||
const webpack = require('webpack');
|
||||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
|
||||
const extractSass = new ExtractTextPlugin({
|
||||
filename: 'notifications.css',
|
||||
disable: process.env.NODE_ENV === 'development'
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
entry: ['./src/index.js', './src/style.scss'],
|
||||
output: {
|
||||
path: __dirname + '/dist',
|
||||
filename: 'notifications.js'
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
loader: 'babel-loader',
|
||||
query: {
|
||||
presets: ['babel-preset-es2015', 'es2015-ie']
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: extractSass.extract({
|
||||
use: [{
|
||||
loader: 'css-loader'
|
||||
}, {
|
||||
loader: 'sass-loader'
|
||||
}],
|
||||
// use style-loader in development
|
||||
fallback: 'style-loader'
|
||||
})
|
||||
}
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
extractSass
|
||||
]
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user