Browse Source

nuovo sistema gestione sicurezza

mauro 10 months ago
parent
commit
a5bdfb761f

+ 1 - 2
amministratore/admin.py

@@ -4,6 +4,5 @@ from .models import *
 # Register your models here.
 @admin.register(Amministratore)
 class AmministratoreAdmin(admin.ModelAdmin):
-  list_display = ['login','nome','pin','sola_lettura','crea_azienda','crea_sede','crea_utente','crea_documento','crea_comunicazione',
-                  'edit_azienda','edit_utente','edit_documento','edit_comunicazione',]
+  list_display = ['login','nome','pin','mail',]
 

+ 30 - 0
amministratore/migrations/0007_permesso_ap.py

@@ -0,0 +1,30 @@
+# Generated by Django 5.1.5 on 2025-02-04 11:18
+
+import django.db.models.deletion
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('amministratore', '0006_rename_vedi_permesso_amministratore_read_permesso'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Permesso',
+            fields=[
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('nome', models.CharField(max_length=20, null=True)),
+                ('descrizione', models.CharField(max_length=128, null=True)),
+            ],
+        ),
+        migrations.CreateModel(
+            name='AP',
+            fields=[
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('amministratore', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='amministratore.amministratore')),
+                ('Permesso', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='amministratore.permesso')),
+            ],
+        ),
+    ]

+ 18 - 0
amministratore/migrations/0008_rename_permesso_ap_permesso.py

@@ -0,0 +1,18 @@
+# Generated by Django 5.1.5 on 2025-02-04 11:28
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('amministratore', '0007_permesso_ap'),
+    ]
+
+    operations = [
+        migrations.RenameField(
+            model_name='ap',
+            old_name='Permesso',
+            new_name='permesso',
+        ),
+    ]

+ 73 - 0
amministratore/migrations/0009_remove_amministratore_crea_azienda_and_more.py

@@ -0,0 +1,73 @@
+# Generated by Django 5.1.5 on 2025-02-04 14:21
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('amministratore', '0008_rename_permesso_ap_permesso'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='amministratore',
+            name='crea_azienda',
+        ),
+        migrations.RemoveField(
+            model_name='amministratore',
+            name='crea_comunicazione',
+        ),
+        migrations.RemoveField(
+            model_name='amministratore',
+            name='crea_documento',
+        ),
+        migrations.RemoveField(
+            model_name='amministratore',
+            name='crea_permesso',
+        ),
+        migrations.RemoveField(
+            model_name='amministratore',
+            name='crea_sede',
+        ),
+        migrations.RemoveField(
+            model_name='amministratore',
+            name='crea_utente',
+        ),
+        migrations.RemoveField(
+            model_name='amministratore',
+            name='edit_azienda',
+        ),
+        migrations.RemoveField(
+            model_name='amministratore',
+            name='edit_comunicazione',
+        ),
+        migrations.RemoveField(
+            model_name='amministratore',
+            name='edit_documento',
+        ),
+        migrations.RemoveField(
+            model_name='amministratore',
+            name='edit_permesso',
+        ),
+        migrations.RemoveField(
+            model_name='amministratore',
+            name='edit_sede',
+        ),
+        migrations.RemoveField(
+            model_name='amministratore',
+            name='edit_utente',
+        ),
+        migrations.RemoveField(
+            model_name='amministratore',
+            name='read_permesso',
+        ),
+        migrations.RemoveField(
+            model_name='amministratore',
+            name='sola_lettura',
+        ),
+        migrations.RemoveField(
+            model_name='amministratore',
+            name='uuid',
+        ),
+    ]

+ 11 - 0
amministratore/models.py

@@ -6,6 +6,7 @@ class Amministratore(models.Model):
   nome = models.CharField(max_length=128,null=False,unique=True)
   mail = models.CharField(max_length=128,null=False,default="")
   pin = models.CharField(max_length=64,null=False)
+  '''
   uuid = models.CharField(max_length=32,null=False,default="")
   sola_lettura = models.BooleanField(default=False)
   crea_azienda = models.BooleanField(default=True)
@@ -21,7 +22,17 @@ class Amministratore(models.Model):
   crea_permesso = models.BooleanField(default=False)
   edit_permesso = models.BooleanField(default=False)
   read_permesso = models.BooleanField(default=True)
+  '''
+  def __str__(self):
+    return f"{self.id}: {self.nome}"
 
+class Permesso(models.Model):
+  nome=models.CharField(null=True,max_length=20)
+  descrizione=models.CharField(null=True,max_length=128)
   def __str__(self):
     return f"{self.id}: {self.nome}"
 
+class AP(models.Model):
+  # AP: Associazione Permessi
+  amministratore = models.ForeignKey(Amministratore,on_delete=models.PROTECT)
+  permesso = models.ForeignKey(Permesso,on_delete=models.PROTECT)

+ 1 - 0
amministratore/snippets/ap.xml

@@ -0,0 +1 @@
+[{"model": "amministratore.ap", "pk": 1, "fields": {"amministratore": 1, "permesso": 1}}, {"model": "amministratore.ap", "pk": 2, "fields": {"amministratore": 2, "permesso": 1}}, {"model": "amministratore.ap", "pk": 3, "fields": {"amministratore": 1, "permesso": 2}}, {"model": "amministratore.ap", "pk": 4, "fields": {"amministratore": 1, "permesso": 3}}]

+ 1 - 0
amministratore/snippets/permesso.xml

@@ -0,0 +1 @@
+[{"model": "amministratore.permesso", "pk": 1, "fields": {"nome": "AMMINISTRATORE", "descrizione": "Accesso alla gestione degli amministratori"}}, {"model": "amministratore.permesso", "pk": 2, "fields": {"nome": "AMMINISTRATORE.EDIT", "descrizione": "abilita' le attivita di aggiornamento in amministratore"}}, {"model": "amministratore.permesso", "pk": 3, "fields": {"nome": "AMMINISTRATORE.CREA", "descrizione": "abilita' le possibilita di creare nuovi amministratori"}}]

+ 0 - 77
amministratore/templates/amministratore.edit.html

@@ -39,83 +39,6 @@
       <input type='text' class='form-control form-control-lg' name='pin' id='pin' value='{{ amministratore.pin.value }}' {% if admin.sola_lettura %}readonly{% endif %}>
     </div>
 
-    <br>
-    <div class="card">
-      <div class="card-header">
-        Sicurezza
-      </div>
-      <ul class="list-group list-group-flush">
-      <li class="list-group-item">
-        <div class='form-check'>
-          <input class="form-check-input" type="checkbox" {% if amministratore.sola_lettura.value %} checked {% endif %} id="sola_lettura" name="sola_lettura" {% if admin.sola_lettura %} readonly {% endif %}>
-          <label for='sola_lettura' class='form-control-label'>Accesso consentito in sola lettura</label>
-        </div>
-        <div class="form-check">
-          <input class="form-check-input" type="checkbox" id="crea_azienda" name="crea_azienda" {% if admin.sola_lettura %}readonly{% endif %}/>
-          <label for='crea_azienda' class='form-control-label'>Autorizzato a creare aziende</label>
-        </div>
-        <div class="form-check">
-          <input class="form-check-input" type="checkbox" id="crea_sede" name="crea_sede" {% if admin.sola_lettura %}readonly{% endif %}/>
-          <label for='crea_sede' class='form-control-label'>Autorizzato a creare sedi</label>
-        </div>
-        <div class="form-check">
-          <input class="form-check-input" type="checkbox" id="crea_utente" name="crea_utente" {% if admin.sola_lettura %}readonly{% endif %}/>
-          <label for='crea_utente' class='form-control-label'>Autorizzato a creare dipendenti</label>
-        </div>
-        <div class="form-check">
-          <input class="form-check-input" type="checkbox" id="crea_documento" name="crea_documento" {% if admin.sola_lettura %}readonly{% endif %}/>
-          <label for='crea_documento' class='form-control-label'>Autorizzato a caricare documenti</label>
-        </div>
-        <div class="form-check">
-          <input class="form-check-input" type="checkbox" id="crea_comunicazione" name="crea_comunicazione" {% if admin.sola_lettura %}readonly{% endif %}/>
-          <label for='crea_comunicazione' class='form-control-label'>Autorizzato a creare messaggio per comunicazioni</label>
-        </div>
-        <div class="form-check">
-          <input class="form-check-input" type="checkbox" id="crea_permesso" name="crea_permesso" {% if admin.sola_lettura %}readonly{% endif %}/>
-          <label for='crea_permesso' clasm='form-control-label'>Autorizzato a creare/associare permessi</label>
-        </div>
-     </li>
-
-     <!-- editing -->
-     <li class="list-group-item">
-        <div class='form-check'>
-          <input class="form-check-input" type="checkbox" {% if amministratore.edit_azienda.value %} checked {% endif %} id="edit_azienda" name="edit_azienda" {% if admin.sola_lettura %}readonly{% endif %}/>
-          <label for='edit_azienda' class='form-control-label'>Autorizzato a modificare aziende</label>
-        </div>
-        <div class='form-check'>
-          <input class="form-check-input" type="checkbox" {% if amministratore.edit_sede.value %} checked {% endif %} id="edit_sede" name="edit_sede" {% if admin.sola_lettura %}readonly{% endif %}/>
-          <label for='edit_sede' class='form-control-label'>Autorizzato a modificare sedi</label>
-        </div>
-        <div class='form-check'>
-          <input class="form-check-input" type="checkbox" {% if amministratore.edit_utente.value %} checked {% endif %} id="edit_utente" name="edit_utente" {% if admin.sola_lettura %}readonly{% endif %}/>
-           <label for='edit_utente' class='form-control-label'>Autorizzato a modificare dipendenti</label>
-        </div>
-        <div class='form-check'>
-          <input class="form-check-input" type="checkbox" {% if amministratore.edit_documento.value %} checked {% endif %} id="edit_documento" name="edit_documento" {% if admin.sola_lettura %}readonly{% endif %}/>
-           <label for='edit_documento' class='form-control-label'>Autorizzato a modificare documenti</label>
-        </div>
-        <div class='form-check'>
-          <input class="form-check-input" type="checkbox" {% if amministratore.edit_comunicazione.value %} checked {% endif %} id="edit_comunicazione" name="edit_comunicazione" {% if admin.sola_lettura %}readonly{% endif %}/>
-           <label for='edit_comunicazione' class='form-control-label'>Autorizzato a modificare messaggi per comunicazione</label>
-        </div>
-        <div class='form-check'>
-          <input class="form-check-input" type="checkbox" {% if amministratore.edit_permesso.value %} checked {% endif %} id="edit_permesso" name="edit_permesso" {% if admin.sola_lettura %}readonly{% endif %}/>
-           <label for='edit_permesso' class='form-control-label'>Autorizzato a modificare permessi e associazioni</label>
-        </div>
-        <div class='form-check'>
-          <input class="form-check-input" type="checkbox" {% if amministratore.vedi_permesso.value %} checked {% endif %} id="vedi_permesso" name="vedi_permesso" {% if admin.sola_lettura %}readonly{% endif %}/>
-           <label for='vedi_permesso' class='form-control-label'>Visualizza permessi e associazioni</label>
-        </div>
-      </li>
-
-      <!-- blocco automazione OTP accesso -->
-      <li class="list-group-item">
-      </li>
-    </ul>
-    </div>
-
-    <br>
-
     <div class="btn-group">
       <input type='submit' class="btn btn-primary" value='Aggiorna' {% if admin.sola_lettura %} disable {% endif %}>
       <input type='submit' class="btn btn-primary" name="indietro" value="Indietro">

+ 4 - 4
amministratore/templates/amministratore.welcome.html

@@ -16,7 +16,7 @@
   <table class='table table-striped table-hover'>
     <thead class='thead-dark'>
       <tr>
-        {% if admin.edit_permesso %}<th scope='col'>*</th>{% endif %}
+        {% if "AMMINISTRATORE.EDIT" in permesso %}<th scope='col'>*</th>{% endif %}
         <th scope='col'>Login</th>
         <th scope='col'>Nome</th>
         <th scope='col'>Mail</th>
@@ -29,13 +29,13 @@
       {% csrf_token %}
       {% for aa in amministratorelista %}
         <tr>
-          {% if admin.edit_permesso %}
+          {% if "AMMINISTRATORE.EDIT" in permesso %}
             <td> <button type='submit' class='btn btn-primary btn-block btn-lg mb-2 active' name='scelta' value='{{ aa.id }}' {% if not admin.edit_permesso %}disable{% endif %} onchange="this.form.submit()">Edit</button></td>
           {% endif %}
           <td> {{ aa.login }} </td>
 	  <td> {{ aa.nome }} </td>
           <td> {{ aa.mail }} </td>
-          {% if admin.edit_permesso %}
+          {% if "AMMINISTRATORE.EDIT" in permesso %}
             <td> {{ aa.pin }} </td>
           {% endif %}
 	</tr>
@@ -44,7 +44,7 @@
   </table>
   </form>
 
-  {% if admin.crea_amministratore %}
+  {% if "AMMINISTRATORE.CREA" in permesso %}
   <!-- Modal -->
   <div class="modal fade" id="CaricaIndiceModal" tabindex="-1" role="dialog" aria-labelledby="CaricaIndiceLabel" aria-hidden="true">
     <div class="modal-dialog" role="document">

+ 20 - 1
amministratore/views.py

@@ -7,6 +7,23 @@ from config.views import *
 from django.http import HttpResponse,HttpResponseRedirect
 from django.urls import reverse
 
+def getAP(amministratore=None):
+  amm=None
+  print('getAP',amministratore)
+  if isinstance(amministratore,Amministratore):
+    print('si tratta di una istanza, quindi possiamo direttamente accedere')
+    amm = amministratore
+  if isinstance(amministratore,int):
+    print('si tratta di un int, quindi dobbiamo cercare il valore')
+    amm = Amministratore.object.get(pk=amministratore)
+
+  permessi = list()
+  for p in amm.ap_set.all():
+    permessi.append(p.permesso.nome)
+
+  print('permessi disponibili',len(permessi))
+  return permessi
+
 def welcome(request):
   if not 'AdminId' in request.session:
     print("Non rilevo presensa AdminId in request.session")
@@ -22,6 +39,7 @@ def welcome(request):
   admin = Amministratore.objects.get(pk=AdminId)
   data['admin'] = admin
   print('admin',admin.id,admin.nome)
+  data['permesso'] = getAP(admin)
 
   azienda = None
   if 'AziendaId' in request.session:
@@ -98,7 +116,8 @@ def edit(request):
     admin = Amministratore.objects.get(pk=data['AdminId'])
     data['admin'] = admin
     print('admin',admin.id,admin.nome)
-
+    data['permesso'] = getAP(admin)
+   
   amministratore = None
   print(request)
   if 'AmministratoreEditId' in request.session:

+ 1 - 1
azienda/templates/azienda.welcome.html

@@ -17,7 +17,7 @@
       <button type='submit' class='btn btn-primary' name='parazienda' value='{{ azienda.id }}'>Par.Azienda</button>
       <button type='submit' class='btn btn-primary' name='parsede' value='{{ sede.id }}' {% if not sede.id %} disabled {% endif %}>Par.Sede</button>
     {% endif %}
-    {% if admin.read_permesso %}
+    {% if "AMMINISTRAZIONE" in permesso %}
       <button type='submit' class='btn btn-primary' name='amministratore' value='{{ admin.id }}'>Amministratori</button> 
     {% endif %}
   </form>

+ 2 - 1
azienda/views.py

@@ -5,7 +5,7 @@ from .models import *
 from config.views import *
 from att.views import *
 from .forms import *
-
+from amministratore.views import getAP
 def welcome(request):
 
   if not 'AdminId' in request.session:
@@ -40,6 +40,7 @@ def welcome(request):
 
   admin = Amministratore.objects.get(pk=AdminId)
   data['admin'] = admin
+  data['permesso'] = getAP(admin)
   print('admin',admin.id,admin.nome)
 
   assegnazioneazienda = AssegnazioneAzienda.objects.filter(amministratore=admin.id).order_by('azienda__nome')

+ 0 - 0
registratore/__init__.py


+ 3 - 0
registratore/admin.py

@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.

+ 6 - 0
registratore/apps.py

@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+
+
+class RegistratoreConfig(AppConfig):
+    default_auto_field = 'django.db.models.BigAutoField'
+    name = 'registratore'

+ 0 - 0
registratore/migrations/__init__.py


+ 7 - 0
registratore/models.py

@@ -0,0 +1,7 @@
+from django.db import models
+
+class Registratore(models.model)
+  data = models.DateTimeField(default=datetime.datetime(2024, 1, 1, 21, 43, 52, 352359))
+  causale = models.ForeignKey(Causale,null=True,on_delete=models.PROTECT,default=None)
+  valore = models.CharField(max_length=256,default='',null=False)
+

+ 3 - 0
registratore/tests.py

@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.

+ 3 - 0
registratore/views.py

@@ -0,0 +1,3 @@
+from django.shortcuts import render
+
+# Create your views here.