You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Models/Group.php
+33Lines changed: 33 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -76,6 +76,7 @@ public static function getTranslatedFields()
76
76
* Sincronizza i permessi delle viste e dei segmenti per un modulo specifico.
77
77
* Se il gruppo non ha permessi sul modulo, rimuove i permessi sulle viste e segmenti.
78
78
* Se il gruppo ha permessi sul modulo, aggiunge i permessi alle viste predefinite e al segmento predefinito.
79
+
* Se non ci sono viste o segmenti predefiniti, aggiunge il gruppo ad almeno uno di essi.
79
80
* Gli Amministratori mantengono sempre accesso completo.
80
81
*
81
82
* @param int $id_module ID del modulo
@@ -109,6 +110,22 @@ public function syncModulePermissions($id_module, $permessi)
109
110
}
110
111
}
111
112
113
+
// Se non ci sono viste predefinite, aggiungi il gruppo ad almeno una vista (la prima disponibile)
114
+
if (empty($default_views)) {
115
+
$first_view = $database->fetchArray('SELECT `id` FROM `zz_views` WHERE `id_module`='.prepare($id_module).' ORDER BY `order` ASC LIMIT 1');
116
+
117
+
if (!empty($first_view)) {
118
+
$has_view_access = $database->fetchArray('SELECT COUNT(*) as cont FROM `zz_group_view` WHERE `id_gruppo` = '.prepare($this->id).' AND `id_vista` = '.prepare($first_view[0]['id']))['cont'];
119
+
120
+
if ($has_view_access == 0) {
121
+
$database->insert('zz_group_view', [
122
+
'id_gruppo' => $this->id,
123
+
'id_vista' => $first_view[0]['id'],
124
+
]);
125
+
}
126
+
}
127
+
}
128
+
112
129
// Aggiungi accesso ai segmenti predefiniti se non ce l'ha già
113
130
$default_segments = $database->fetchArray('SELECT `id` FROM `zz_segments` WHERE `id_module`='.prepare($id_module).' AND `predefined` = 1');
114
131
@@ -123,6 +140,22 @@ public function syncModulePermissions($id_module, $permessi)
123
140
]);
124
141
}
125
142
}
143
+
144
+
// Se non ci sono segmenti predefiniti, aggiungi il gruppo ad almeno un segmento (il primo disponibile)
145
+
if (empty($default_segments)) {
146
+
$first_segment = $database->fetchArray('SELECT `id` FROM `zz_segments` WHERE `id_module`='.prepare($id_module).' ORDER BY `id` ASC LIMIT 1');
147
+
148
+
if (!empty($first_segment)) {
149
+
$has_segment_access = $database->fetchArray('SELECT COUNT(*) as cont FROM `zz_group_segment` WHERE `id_gruppo` = '.prepare($this->id).' AND `id_segment` = '.prepare($first_segment[0]['id']))['cont'];
150
+
151
+
if ($has_segment_access == 0) {
152
+
$database->insert('zz_group_segment', [
153
+
'id_gruppo' => $this->id,
154
+
'id_segment' => $first_segment[0]['id'],
155
+
]);
156
+
}
157
+
}
158
+
}
126
159
} else {
127
160
// Se i permessi sono stati rimossi, rimuovi tutti i permessi su viste e segmenti del modulo
128
161
$database->query('DELETE FROM `zz_group_view` WHERE `id_gruppo` = '.prepare($this->id).' AND `id_vista` IN (SELECT `id` FROM `zz_views` WHERE `id_module`='.prepare($id_module).')');
0 commit comments