Added user list function
This commit is contained in:
parent
034c3eed70
commit
baf02cca44
@ -129,6 +129,6 @@ LOGIN_REDIRECT_URL = '/'
|
||||
LOGOUT_REDIRECT_URL = '/'
|
||||
|
||||
ZENDESK_ROLES = {
|
||||
'engineer': '360005209000',
|
||||
'light_agent': '360005208980',
|
||||
'engineer': 360005209000,
|
||||
'light_agent': 360005208980,
|
||||
}
|
||||
|
@ -127,6 +127,13 @@ def make_light_agent(user_profile):
|
||||
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):
|
||||
"""
|
||||
Функция обновляет профиль пользователя в соотвтетствии с текущим в Zendesk
|
||||
|
@ -27,30 +27,26 @@
|
||||
{{ field.tag }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div>
|
||||
<div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-10">
|
||||
<h6 class="table-title">Список сотрудников</h6>
|
||||
<table class="light-table">
|
||||
<thead>
|
||||
<th>ID</th>
|
||||
<th>Email</th>
|
||||
<th>Role</th>
|
||||
<th>Name(link to profile)</th>
|
||||
<th>Checked</th>
|
||||
<thead>
|
||||
<th>ID</th>
|
||||
<th>Email</th>
|
||||
<th>Role</th>
|
||||
<th>Name(link to profile)</th>
|
||||
<th>Checked</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for user in users %}
|
||||
<tr>
|
||||
<td>{{ user.id }}</td>
|
||||
<td>{{ user.user.email }}</td>
|
||||
<td>{{ user.role }}</td>
|
||||
<td><a href="#">{{ user.name }}</a></td>
|
||||
<td class="checkbox_field"></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% for user in users %}
|
||||
<tr>
|
||||
<td>{{ user.id }}</td>
|
||||
<td>{{ user.user.email }}</td>
|
||||
<td>{{ user.role }}</td>
|
||||
<td><a href="#">{{ user.name }}</a></td>
|
||||
<td class="checkbox_field"></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@ -62,20 +58,20 @@
|
||||
<div class="info-target">Инженеров:</div>
|
||||
<div class="info-quantity">
|
||||
<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 class="info-row">
|
||||
<div class="info-target">Легких агентов:</div>
|
||||
<div class="info-quantity">
|
||||
<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 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 type="submit" name="light_agent" class="hand-over-acess-button default-button">
|
||||
@ -96,7 +92,6 @@
|
||||
fields[i].appendChild(el);
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
|
@ -2,8 +2,8 @@ from django.core.exceptions import PermissionDenied
|
||||
from django.shortcuts import render, get_list_or_404
|
||||
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, make_engineer, make_light_agent
|
||||
from main.extra_func import check_user_exist, check_user_auth, update_profile, \
|
||||
make_engineer, make_light_agent, get_users_list
|
||||
from main.models import UserProfile
|
||||
|
||||
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 zenpy import Zenpy
|
||||
from access_controller.settings import ZENDESK_ROLES
|
||||
|
||||
|
||||
class CustomRegistrationView(RegistrationView):
|
||||
@ -97,11 +98,21 @@ class AdminPageView(FormView, LoginRequiredMixin):
|
||||
for user in users:
|
||||
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
|
||||
if self.request.user.userprofile.role != 'admin':
|
||||
raise PermissionDenied
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['users'] = get_list_or_404(
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user