Added user list function
This commit is contained in:
parent
034c3eed70
commit
baf02cca44
@ -129,6 +129,6 @@ LOGIN_REDIRECT_URL = '/'
|
|||||||
LOGOUT_REDIRECT_URL = '/'
|
LOGOUT_REDIRECT_URL = '/'
|
||||||
|
|
||||||
ZENDESK_ROLES = {
|
ZENDESK_ROLES = {
|
||||||
'engineer': '360005209000',
|
'engineer': 360005209000,
|
||||||
'light_agent': '360005208980',
|
'light_agent': 360005208980,
|
||||||
}
|
}
|
||||||
|
@ -127,6 +127,13 @@ def make_light_agent(user_profile):
|
|||||||
zendesk.admin.users.update(user)
|
zendesk.admin.users.update(user)
|
||||||
|
|
||||||
|
|
||||||
|
def get_users_list():
|
||||||
|
zendesk = ZendeskAdmin()
|
||||||
|
admin = zendesk.get_user(zendesk.email)
|
||||||
|
group = next(zendesk.admin.users.groups(user=admin)) # TODO: user can be in many groups
|
||||||
|
return zendesk.admin.groups.users(group) # TODO: add role parameter
|
||||||
|
|
||||||
|
|
||||||
def update_profile(user_profile: UserProfile):
|
def update_profile(user_profile: UserProfile):
|
||||||
"""
|
"""
|
||||||
Функция обновляет профиль пользователя в соотвтетствии с текущим в Zendesk
|
Функция обновляет профиль пользователя в соотвтетствии с текущим в Zendesk
|
||||||
|
@ -27,30 +27,26 @@
|
|||||||
{{ field.tag }}
|
{{ field.tag }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
<div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-10">
|
<div class="col-10">
|
||||||
<h6 class="table-title">Список сотрудников</h6>
|
<h6 class="table-title">Список сотрудников</h6>
|
||||||
<table class="light-table">
|
<table class="light-table">
|
||||||
<thead>
|
<thead>
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
<th>Email</th>
|
<th>Email</th>
|
||||||
<th>Role</th>
|
<th>Role</th>
|
||||||
<th>Name(link to profile)</th>
|
<th>Name(link to profile)</th>
|
||||||
<th>Checked</th>
|
<th>Checked</th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for user in users %}
|
{% for user in users %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ user.id }}</td>
|
<td>{{ user.id }}</td>
|
||||||
<td>{{ user.user.email }}</td>
|
<td>{{ user.user.email }}</td>
|
||||||
<td>{{ user.role }}</td>
|
<td>{{ user.role }}</td>
|
||||||
<td><a href="#">{{ user.name }}</a></td>
|
<td><a href="#">{{ user.name }}</a></td>
|
||||||
<td class="checkbox_field"></td>
|
<td class="checkbox_field"></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
@ -62,20 +58,20 @@
|
|||||||
<div class="info-target">Инженеров:</div>
|
<div class="info-target">Инженеров:</div>
|
||||||
<div class="info-quantity">
|
<div class="info-quantity">
|
||||||
<div class="status-circle-small light-green"></div>
|
<div class="status-circle-small light-green"></div>
|
||||||
<span class="info-quantity-value">13</span>
|
<span class="info-quantity-value">{{ engineers }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="info-row">
|
<div class="info-row">
|
||||||
<div class="info-target">Легких агентов:</div>
|
<div class="info-target">Легких агентов:</div>
|
||||||
<div class="info-quantity">
|
<div class="info-quantity">
|
||||||
<div class="status-circle-small light-yellow"></div>
|
<div class="status-circle-small light-yellow"></div>
|
||||||
<span class="info-quantity-value">22</span>
|
<span class="info-quantity-value">{{ light_agents }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-5">
|
<div class="col-5">
|
||||||
<button type="submit" name="engineer" class="request-acess-button default-button">
|
<button type="submit" name="engineer" class="request-acess-button default-button">
|
||||||
Назначить выбранных на роль инженера
|
Назначить выбранных на роль инженера
|
||||||
</button>
|
</button>
|
||||||
<button type="submit" name="light_agent" class="hand-over-acess-button default-button">
|
<button type="submit" name="light_agent" class="hand-over-acess-button default-button">
|
||||||
@ -96,7 +92,6 @@
|
|||||||
fields[i].appendChild(el);
|
fields[i].appendChild(el);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -2,8 +2,8 @@ from django.core.exceptions import PermissionDenied
|
|||||||
from django.shortcuts import render, get_list_or_404
|
from django.shortcuts import render, get_list_or_404
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
|
|
||||||
from main.apiauth import api_auth
|
from main.extra_func import check_user_exist, check_user_auth, update_profile, \
|
||||||
from main.extra_func import check_user_exist, check_user_auth, update_profile, make_engineer, make_light_agent
|
make_engineer, make_light_agent, get_users_list
|
||||||
from main.models import UserProfile
|
from main.models import UserProfile
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
@ -14,6 +14,7 @@ from django.contrib.auth.decorators import login_required
|
|||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
|
||||||
from zenpy import Zenpy
|
from zenpy import Zenpy
|
||||||
|
from access_controller.settings import ZENDESK_ROLES
|
||||||
|
|
||||||
|
|
||||||
class CustomRegistrationView(RegistrationView):
|
class CustomRegistrationView(RegistrationView):
|
||||||
@ -97,11 +98,21 @@ class AdminPageView(FormView, LoginRequiredMixin):
|
|||||||
for user in users:
|
for user in users:
|
||||||
make_light_agent(user)
|
make_light_agent(user)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def count_users(users): # TODO: this func counts users from all zendesk instead of just from a model
|
||||||
|
engineers, light_agents = 0, 0
|
||||||
|
for user in users:
|
||||||
|
if user.custom_role_id == ZENDESK_ROLES['engineer']:
|
||||||
|
engineers += 1
|
||||||
|
elif user.custom_role_id == ZENDESK_ROLES['light_agent']:
|
||||||
|
light_agents += 1
|
||||||
|
return engineers, light_agents
|
||||||
|
|
||||||
def get_context_data(self, **kwargs): # TODO: add engineers and agents count
|
def get_context_data(self, **kwargs): # TODO: add engineers and agents count
|
||||||
if self.request.user.userprofile.role != 'admin':
|
if self.request.user.userprofile.role != 'admin':
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context['users'] = get_list_or_404(
|
context['users'] = get_list_or_404(
|
||||||
UserProfile, role='agent')
|
UserProfile, role='agent')
|
||||||
context['engineers'] = get_list_or_404(UserProfile, )
|
context['engineers'], context['light_agents'] = self.count_users(get_users_list())
|
||||||
return context # TODO: need to get profile page url
|
return context # TODO: need to get profile page url
|
||||||
|
Loading…
x
Reference in New Issue
Block a user