show all groups on one site
This commit is contained in:
parent
0bc56731f9
commit
174d02d26b
|
@ -31,14 +31,10 @@ class CustomersTable(CoreTable):
|
|||
text='Users',
|
||||
args=[A('pk')],
|
||||
orderable=False)
|
||||
ad_groups = tables.LinkColumn('ad_groups',
|
||||
text='AD Groups',
|
||||
args=[A('pk')],
|
||||
orderable=False)
|
||||
mail_groups = tables.LinkColumn('mail_groups',
|
||||
text='Mail Groups',
|
||||
args=[A('pk')],
|
||||
orderable=False)
|
||||
groups = tables.LinkColumn('groups',
|
||||
text='Groups',
|
||||
args=[A('pk')],
|
||||
orderable=False)
|
||||
delete = tables.LinkColumn('customer_delete',
|
||||
text='delete',
|
||||
args=[A('pk')], attrs={
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
from django.db import models
|
||||
|
||||
from model_utils.managers import InheritanceManager
|
||||
|
||||
from customers.models import Customer
|
||||
|
||||
|
||||
|
@ -6,6 +9,8 @@ class Group(models.Model):
|
|||
name = models.CharField(max_length=50)
|
||||
customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
|
||||
|
||||
objects = InheritanceManager()
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
|
|
@ -33,9 +33,9 @@ class UsersTable(CoreTable):
|
|||
|
||||
class AdGroupsTable(CoreTable):
|
||||
id = tables.Column(visible=False)
|
||||
name = tables.Column('AdGroup', linkify=True)
|
||||
customer = tables.Column('Customer', linkify=True)
|
||||
delete = tables.LinkColumn('ad_group_delete',
|
||||
name = tables.Column('Ad Groups', linkify=True)
|
||||
customer = tables.Column(visible=False)
|
||||
action = tables.LinkColumn('ad_group_delete',
|
||||
text='delete',
|
||||
args=[A('pk')], attrs={
|
||||
'a': {'class': 'delete material-icons', }
|
||||
|
@ -47,9 +47,10 @@ class AdGroupsTable(CoreTable):
|
|||
|
||||
class MailGroupsTable(CoreTable):
|
||||
id = tables.Column(visible=False)
|
||||
name = tables.Column('MailGroup', linkify=True)
|
||||
customer = tables.Column('Customer', linkify=True)
|
||||
delete = tables.LinkColumn('mail_group_delete',
|
||||
name = tables.Column('Mail Groups', linkify=True)
|
||||
mail_address = tables.EmailColumn(verbose_name='Mail Address')
|
||||
customer = tables.Column(visible=False)
|
||||
action = tables.LinkColumn('mail_group_delete',
|
||||
text='delete',
|
||||
args=[A('pk')], attrs={
|
||||
'a': {'class': 'delete material-icons', }
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
{% extends "core/base.html" %}
|
||||
{% load render_table from django_tables2 %}
|
||||
{% block section_title %}Groups{% endblock %}
|
||||
{% block section_title %}{{ customer }} Groups{% endblock %}
|
||||
{% block content %}
|
||||
<div class="table-responsive">
|
||||
{% render_table groups %}
|
||||
{% render_table ad_groups %}
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
{% render_table mail_groups %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -10,7 +10,7 @@ pytestmark = pytest.mark.django_db
|
|||
|
||||
|
||||
def test_customer_ad_group_table_not_logged_in():
|
||||
response = Client().get('/customer/1/ad-groups/')
|
||||
response = Client().get('/customer/1/groups/')
|
||||
assert response.status_code == 302 and 'login' in response.url
|
||||
|
||||
|
||||
|
@ -20,7 +20,7 @@ def test_customer_ad_group_table(create_admin_user):
|
|||
client = Client()
|
||||
client.login(username="pharma-admin", password="password")
|
||||
ad_group = mixer.blend('users.AdGroup', customer=customer)
|
||||
response = client.get('/customer/' + str(customer.id) + '/ad-groups/')
|
||||
response = client.get('/customer/' + str(customer.id) + '/groups/')
|
||||
assert (response.status_code == 200
|
||||
and helper.in_content(response, ad_group))
|
||||
|
||||
|
@ -30,9 +30,8 @@ def test_customer_ad_group_table_no_group(create_admin_user):
|
|||
customer = fixture['customer']
|
||||
client = Client()
|
||||
client.login(username="pharma-admin", password="password")
|
||||
response = client.get('/customer/' + str(customer.id) + '/ad-groups/')
|
||||
assert (response.status_code == 200
|
||||
and helper.not_in_content(response, customer))
|
||||
response = client.get('/customer/' + str(customer.id) + '/groups/')
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_customer_ad_group_table_no_permission(create_admin_user):
|
||||
|
@ -41,8 +40,8 @@ def test_customer_ad_group_table_no_permission(create_admin_user):
|
|||
client = Client()
|
||||
client.login(username="pharma-admin", password="password")
|
||||
mixer.blend('users.AdGroup', customer=customer)
|
||||
response = client.get('/customer/' + str(customer.id) + '/ad-groups/')
|
||||
assert response.status_code == 404
|
||||
response = client.get('/customer/' + str(customer.id) + '/groups/')
|
||||
assert response.status_code == 403
|
||||
|
||||
|
||||
def test_customer_ad_group_table_multiple_groups(create_admin_user):
|
||||
|
@ -52,7 +51,7 @@ def test_customer_ad_group_table_multiple_groups(create_admin_user):
|
|||
client.login(username="pharma-admin", password="password")
|
||||
group1 = mixer.blend('users.AdGroup', customer=mixer.SELECT)
|
||||
group2 = mixer.blend('users.AdGroup', customer=mixer.SELECT)
|
||||
response = client.get('/customer/' + str(customer.id) + '/ad-groups/')
|
||||
response = client.get('/customer/' + str(customer.id) + '/groups/')
|
||||
assert (response.status_code == 200
|
||||
and helper.in_content(response, group1.name)
|
||||
and helper.in_content(response, group2.name))
|
||||
|
|
|
@ -10,7 +10,7 @@ pytestmark = pytest.mark.django_db
|
|||
|
||||
|
||||
def test_customer_mail_group_table_not_logged_in():
|
||||
response = Client().get('/customer/1/mail-groups/')
|
||||
response = Client().get('/customer/1/groups/')
|
||||
assert response.status_code == 302 and 'login' in response.url
|
||||
|
||||
|
||||
|
@ -20,7 +20,7 @@ def test_customer_mail_group_table(create_admin_user):
|
|||
client = Client()
|
||||
client.login(username="pharma-admin", password="password")
|
||||
mail_group = mixer.blend('users.MailGroup', customer=customer)
|
||||
response = client.get('/customer/' + str(customer.id) + '/mail-groups/')
|
||||
response = client.get('/customer/' + str(customer.id) + '/groups/')
|
||||
assert (response.status_code == 200
|
||||
and helper.in_content(response, mail_group))
|
||||
|
||||
|
@ -30,9 +30,8 @@ def test_customer_mail_group_table_no_group(create_admin_user):
|
|||
customer = fixture['customer']
|
||||
client = Client()
|
||||
client.login(username="pharma-admin", password="password")
|
||||
response = client.get('/customer/' + str(customer.id) + '/mail-groups/')
|
||||
assert (response.status_code == 200
|
||||
and helper.not_in_content(response, customer))
|
||||
response = client.get('/customer/' + str(customer.id) + '/groups/')
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_customer_mail_group_table_no_permission(create_admin_user):
|
||||
|
@ -41,8 +40,8 @@ def test_customer_mail_group_table_no_permission(create_admin_user):
|
|||
client = Client()
|
||||
client.login(username="pharma-admin", password="password")
|
||||
mixer.blend('users.MailGroup', customer=customer)
|
||||
response = client.get('/customer/' + str(customer.id) + '/mail-groups/')
|
||||
assert response.status_code == 404
|
||||
response = client.get('/customer/' + str(customer.id) + '/groups/')
|
||||
assert response.status_code == 403
|
||||
|
||||
|
||||
def test_customer_mail_group_table_multiple_groups(create_admin_user):
|
||||
|
@ -52,7 +51,7 @@ def test_customer_mail_group_table_multiple_groups(create_admin_user):
|
|||
client.login(username="pharma-admin", password="password")
|
||||
group1 = mixer.blend('users.MailGroup', customer=mixer.SELECT)
|
||||
group2 = mixer.blend('users.MailGroup', customer=mixer.SELECT)
|
||||
response = client.get('/customer/' + str(customer.id) + '/mail-groups/')
|
||||
response = client.get('/customer/' + str(customer.id) + '/groups/')
|
||||
assert (response.status_code == 200
|
||||
and helper.in_content(response, group1.name)
|
||||
and helper.in_content(response, group2.name))
|
||||
|
|
|
@ -3,12 +3,11 @@ from django.urls import path
|
|||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('customer/<int:pk>/ad-groups/', views.ad_groups_table_view,
|
||||
name='ad_groups'),
|
||||
path('customer/<int:pk>/mail-groups/', views.mail_groups_table_view,
|
||||
name='mail_groups'),
|
||||
path('customer/<int:pk>/groups/', views.groups_table_view,
|
||||
name='groups'),
|
||||
path('ad-group/<int:pk>/', views.ad_group_detail_view, name='ad_group'),
|
||||
path('mail-group/<int:pk>/', views.mail_group_detail_view, name='mail_group'),
|
||||
path('mail-group/<int:pk>/', views.mail_group_detail_view,
|
||||
name='mail_group'),
|
||||
path('delete/ad-group/<int:pk>/', views.delete_ad_group,
|
||||
name='ad_group_delete'),
|
||||
path('delete/mail-group/<int:pk>/', views.delete_mail_group,
|
||||
|
|
|
@ -11,6 +11,7 @@ from django_tables2 import RequestConfig
|
|||
|
||||
from core import utils
|
||||
from customers.decorators import customer_view_permission
|
||||
from customers.models import Customer
|
||||
from computers.models import Computer
|
||||
from licenses.models import LicenseWithUser
|
||||
|
||||
|
@ -60,14 +61,25 @@ class UserDeleteView(LoginRequiredMixin, DeleteView):
|
|||
|
||||
|
||||
@login_required
|
||||
def ad_groups_table_view(request, pk):
|
||||
table = AdGroupsTable(utils.get_objects_for_customer(AdGroup,
|
||||
user=request.user,
|
||||
customer_pk=pk))
|
||||
RequestConfig(request).configure(table)
|
||||
@customer_view_permission
|
||||
def groups_table_view(request, pk):
|
||||
customer = get_object_or_404(Customer, pk=pk)
|
||||
ad_groups_table = AdGroupsTable(
|
||||
utils.get_objects_for_customer(AdGroup,
|
||||
user=request.user,
|
||||
customer_pk=pk))
|
||||
RequestConfig(request).configure(ad_groups_table)
|
||||
|
||||
mail_groups_table = MailGroupsTable(
|
||||
utils.get_objects_for_customer(MailGroup,
|
||||
user=request.user,
|
||||
customer_pk=pk))
|
||||
RequestConfig(request).configure(mail_groups_table)
|
||||
return TemplateResponse(request,
|
||||
'groups/group_list.html',
|
||||
{'groups': table})
|
||||
{'customer': customer.name,
|
||||
'ad_groups': ad_groups_table,
|
||||
'mail_groups': mail_groups_table})
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -79,17 +91,6 @@ def ad_group_detail_view(request, pk):
|
|||
{'group': group})
|
||||
|
||||
|
||||
@login_required
|
||||
def mail_groups_table_view(request, pk):
|
||||
table = MailGroupsTable(utils.get_objects_for_customer(MailGroup,
|
||||
user=request.user,
|
||||
customer_pk=pk))
|
||||
RequestConfig(request).configure(table)
|
||||
return TemplateResponse(request,
|
||||
'groups/group_list.html',
|
||||
{'groups': table})
|
||||
|
||||
|
||||
@login_required
|
||||
def mail_group_detail_view(request, pk):
|
||||
group = utils.get_object_with_view_permission(MailGroup,
|
||||
|
|
Loading…
Reference in New Issue