This commit is contained in:
Dmitriy Andreev 2021-04-15 19:57:16 +03:00
commit 8417616bac
6 changed files with 11 additions and 58 deletions

View File

@ -58,8 +58,8 @@ EMAIL_PORT = 587
EMAIL_USE_TLS = True EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'group02django@gmail.com' EMAIL_HOST_USER = 'group02django@gmail.com'
EMAIL_HOST_PASSWORD = 'djangogroup02' EMAIL_HOST_PASSWORD = 'djangogroup02'
SERVER_EMAIL = EMAIL_HOST_USER
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
SERVER_EMAIL = EMAIL_HOST_USER
TEMPLATES = [ TEMPLATES = [
{ {

View File

@ -14,7 +14,6 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.contrib import admin from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.urls import path, include from django.urls import path, include
from main.views import main_page, profile_page, CustomRegistrationView, CustomLoginView, registration_error from main.views import main_page, profile_page, CustomRegistrationView, CustomLoginView, registration_error
@ -30,41 +29,16 @@ urlpatterns = [
path('accounts/register/error/', registration_error, name='registration_email_error'), path('accounts/register/error/', registration_error, name='registration_email_error'),
path('accounts/login/', CustomLoginView.as_view(), name='login'), path('accounts/login/', CustomLoginView.as_view(), name='login'),
path('accounts/', include('django.contrib.auth.urls')), 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/<int:id>', work_page, name="work"),
path('work/hand_over/', work_hand_over, name="work_hand_over"), path('work/hand_over/', work_hand_over, name="work_hand_over"),
path('work/become_engineer/', work_become_engineer, name="work_become_engineer"), path('work/become_engineer/', work_become_engineer, name="work_become_engineer"),
path('work/get_tickets', work_get_tickets, name='work_get_tickets'), path('work/get_tickets', work_get_tickets, name='work_get_tickets'),
path('accounts/', include('django_registration.backends.activation.urls')), path('accounts/', include('django_registration.backends.activation.urls')),
path('accounts/login/', include('django.contrib.auth.urls')),
path('control/', AdminPageView.as_view(), name='control'), 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 # Django REST
urlpatterns += [ urlpatterns += [
path('api/', include(router.urls)) path('api/', include(router.urls))

View File

@ -132,6 +132,7 @@ extensions = {
'sphinx.ext.autodoc', 'sphinx.ext.autodoc',
'sphinx.ext.intersphinx', 'sphinx.ext.intersphinx',
'sphinx.ext.viewcode', 'sphinx.ext.viewcode',
'sphinx.ext.napoleon',
'sphinx_rtd_theme', 'sphinx_rtd_theme',
'sphinx.ext.graphviz', 'sphinx.ext.graphviz',
'sphinx.ext.inheritance_diagram', 'sphinx.ext.inheritance_diagram',
@ -205,3 +206,5 @@ set_type_checking_flag = True
typehints_fully_qualified = True typehints_fully_qualified = True
always_document_param_types = True always_document_param_types = True
typehints_document_rtype = True typehints_document_rtype = True
napoleon_attr_annotations = True

View File

@ -114,7 +114,7 @@ class ZendeskAdmin:
user = self.admin.users.search(email).values[0] user = self.admin.users.search(email).values[0]
return user.organization.name if user.organization else None return user.organization.name if user.organization else None
def create_admin(self) -> Zenpy: def create_admin(self) -> None:
""" """
Функция создает администратора, проверяя наличие вводимых данных в env. Функция создает администратора, проверяя наличие вводимых данных в env.
@ -141,7 +141,7 @@ class ZendeskAdmin:
raise ValueError('invalid access_controller`s login data') raise ValueError('invalid access_controller`s login data')
def update_role(user_profile: UserProfile, role: int) -> UserProfile: def update_role(user_profile: UserProfile, role: int) -> None:
""" """
Функция меняет роль пользователя. Функция меняет роль пользователя.
@ -157,7 +157,7 @@ def update_role(user_profile: UserProfile, role: int) -> UserProfile:
zendesk.admin.users.update(user) 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:
""" """
Функция устанавливает пользователю роль инженера. Функция устанавливает пользователю роль инженера.
@ -167,7 +167,7 @@ def make_engineer(user_profile: UserProfile, who_changes: User) -> UserProfile:
update_role(user_profile, ROLES['engineer']) 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:
""" """
Функция устанавливает пользователю роль легкого агента. Функция устанавливает пользователю роль легкого агента.

View File

@ -14,7 +14,7 @@ class CustomRegistrationForm(RegistrationFormUniqueEmail):
:type visible_fields.email: :class:`django_registration.forms.RegistrationFormUniqueEmail` :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) super().__init__(*args, **kwargs)
for visible in self.visible_fields(): for visible in self.visible_fields():
if visible.field.widget.attrs.get('class', False): if visible.field.widget.attrs.get('class', False):

View File

@ -1,7 +1,3 @@
import logging
import os
from datetime import datetime
from smtplib import SMTPException from smtplib import SMTPException
from django.contrib import messages from django.contrib import messages
@ -13,7 +9,6 @@ from django.contrib.auth.forms import PasswordResetForm
from django.contrib.auth.views import LoginView from django.contrib.auth.views import LoginView
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.contrib.messages.views import SuccessMessageMixin from django.contrib.messages.views import SuccessMessageMixin
from django.core.exceptions import PermissionDenied
from django.core.handlers.wsgi import WSGIRequest from django.core.handlers.wsgi import WSGIRequest
from django.http import HttpResponseRedirect, HttpResponse from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render, redirect, get_list_or_404 from django.shortcuts import render, redirect, get_list_or_404
@ -25,7 +20,7 @@ from rest_framework import viewsets
from rest_framework.response import Response from rest_framework.response import Response
from zenpy.lib.api_objects import User as ZenpyUser from zenpy.lib.api_objects import User as ZenpyUser
from access_controller.settings import EMAIL_HOST_USER, ZENDESK_ROLES, ZENDESK_MAX_AGENTS, ZENDESK_GROUPS 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, \ 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, \ make_engineer, make_light_agent, get_users_list, update_users_in_model, count_users, \
StatisticData, log, ZendeskAdmin StatisticData, log, ZendeskAdmin
@ -36,7 +31,6 @@ from .models import UserProfile
def setup_context(profile_lit: bool = False, control_lit: bool = False, work_lit: bool = False, def setup_context(profile_lit: bool = False, control_lit: bool = False, work_lit: bool = False,
registration_lit: bool = False, login_lit: bool = False): registration_lit: bool = False, login_lit: bool = False):
print(profile_lit, control_lit, work_lit, registration_lit, login_lit)
context = { context = {
'profile_lit': profile_lit, 'profile_lit': profile_lit,
'control_lit': control_lit, 'control_lit': control_lit,
@ -88,7 +82,7 @@ class CustomRegistrationView(RegistrationView):
opts = { opts = {
'use_https': self.request.is_secure(), 'use_https': self.request.is_secure(),
'token_generator': default_token_generator, 'token_generator': default_token_generator,
'from_email': EMAIL_HOST_USER, 'from_email': DEFAULT_FROM_EMAIL,
'email_template_name': 'registration/password_reset_email.html', 'email_template_name': 'registration/password_reset_email.html',
'subject_template_name': 'registration/password_reset_subject.txt', 'subject_template_name': 'registration/password_reset_subject.txt',
'request': self.request, 'request': self.request,
@ -205,23 +199,6 @@ def work_page(request: WSGIRequest, id: int) -> HttpResponse:
return redirect("login") 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.custom_role_id = zenpy_user.custom_role_id
request.user.userprofile.save()
messages.success(request, "Права были изменены")
@login_required() @login_required()
def work_hand_over(request: WSGIRequest) -> HttpResponseRedirect: def work_hand_over(request: WSGIRequest) -> HttpResponseRedirect:
""" """
@ -348,7 +325,6 @@ class AdminPageView(LoginRequiredMixin, PermissionRequiredMixin, SuccessMessageM
return context # TODO: need to get profile page url return context # TODO: need to get profile page url
class CustomLoginView(LoginView): class CustomLoginView(LoginView):
""" """
Отображение страницы авторизации пользователя Отображение страницы авторизации пользователя