2
.vscode/extensions.json
vendored
2
.vscode/extensions.json
vendored
@ -4,5 +4,7 @@
|
||||
"njpwerner.autodocstring",
|
||||
"streetsidesoftware.code-spell-checker-australian-english",
|
||||
"streetsidesoftware.code-spell-checker",
|
||||
"qwtel.sqlite-viewer",
|
||||
"jebbs.markdown-extended",
|
||||
]
|
||||
}
|
@ -35,6 +35,7 @@ class YourObject(TenancyObject):
|
||||
|
||||
```
|
||||
|
||||
|
||||
#### View Setup
|
||||
|
||||
``` python
|
||||
|
@ -24,10 +24,10 @@
|
||||
|
||||
{{ formset.non_form_errors.as_ul }}
|
||||
|
||||
<form action="{% url 'Access:_team' arg1=organization.id arg2=team.id as url %}" method="post">
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<input type="submit" value="Submit">
|
||||
<input type="button" value="delete Team" onclick="window.location='{% url 'Access:_team_delete' organization_id=organization_id pk=team.id %}';">
|
||||
<input type="button" value="delete Team" onclick="window.location='{% url 'Access:_team_delete' organization_id=organization.id pk=team.id %}';">
|
||||
|
||||
{{ formset.management_form }}
|
||||
|
||||
|
@ -26,7 +26,10 @@ from access.models import Organization, Team
|
||||
# )
|
||||
|
||||
|
||||
|
||||
######################################################################
|
||||
# SoF for loop for tests
|
||||
# for test in ['organization','team']
|
||||
######################################################################
|
||||
@pytest.mark.skip(reason="to be written")
|
||||
def test_authorization_organization_view(user):
|
||||
"""User of organization can view
|
||||
@ -95,3 +98,11 @@ def test_authorization_organization_object_no_delete(user):
|
||||
"""User not part of organization cant view organization object
|
||||
"""
|
||||
pass
|
||||
|
||||
######################################################################
|
||||
# EoF for loop for tests
|
||||
# for test in ['organization','team']
|
||||
######################################################################
|
||||
|
||||
# is_superuser to be able to view, add, change, delete for all objects
|
||||
|
||||
|
@ -1,14 +1,15 @@
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
from .views import team, organization
|
||||
|
||||
app_name = "Access"
|
||||
urlpatterns = [
|
||||
path("", views.IndexView.as_view(), name="Organizations"),
|
||||
path("<int:pk>/", views.OrganizationView.as_view(), name="_organization"),
|
||||
path("<int:pk>/edit", views.OrganizationChange.as_view(), name="_organization_change"),
|
||||
path("<int:organization_id>/team/<int:pk>/", views.TeamView.as_view(), name="_team"),
|
||||
path("<int:pk>/team/add", views.TeamAdd.as_view(), name="_team_add"),
|
||||
path("<int:organization_id>/team/<int:pk>/edit", views.TeamChange.as_view(), name="_team_change"),
|
||||
path("<int:organization_id>/team/<int:pk>/delete", views.TeamDelete.as_view(), name="_team_delete"),
|
||||
path("", organization.IndexView.as_view(), name="Organizations"),
|
||||
path("<int:pk>/", organization.View.as_view(), name="_organization"),
|
||||
path("<int:pk>/edit", organization.Change.as_view(), name="_organization_change"),
|
||||
path("<int:organization_id>/team/<int:pk>/", team.View.as_view(), name="_team"),
|
||||
path("<int:pk>/team/add", team.Add.as_view(), name="_team_add"),
|
||||
path("<int:organization_id>/team/<int:pk>/edit", team.Change.as_view(), name="_team_change"),
|
||||
path("<int:organization_id>/team/<int:pk>/delete", team.Delete.as_view(), name="_team_delete"),
|
||||
]
|
||||
|
@ -1,187 +0,0 @@
|
||||
from django.contrib.auth.decorators import permission_required
|
||||
from django.contrib.auth.models import User, Group, Permission
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin, LoginRequiredMixin
|
||||
from django.forms import inlineformset_factory
|
||||
from django.http import HttpResponseRedirect, request
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views import generic
|
||||
|
||||
from access.forms import TeamForm
|
||||
from access.models import *
|
||||
from access.mixin import *
|
||||
|
||||
|
||||
|
||||
class IndexView(PermissionRequiredMixin, OrganizationPermission, generic.ListView):
|
||||
permission_required = 'access.view_organization'
|
||||
template_name = 'access/index.html.j2'
|
||||
context_object_name = "organization_list"
|
||||
|
||||
|
||||
def get_queryset(self):
|
||||
|
||||
if self.request.user.is_superuser:
|
||||
|
||||
return Organization.objects.filter()
|
||||
|
||||
else:
|
||||
|
||||
return Organization.objects.filter(pk__in=self.user_organizations())
|
||||
|
||||
|
||||
|
||||
class OrganizationView(LoginRequiredMixin, OrganizationPermission, generic.UpdateView):
|
||||
model = Organization
|
||||
permission_required = 'access.view_organization'
|
||||
template_name = "access/organization.html.j2"
|
||||
fields = ["name", 'id']
|
||||
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
return f"/organization/{self.kwargs['pk']}/"
|
||||
|
||||
def get_queryset(self):
|
||||
|
||||
return Organization.objects.filter(pk=self.kwargs['pk'])
|
||||
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
organization = Organization.objects.get(pk=self.kwargs['pk'])
|
||||
|
||||
context['organization'] = organization
|
||||
|
||||
TeamsForm = inlineformset_factory(Organization, Team, fields=["team_name", 'id'], fk_name='organization', extra=1)
|
||||
formset = TeamsForm(instance=organization)
|
||||
|
||||
context['formset'] = formset
|
||||
|
||||
return context
|
||||
|
||||
|
||||
|
||||
class OrganizationChange(LoginRequiredMixin, OrganizationPermission, generic.DetailView):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class OrganizationDelete(LoginRequiredMixin, OrganizationPermission, generic.DetailView):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class TeamView(OrganizationPermission, generic.UpdateView):
|
||||
model = Team
|
||||
permission_required = 'access.view_team'
|
||||
template_name = 'access/team.html.j2'
|
||||
user = User
|
||||
|
||||
readonly_fields = ['team_name']
|
||||
|
||||
|
||||
def get(self, request, organization_id, pk):
|
||||
|
||||
team = Team.objects.get(pk=pk)
|
||||
|
||||
TeamForm = inlineformset_factory(Team, TeamUsers, fields=['id', 'user', 'manager'], fk_name='team', extra=1)
|
||||
|
||||
permissions = Permission.objects.filter()
|
||||
|
||||
formset = TeamForm(instance=team)
|
||||
|
||||
return render(request, self.template_name, {"formset": formset, "team": team, 'organization_id': organization_id, 'permissions': permissions})
|
||||
|
||||
|
||||
def post(self, request, organization_id, pk):
|
||||
team = Team.objects.get(pk=pk)
|
||||
TeamForm = inlineformset_factory(Team, TeamUsers, fields=['user'], fk_name='team', extra=1)
|
||||
|
||||
|
||||
formset = TeamForm(request.POST, request.FILES, instance=team)
|
||||
|
||||
if formset.is_valid():
|
||||
|
||||
formset.save()
|
||||
|
||||
return HttpResponseRedirect('#')
|
||||
|
||||
|
||||
return render(request, self.template_name, {"formset": formset, 'organization_id': organization_id, "team_id": pk, "team": team})
|
||||
|
||||
|
||||
class TeamAdd(OrganizationPermission, generic.CreateView):
|
||||
model = Team
|
||||
permission_required = 'access.add_team'
|
||||
template_name = 'form.html.j2'
|
||||
fields = [
|
||||
'team_name',
|
||||
]
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.organization = Organization.objects.get(pk=self.kwargs['pk'])
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
return f"/organization/{self.kwargs['pk']}/"
|
||||
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
context['content_title'] = 'Add Team'
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class TeamChange(OrganizationPermission, generic.UpdateView):
|
||||
model = Team
|
||||
permission_required = 'access.change_team'
|
||||
template_name = 'form.html.j2'
|
||||
fields = [
|
||||
'team_name',
|
||||
'permissions',
|
||||
'organization'
|
||||
]
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
return f"/organization/{self.kwargs['pk']}/"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
context['content_title'] = 'Edit Team'
|
||||
|
||||
return context
|
||||
|
||||
|
||||
|
||||
class TeamDelete(OrganizationPermission, generic.DeleteView):
|
||||
model = Team
|
||||
permission_required = 'access.delete_team'
|
||||
template_name = 'form.html.j2'
|
||||
fields = [
|
||||
'team_name',
|
||||
'permissions',
|
||||
'organization'
|
||||
]
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
return f"/organization/{self.kwargs['organization_id']}/"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
context['content_title'] = 'Delete Team'
|
||||
|
||||
return context
|
75
itsm/access/views/organization.py
Normal file
75
itsm/access/views/organization.py
Normal file
@ -0,0 +1,75 @@
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin, LoginRequiredMixin
|
||||
from django.forms import inlineformset_factory
|
||||
from django.views import generic
|
||||
|
||||
from access.forms import TeamForm
|
||||
from access.mixin import *
|
||||
from access.models import *
|
||||
|
||||
|
||||
|
||||
class IndexView(PermissionRequiredMixin, OrganizationPermission, generic.ListView):
|
||||
permission_required = 'access.view_organization'
|
||||
template_name = 'access/index.html.j2'
|
||||
context_object_name = "organization_list"
|
||||
|
||||
|
||||
def get_queryset(self):
|
||||
|
||||
if self.request.user.is_superuser:
|
||||
|
||||
return Organization.objects.filter()
|
||||
|
||||
else:
|
||||
|
||||
return Organization.objects.filter(pk__in=self.user_organizations())
|
||||
|
||||
|
||||
|
||||
class View(LoginRequiredMixin, OrganizationPermission, generic.UpdateView):
|
||||
model = Organization
|
||||
permission_required = 'access.view_organization'
|
||||
template_name = "access/organization.html.j2"
|
||||
fields = ["name", 'id']
|
||||
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
return f"/organization/{self.kwargs['pk']}/"
|
||||
|
||||
def get_queryset(self):
|
||||
|
||||
return Organization.objects.filter(pk=self.kwargs['pk'])
|
||||
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
organization = Organization.objects.get(pk=self.kwargs['pk'])
|
||||
|
||||
context['organization'] = organization
|
||||
|
||||
TeamsForm = inlineformset_factory(Organization, Team, fields=["team_name", 'id'], fk_name='organization', extra=1)
|
||||
formset = TeamsForm(instance=organization)
|
||||
|
||||
context['formset'] = formset
|
||||
|
||||
return context
|
||||
|
||||
|
||||
|
||||
class Change(LoginRequiredMixin, OrganizationPermission, generic.DetailView):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class Delete(LoginRequiredMixin, OrganizationPermission, generic.DetailView):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
127
itsm/access/views/team.py
Normal file
127
itsm/access/views/team.py
Normal file
@ -0,0 +1,127 @@
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin, LoginRequiredMixin
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.forms import inlineformset_factory
|
||||
from django.views import generic
|
||||
|
||||
from access.forms import TeamForm
|
||||
from access.models import Team, TeamUsers, Organization
|
||||
from access.mixin import *
|
||||
|
||||
|
||||
|
||||
class View(OrganizationPermission, generic.UpdateView):
|
||||
model = Team
|
||||
permission_required = 'access.view_team'
|
||||
template_name = 'access/team.html.j2'
|
||||
|
||||
fields = [
|
||||
"name",
|
||||
'id'
|
||||
]
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
organization = Organization.objects.get(pk=self.kwargs['organization_id'])
|
||||
|
||||
context['organization'] = organization
|
||||
|
||||
team = Team.objects.get(pk=self.kwargs['pk'])
|
||||
|
||||
TeamForm = inlineformset_factory(Team, TeamUsers, fields=['id', 'user', 'manager'], fk_name='team', extra=1)
|
||||
|
||||
formset = TeamForm(instance=team)
|
||||
|
||||
# {"formset": formset, "team": team, 'organization_id': organization_id, 'permissions': permissions}
|
||||
context['formset'] = formset
|
||||
context['permissions'] = permissions = Permission.objects.filter()
|
||||
|
||||
return context
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
return f"/organization/{self.kwargs['organization_id']}/team/{self.kwargs['pk']}/"
|
||||
|
||||
|
||||
|
||||
class Add(PermissionRequiredMixin, OrganizationPermission, generic.CreateView):
|
||||
model = Team
|
||||
permission_required = 'access.add_team'
|
||||
template_name = 'form.html.j2'
|
||||
fields = [
|
||||
'team_name',
|
||||
]
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.organization = Organization.objects.get(pk=self.kwargs['pk'])
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
return f"/organization/{self.kwargs['pk']}/"
|
||||
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
context['content_title'] = 'Add Team'
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class Change(PermissionRequiredMixin, OrganizationPermission, generic.UpdateView):
|
||||
model = Team
|
||||
permission_required = 'access.change_team'
|
||||
template_name = 'form.html.j2'
|
||||
fields = [
|
||||
'team_name',
|
||||
'permissions',
|
||||
'organization'
|
||||
]
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
return f"/organization/{self.kwargs['pk']}/"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
context['content_title'] = 'Edit Team'
|
||||
|
||||
return context
|
||||
|
||||
|
||||
|
||||
class Delete(PermissionRequiredMixin, OrganizationPermission, generic.DeleteView):
|
||||
model = Team
|
||||
permission_required = 'access.delete_team'
|
||||
template_name = 'form.html.j2'
|
||||
fields = [
|
||||
'team_name',
|
||||
'permissions',
|
||||
'organization'
|
||||
]
|
||||
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
return f"/organization/{self.kwargs['organization_id']}/"
|
||||
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
context['content_title'] = 'Delete Team'
|
||||
|
||||
return context
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user