add userRol

This commit is contained in:
Cayo Puigdefabregas 2023-10-17 17:42:48 +02:00
parent d9ec205c4e
commit fcd1316872
36 changed files with 286 additions and 39 deletions

View File

@ -21,3 +21,5 @@ class RolForm(forms.ModelForm):
class ServiceForm(forms.ModelForm):
MANDATORY_FIELDS = ['domain', 'rol']
class UserRolForm(forms.ModelForm):
MANDATORY_FIELDS = ['service']

View File

@ -7,13 +7,19 @@ from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse_lazy
from django.contrib import messages
from idhub.models import Membership, Rol, Service
from idhub.models import Membership, Rol, Service, UserRol
from idhub.mixins import AdminView
from idhub.admin.forms import ProfileForm, MembershipForm, RolForm, ServiceForm
from idhub.admin.forms import (
ProfileForm,
MembershipForm,
RolForm,
ServiceForm,
UserRolForm
)
class AdminDashboardView(AdminView, TemplateView):
template_name = "idhub/admin_dashboard.html"
template_name = "idhub/admin/dashboard.html"
title = _('Dashboard')
subtitle = _('Success')
icon = 'bi bi-bell'
@ -45,7 +51,7 @@ class ImportExport(AdminView, TemplateView):
class AdminPeopleListView(People, TemplateView):
template_name = "idhub/admin_people.html"
template_name = "idhub/admin/people.html"
subtitle = _('People list')
icon = 'bi bi-person'
@ -58,7 +64,7 @@ class AdminPeopleListView(People, TemplateView):
class AdminPeopleView(People, TemplateView):
template_name = "idhub/admin_user.html"
template_name = "idhub/admin/user.html"
subtitle = _('User Profile')
icon = 'bi bi-person'
model = User
@ -109,14 +115,14 @@ class AdminPeopleDeleteView(AdminPeopleView):
return redirect('idhub:admin_people_list')
class AdminPeopleEditView(AdminPeopleView, UpdateView):
template_name = "idhub/admin_user_edit.html"
template_name = "idhub/admin/user_edit.html"
from_class = ProfileForm
fields = ('first_name', 'last_name', 'email', 'username')
success_url = reverse_lazy('idhub:admin_people_list')
class AdminPeopleRegisterView(People, CreateView):
template_name = "idhub/admin_people_register.html"
template_name = "idhub/admin/people_register.html"
subtitle = _('People Register')
icon = 'bi bi-person'
model = User
@ -133,7 +139,7 @@ class AdminPeopleRegisterView(People, CreateView):
class AdminPeopleMembershipRegisterView(People, CreateView):
template_name = "idhub/admin_people_membership_register.html"
template_name = "idhub/admin/people_membership_register.html"
subtitle = _('People add membership')
icon = 'bi bi-person'
model = Membership
@ -164,14 +170,14 @@ class AdminPeopleMembershipRegisterView(People, CreateView):
def get_success_url(self):
self.success_url = reverse_lazy(
'idhub:admin_people_edit',
'idhub:admin_people_rol_new',
kwargs={"pk": self.user.id}
)
return self.success_url
class AdminPeopleMembershipEditView(People, CreateView):
template_name = "idhub/admin_people_membership_register.html"
template_name = "idhub/admin/people_membership_register.html"
subtitle = _('People add membership')
icon = 'bi bi-person'
model = Membership
@ -209,8 +215,75 @@ class AdminPeopleMembershipDeleteView(AdminPeopleView):
return redirect('idhub:admin_people_edit', user.id)
class AdminPeopleRolRegisterView(People, CreateView):
template_name = "idhub/admin/people_rol_register.html"
subtitle = _('Add Rol to User')
icon = 'bi bi-person'
model = UserRol
from_class = UserRolForm
fields = ('service',)
def get(self, request, *args, **kwargs):
self.pk = kwargs['pk']
self.user = get_object_or_404(User, pk=self.pk)
return super().get(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
self.pk = kwargs['pk']
self.user = get_object_or_404(User, pk=self.pk)
return super().post(request, *args, **kwargs)
def get_form_kwargs(self):
self.object = self.model(user=self.user)
kwargs = super().get_form_kwargs()
return kwargs
def get_success_url(self):
self.success_url = reverse_lazy(
'idhub:admin_people_edit',
kwargs={"pk": self.user.id}
)
return self.success_url
class AdminPeopleRolEditView(People, CreateView):
template_name = "idhub/admin/people_rol_register.html"
subtitle = _('Edit Rol to User')
icon = 'bi bi-person'
model = UserRol
from_class = UserRolForm
fields = ('service',)
def get_form_kwargs(self):
pk = self.kwargs.get('pk')
if pk:
self.object = get_object_or_404(self.model, pk=pk)
kwargs = super().get_form_kwargs()
return kwargs
def get_success_url(self):
self.success_url = reverse_lazy(
'idhub:admin_people_edit',
kwargs={"pk": self.object.user.id}
)
return self.success_url
class AdminPeopleRolDeleteView(AdminPeopleView):
model = UserRol
def get(self, request, *args, **kwargs):
self.pk = kwargs['pk']
self.object = get_object_or_404(self.model, pk=self.pk)
user = self.object.user
self.object.delete()
return redirect('idhub:admin_people_edit', user.id)
class AdminRolesView(AccessControl):
template_name = "idhub/admin_roles.html"
template_name = "idhub/admin/roles.html"
subtitle = _('Roles Management')
icon = ''
@ -222,7 +295,7 @@ class AdminRolesView(AccessControl):
return context
class AdminRolRegisterView(AccessControl, CreateView):
template_name = "idhub/admin_rol_register.html"
template_name = "idhub/admin/rol_register.html"
subtitle = _('Add Rol')
icon = ''
model = Rol
@ -233,7 +306,7 @@ class AdminRolRegisterView(AccessControl, CreateView):
class AdminRolEditView(AccessControl, CreateView):
template_name = "idhub/admin_rol_register.html"
template_name = "idhub/admin/rol_register.html"
subtitle = _('Edit Rol')
icon = ''
model = Rol
@ -261,7 +334,7 @@ class AdminRolDeleteView(AccessControl):
class AdminServicesView(AccessControl):
template_name = "idhub/admin_services.html"
template_name = "idhub/admin/services.html"
subtitle = _('Service Management')
icon = ''
@ -273,7 +346,7 @@ class AdminServicesView(AccessControl):
return context
class AdminServiceRegisterView(AccessControl, CreateView):
template_name = "idhub/admin_service_register.html"
template_name = "idhub/admin/service_register.html"
subtitle = _('Add Service')
icon = ''
model = Service
@ -284,7 +357,7 @@ class AdminServiceRegisterView(AccessControl, CreateView):
class AdminServiceEditView(AccessControl, CreateView):
template_name = "idhub/admin_service_register.html"
template_name = "idhub/admin/service_register.html"
subtitle = _('Edit Service')
icon = ''
model = Service
@ -312,69 +385,69 @@ class AdminServiceDeleteView(AccessControl):
class AdminCredentialsView(Credentials):
template_name = "idhub/admin_credentials.html"
template_name = "idhub/admin/credentials.html"
subtitle = _('Credentials list')
icon = ''
class AdminIssueCredentialsView(Credentials):
template_name = "idhub/admin_issue_credentials.html"
template_name = "idhub/admin/issue_credentials.html"
subtitle = _('Issuance of Credentials')
icon = ''
class AdminRevokeCredentialsView(Credentials):
template_name = "idhub/admin_revoke_credentials.html"
template_name = "idhub/admin/revoke_credentials.html"
subtitle = _('Revoke Credentials')
icon = ''
class AdminWalletIdentitiesView(Credentials):
template_name = "idhub/admin_wallet_identities.html"
template_name = "idhub/admin/wallet_identities.html"
subtitle = _('Organization Identities (DID)')
icon = 'bi bi-patch-check-fill'
wallet = True
class AdminWalletCredentialsView(Credentials):
template_name = "idhub/admin_wallet_credentials.html"
template_name = "idhub/admin/wallet_credentials.html"
subtitle = _('Credentials')
icon = 'bi bi-patch-check-fill'
wallet = True
class AdminWalletConfigIssuesView(Credentials):
template_name = "idhub/admin_wallet_issues.html"
template_name = "idhub/admin/wallet_issues.html"
subtitle = _('Configure Issues')
icon = 'bi bi-patch-check-fill'
wallet = True
class AdminSchemesView(Schemes):
template_name = "idhub/admin_schemes.html"
template_name = "idhub/admin/schemes.html"
subtitle = _('Schemes List')
icon = ''
class AdminSchemesImportView(Schemes):
template_name = "idhub/admin_schemes_import.html"
template_name = "idhub/admin/schemes_import.html"
subtitle = _('Import Schemes')
icon = ''
class AdminSchemesExportView(Schemes):
template_name = "idhub/admin_schemes_export.html"
template_name = "idhub/admin/schemes_export.html"
subtitle = _('Export Schemes')
icon = ''
class AdminImportView(ImportExport):
template_name = "idhub/admin_import.html"
template_name = "idhub/admin/import.html"
subtitle = _('Import')
icon = ''
class AdminExportView(ImportExport):
template_name = "idhub/admin_export.html"
template_name = "idhub/admin/export.html"
subtitle = _('Export')
icon = ''

View File

@ -0,0 +1,45 @@
# Generated by Django 4.2.5 on 2023-10-17 14:24
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("idhub", "0003_service"),
]
operations = [
migrations.CreateModel(
name="UserRol",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"service",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="users",
to="idhub.service",
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="roles",
to=settings.AUTH_USER_MODEL,
),
),
],
),
]

View File

@ -97,3 +97,19 @@ class Service(models.Model):
on_delete=models.CASCADE,
related_name='services',
)
def __str__(self):
return "{} -> {}".format(self.domain, self.rol.name)
class UserRol(models.Model):
user = models.ForeignKey(
User,
on_delete=models.CASCADE,
related_name='roles',
)
service = models.ForeignKey(
Service,
on_delete=models.CASCADE,
related_name='users',
)

View File

@ -13,8 +13,8 @@
<th scope="col"><button type="button" class="btn btn-green-admin border border-dark">{% trans 'Last name' %}</button></th>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'First name' %}</button></th>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">Username</button></th>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Role' %}</button></th>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Membership' %}</button></th>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Role' %}</button></th>
<th scope="col"></th>
</tr>
</thead>
@ -24,8 +24,16 @@
<td>{{ user.last_name }}</td>
<td>{{ user.first_name }}</td>
<td>{{ user.username }}</td>
<td>{{ user.get_membership }}</td>
<td>{{ user.get_role }}</td>
<td>
{% for m in user.memberships.all %}
{{ m.get_type }}
{% endfor %}
</td>
<td>
{% for r in user.roles.all %}
{{ r.service.rol.name }}
{% endfor %}
</td>
<td><a type="button" class="btn btn-green-admin rounded-pill" href="{% url 'idhub:admin_people' user.id %}">{% trans 'View' %}</td>
</tr>
{% endfor %}

View File

@ -26,7 +26,7 @@
</div>
</div>
<div class="form-actions-no-box">
<a class="btn btn-grey" href="{% url 'idhub:admin_people_list' %}">{% translate "Cancel" %}</a>
<a class="btn btn-grey" href="{% url 'idhub:admin_people_edit' form.instance.user.id %}">{% translate "Cancel" %}</a>
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
</div>

View File

@ -0,0 +1,34 @@
{% extends "idhub/base_admin.html" %}
{% load i18n %}
{% block content %}
<h3>
<i class="{{ icon }}"></i>
{{ subtitle }}
</h3>
{% load django_bootstrap5 %}
<form role="form" method="post">
{% csrf_token %}
{% if form.errors %}
<div class="alert alert-danger alert-icon alert-icon-border alert-dismissible" role="alert">
<div class="icon"><span class="mdi mdi-close-circle-o"></span></div>
<div class="message">
{% for field, error in form.errors.items %}
{{ error }}<br />
{% endfor %}
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
</div>
</div>
{% endif %}
<div class="row">
<div class="col-sm-4">
{% bootstrap_form form %}
</div>
</div>
<div class="form-actions-no-box">
<a class="btn btn-grey" href="{% url 'idhub:admin_people_edit' form.instance.user.id %}">{% translate "Cancel" %}</a>
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
</div>
</form>
{% endblock %}

View File

@ -47,6 +47,9 @@
</div>
</div>
</div>
<hr />
<div class="row">
<div class="col">
<div class="table-responsive">
@ -72,6 +75,32 @@
</div>
</div>
<div class="row mt-5">
<div class="col">
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Rol' %}</button></th>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Description' %}</button></th>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Service' %}</button></th>
</tr>
</thead>
<tbody>
{% for rol in object.roles.all %}
<tr>
<td>{{ rol.service.rol.name }}</td>
<td>{{ rol.service.description }}</td>
<td>{{ rol.service.domain }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal" id="confirm-delete" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">

View File

@ -30,6 +30,8 @@
</form>
<hr />
<div class="row mt-5">
<div class="col">
<div class="table-responsive">
@ -61,4 +63,36 @@
</div>
</div>
</div>
<div class="row mt-5 mb-3">
<div class="col">
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Rol' %}</button></th>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Description' %}</button></th>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Service' %}</button></th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
{% for rol in object.roles.all %}
<tr>
<td>{{ rol.service.rol.name }}</td>
<td>{{ rol.service.description }}</td>
<td>{{ rol.service.domain }}</td>
<td><a href="{% url 'idhub:admin_people_rol_edit' rol.id %}" title="{% trans 'Edit' %}"><i class="bi bi-pencil-square"></i></a></td>
<td><a href="{% url 'idhub:admin_people_rol_del' rol.id %}" title="{% trans 'Delete' %}"><i class="bi bi-trash"></i></a></td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="form-actions-no-box">
<a class="btn btn-green-admin" href="{% url 'idhub:admin_people_rol_new' object.id %}">{% translate "Add Rol" %} <i class="bi bi-plus"></i></a>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -70,6 +70,12 @@ urlpatterns = [
name='admin_people_membership_edit'),
path('admin/membership/<int:pk>/del/', views_admin.AdminPeopleMembershipDeleteView.as_view(),
name='admin_people_membership_del'),
path('admin/people/<int:pk>/rol/new/', views_admin.AdminPeopleRolRegisterView.as_view(),
name='admin_people_rol_new'),
path('admin/people/<int:pk>/rol/edit/', views_admin.AdminPeopleRolEditView.as_view(),
name='admin_people_rol_edit'),
path('admin/people/<int:pk>/rol/del/', views_admin.AdminPeopleRolDeleteView.as_view(),
name='admin_people_rol_del'),
path('admin/roles/', views_admin.AdminRolesView.as_view(),
name='admin_roles'),
path('admin/roles/new', views_admin.AdminRolRegisterView.as_view(),

View File

@ -20,7 +20,7 @@ class MyWallet(UserView, TemplateView):
class UserDashboardView(UserView, TemplateView):
template_name = "idhub/user_dashboard.html"
template_name = "idhub/user/dashboard.html"
title = _('Dashboard')
subtitle = _('Success')
icon = 'bi bi-bell'
@ -28,7 +28,7 @@ class UserDashboardView(UserView, TemplateView):
class UserProfileView(MyProfile, UpdateView):
template_name = "idhub/user_profile.html"
template_name = "idhub/user/profile.html"
subtitle = _('My personal Data')
icon = 'bi bi-person'
from_class = ProfileForm
@ -40,36 +40,36 @@ class UserProfileView(MyProfile, UpdateView):
class UserRolesView(MyProfile, TemplateView):
template_name = "idhub/user_roles.html"
template_name = "idhub/user/roles.html"
subtitle = _('My roles')
icon = 'fa-brands fa-critical-role'
class UserGDPRView(MyProfile, TemplateView):
template_name = "idhub/user_gdpr.html"
template_name = "idhub/user/gdpr.html"
subtitle = _('GDPR info')
icon = 'bi bi-file-earmark-medical'
class UserIdentitiesView(MyWallet):
template_name = "idhub/user_identities.html"
template_name = "idhub/user/identities.html"
subtitle = _('Identities (DID)')
icon = 'bi bi-patch-check-fill'
class UserCredentialsView(MyWallet):
template_name = "idhub/user_credentials.html"
template_name = "idhub/user/credentials.html"
subtitle = _('Credentials')
icon = 'bi bi-patch-check-fill'
class UserCredentialsRequiredView(MyWallet):
template_name = "idhub/user_credentials_required.html"
template_name = "idhub/user/credentials_required.html"
subtitle = _('Credentials required')
icon = 'bi bi-patch-check-fill'
class UserCredentialsPresentationView(MyWallet):
template_name = "idhub/user_credentials_presentation.html"
template_name = "idhub/user/credentials_presentation.html"
subtitle = _('Credentials Presentation')
icon = 'bi bi-patch-check-fill'