Remove second argument from light_agent and make_engineer functions
This commit is contained in:
parent
cd1196efb2
commit
ab275fe3f8
@ -21,13 +21,12 @@ from main.models import UserProfile, RoleChangeLogs, UnassignedTicket, Unassigne
|
||||
from main.zendesk_admin import zenpy
|
||||
|
||||
|
||||
def update_role(user_profile: UserProfile, role: int, who_changes: User) -> None:
|
||||
def update_role(user_profile: UserProfile, role: int) -> None:
|
||||
"""
|
||||
Функция меняет роль пользователя.
|
||||
|
||||
:param user_profile: Профиль пользователя
|
||||
:param role: Новая роль
|
||||
:param who_changes: Пользователь, меняющий роль
|
||||
:return: Пользователь с обновленной ролью
|
||||
"""
|
||||
zendesk = zenpy
|
||||
@ -35,21 +34,21 @@ def update_role(user_profile: UserProfile, role: int, who_changes: User) -> None
|
||||
user.custom_role_id = role
|
||||
user_profile.custom_role_id = role
|
||||
user_profile.save()
|
||||
log(user_profile, who_changes.userprofile)
|
||||
log(user_profile)
|
||||
zendesk.admin.users.update(user)
|
||||
|
||||
|
||||
def make_engineer(user_profile: UserProfile, who_changes: User) -> None:
|
||||
def make_engineer(user_profile: UserProfile) -> None:
|
||||
"""
|
||||
Функция устанавливает пользователю роль инженера.
|
||||
|
||||
:param user_profile: Профиль пользователя
|
||||
:return: Вызов функции **update_role** с параметрами: профиль пользователя, роль "engineer"
|
||||
"""
|
||||
update_role(user_profile, ROLES['engineer'], who_changes)
|
||||
update_role(user_profile, ROLES['engineer'])
|
||||
|
||||
|
||||
def make_light_agent(user_profile: UserProfile, who_changes: User) -> None:
|
||||
def make_light_agent(user_profile: UserProfile) -> None:
|
||||
"""
|
||||
Функция устанавливает пользователю роль легкого агента.
|
||||
|
||||
@ -69,14 +68,13 @@ def make_light_agent(user_profile: UserProfile, who_changes: User) -> None:
|
||||
else:
|
||||
ticket.assignee = None
|
||||
ticket.group_id = zenpy.buffer_group_id
|
||||
|
||||
if tickets.count:
|
||||
zenpy.admin.tickets.update(tickets.values)
|
||||
|
||||
attempts, success = 5, False
|
||||
while not success and attempts != 0:
|
||||
try:
|
||||
update_role(user_profile, ROLES['light_agent'], who_changes)
|
||||
update_role(user_profile, ROLES['light_agent'])
|
||||
success = True
|
||||
except APIException as e:
|
||||
attempts -= 1
|
||||
|
@ -230,7 +230,7 @@ def work_hand_over(request: WSGIRequest) -> HttpResponseRedirect:
|
||||
:param request: данные текущего пользователя (login_required)
|
||||
:return: перезагрузка текущей страницы после выполнения смены роли
|
||||
"""
|
||||
make_light_agent(request.user.userprofile, request.user)
|
||||
make_light_agent(request.user.userprofile)
|
||||
return set_session_params_for_work_page(request)
|
||||
|
||||
|
||||
@ -243,7 +243,7 @@ def work_become_engineer(request: WSGIRequest) -> HttpResponseRedirect:
|
||||
:param request: данные текущего пользователя (login_required)
|
||||
:return: перезагрузка текущей страницы после выполнения смены роли
|
||||
"""
|
||||
make_engineer(request.user.userprofile, request.user)
|
||||
make_engineer(request.user.userprofile)
|
||||
return set_session_params_for_work_page(request)
|
||||
|
||||
|
||||
@ -317,7 +317,7 @@ class AdminPageView(LoginRequiredMixin, PermissionRequiredMixin, SuccessMessageM
|
||||
:return: Обновленный список пользователей
|
||||
"""
|
||||
for user in users:
|
||||
make_engineer(user, self.request.user)
|
||||
make_engineer(user)
|
||||
|
||||
def make_light_agents(self, users: list) -> None:
|
||||
"""
|
||||
@ -327,7 +327,7 @@ class AdminPageView(LoginRequiredMixin, PermissionRequiredMixin, SuccessMessageM
|
||||
:return: Обновленный список пользователей
|
||||
"""
|
||||
for user in users:
|
||||
make_light_agent(user, self.request.user)
|
||||
make_light_agent(user)
|
||||
|
||||
|
||||
class CustomLoginView(LoginView):
|
||||
|
Loading…
x
Reference in New Issue
Block a user