Add notifications on work page, rebase already exists with notifications.js
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
import logging
|
||||
import os
|
||||
from datetime import timedelta, datetime, date
|
||||
|
||||
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 access_controller.settings import ZENDESK_ROLES as ROLES, ONE_DAY, ZENDESK_GROUPS, SOLVED_TICKETS_EMAIL, \
|
||||
ACTRL_API_EMAIL, ACTRL_API_TOKEN, ACTRL_API_PASSWORD, ACTRL_ZENDESK_SUBDOMAIN
|
||||
from main.models import UserProfile, RoleChangeLogs, UnassignedTicket, UnassignedTicketStatus
|
||||
@@ -666,3 +665,13 @@ def log(user, admin=0):
|
||||
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)
|
||||
|
||||
@@ -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>
|
||||
@@ -6,18 +6,16 @@
|
||||
|
||||
{% block heading %}Управление{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
<link rel="stylesheet" href="{% static 'main/css/work.css' %}"/>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_scripts %}
|
||||
<script src="https://unpkg.com/react@17/umd/react.development.js" crossorigin></script>
|
||||
<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">
|
||||
|
||||
@@ -25,6 +23,10 @@
|
||||
<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 %}
|
||||
@@ -100,9 +102,6 @@
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
{% include 'base/success_messages.html' %}
|
||||
</div>
|
||||
|
||||
<script src="{% static 'main/js/control.js'%}" type="text/babel"></script>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -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 %}
|
||||
@@ -66,8 +71,10 @@
|
||||
<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 %}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ from zenpy.lib.api_objects import User as ZenpyUser
|
||||
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, log, ZendeskAdmin
|
||||
StatisticData, log, ZendeskAdmin, set_session_params_for_work_page
|
||||
from main.forms import AdminPageUsers, CustomRegistrationForm, CustomAuthenticationForm, StatisticForm
|
||||
from main.serializers import ProfileSerializer, ZendeskUserSerializer
|
||||
from .models import UserProfile
|
||||
@@ -31,7 +31,6 @@ 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):
|
||||
|
||||
print(profile_lit, control_lit, work_lit, registration_lit, login_lit)
|
||||
|
||||
context = {
|
||||
@@ -182,29 +181,37 @@ 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 = 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")
|
||||
|
||||
|
||||
@login_required()
|
||||
def work_hand_over(request: WSGIRequest) -> HttpResponseRedirect:
|
||||
def work_hand_over(request: WSGIRequest):
|
||||
"""
|
||||
Функция позволяет текущему пользователю (login_required) сдать права, а именно сменить в Zendesk роль с "engineer" на "light agent"
|
||||
и установить роль "agent" в БД. Действия выполняются, если исходная роль пользователя "engineer".
|
||||
@@ -212,8 +219,8 @@ def work_hand_over(request: WSGIRequest) -> HttpResponseRedirect:
|
||||
:param request: данные текущего пользователя (login_required)
|
||||
:return: перезагрузка текущей страницы после выполнения смены роли
|
||||
"""
|
||||
make_light_agent(request.user.userprofile,request.user)
|
||||
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()
|
||||
@@ -224,22 +231,25 @@ def work_become_engineer(request: WSGIRequest) -> HttpResponseRedirect:
|
||||
:param request: данные текущего пользователя (login_required)
|
||||
:return: перезагрузка текущей страницы после выполнения смены роли
|
||||
"""
|
||||
zenpy_user, admin = auth_user(request)
|
||||
make_engineer(request.user.userprofile, request.user)
|
||||
return set_session_params_for_work_page(request)
|
||||
|
||||
make_engineer(request.user.userprofile,request.user)
|
||||
return HttpResponseRedirect(reverse('work', args=(request.user.id,)))
|
||||
|
||||
@login_required()
|
||||
def work_get_tickets(request):
|
||||
zenpy_user, admin = auth_user(request)
|
||||
count_tickets = int(request.GET["count_tickets"])
|
||||
tickets = [ticket for ticket in admin.search(type="ticket") if ticket.group.name == 'Сменная группа' and ticket.assignee is None]
|
||||
for i in range(len(tickets)):
|
||||
if i == count_tickets:
|
||||
return HttpResponseRedirect(reverse('work', args=(request.user.id,)))
|
||||
tickets[i].assignee = zenpy_user
|
||||
admin.tickets.update(tickets[i])
|
||||
return HttpResponseRedirect(reverse('work', args=(request.user.id,)))
|
||||
if zenpy_user.role == 'admin' or zenpy_user.custom_role_id == ZENDESK_ROLES['engineer']:
|
||||
tickets = [ticket for ticket in admin.search(type="ticket") if
|
||||
ticket.group.name == 'Сменная группа' and ticket.assignee is None]
|
||||
count = 0
|
||||
for i in range(len(tickets)):
|
||||
if i == request.GET.get('count_tickets'):
|
||||
return set_session_params_for_work_page(request, count)
|
||||
tickets[i].assignee = zenpy_user
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user