add multiselect for roles in services

This commit is contained in:
Cayo Puigdefabregas 2023-10-19 15:20:06 +02:00
parent 88675bc807
commit acad550dd0
7 changed files with 31 additions and 7 deletions

View File

@ -1,5 +1,6 @@
from django import forms from django import forms
from django.contrib.auth.models import User from django.contrib.auth.models import User
from idhub.models import Rol
class ProfileForm(forms.ModelForm): class ProfileForm(forms.ModelForm):
@ -21,5 +22,6 @@ class RolForm(forms.ModelForm):
class ServiceForm(forms.ModelForm): class ServiceForm(forms.ModelForm):
MANDATORY_FIELDS = ['domain', 'rol'] MANDATORY_FIELDS = ['domain', 'rol']
class UserRolForm(forms.ModelForm): class UserRolForm(forms.ModelForm):
MANDATORY_FIELDS = ['service'] MANDATORY_FIELDS = ['service']

View File

@ -0,0 +1,21 @@
# Generated by Django 4.2.5 on 2023-10-19 13:01
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("idhub", "0004_userrol"),
]
operations = [
migrations.RemoveField(
model_name="service",
name="rol",
),
migrations.AddField(
model_name="service",
name="rol",
field=models.ManyToManyField(to="idhub.rol"),
),
]

View File

@ -92,12 +92,13 @@ class Rol(models.Model):
class Service(models.Model): class Service(models.Model):
domain = models.CharField(max_length=250) domain = models.CharField(max_length=250)
description = models.CharField(max_length=250) description = models.CharField(max_length=250)
rol = models.ForeignKey( rol = models.ManyToManyField(
Rol, Rol,
on_delete=models.CASCADE,
related_name='services',
) )
def get_roles(self):
return ", ".join([x.name for x in self.rol.all()])
def __str__(self): def __str__(self):
return "{} -> {}".format(self.domain, self.rol.name) return "{} -> {}".format(self.domain, self.rol.name)

View File

@ -31,7 +31,7 @@
</td> </td>
<td> <td>
{% for r in user.roles.all %} {% for r in user.roles.all %}
{{ r.service.rol.name }} {{ r.service.get_roles }}
{% endfor %} {% endfor %}
</td> </td>
<td><a type="button" class="btn btn-green-admin rounded-pill" href="{% url 'idhub:admin_people' user.id %}">{% trans 'View' %}</td> <td><a type="button" class="btn btn-green-admin rounded-pill" href="{% url 'idhub:admin_people' user.id %}">{% trans 'View' %}</td>

View File

@ -24,7 +24,7 @@
<tr> <tr>
<td>{{ service.domain }}</td> <td>{{ service.domain }}</td>
<td>{{ service.description }}</td> <td>{{ service.description }}</td>
<td>{{ service.rol.name }}</td> <td>{{ service.get_roles }}</td>
<td><a href="{% url 'idhub:admin_service_edit' service.id %}" title="{% trans 'Edit' %}"><i class="bi bi-pencil-square"></i></a></td> <td><a href="{% url 'idhub:admin_service_edit' service.id %}" title="{% trans 'Edit' %}"><i class="bi bi-pencil-square"></i></a></td>
<td><a href="{% url 'idhub:admin_service_del' service.id %}" title="{% trans 'Delete' %}"><i class="bi bi-trash"></i></a></td> <td><a href="{% url 'idhub:admin_service_del' service.id %}" title="{% trans 'Delete' %}"><i class="bi bi-trash"></i></a></td>
</tr> </tr>

View File

@ -92,7 +92,7 @@
<tbody> <tbody>
{% for rol in object.roles.all %} {% for rol in object.roles.all %}
<tr> <tr>
<td>{{ rol.service.rol.name }}</td> <td>{{ rol.service.get_roles }}</td>
<td>{{ rol.service.description }}</td> <td>{{ rol.service.description }}</td>
<td>{{ rol.service.domain }}</td> <td>{{ rol.service.domain }}</td>
</tr> </tr>

View File

@ -80,7 +80,7 @@
<tbody> <tbody>
{% for rol in object.roles.all %} {% for rol in object.roles.all %}
<tr> <tr>
<td>{{ rol.service.rol.name }}</td> <td>{{ rol.service.get_roles }}</td>
<td>{{ rol.service.description }}</td> <td>{{ rol.service.description }}</td>
<td>{{ rol.service.domain }}</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_edit' rol.id %}" title="{% trans 'Edit' %}"><i class="bi bi-pencil-square"></i></a></td>