|
|
@@ -61,31 +61,27 @@ public function create(array $data): Unit
|
|
|
'access_scope' => 'unit',
|
|
|
]);
|
|
|
|
|
|
- // Clona os perfis customizados (Neurotrainer, Financeiro, Gestor) baseados na unidade da Andreia
|
|
|
- $andreiaUnitId = \App\Models\User::find(11)?->units()->value('units.id');
|
|
|
- if ($andreiaUnitId) {
|
|
|
- $templateRoles = UserType::where('unit_id', $andreiaUnitId)
|
|
|
- ->where('is_system', false)
|
|
|
- ->with('permissions')
|
|
|
- ->get();
|
|
|
-
|
|
|
+ // Clona os perfis customizados a partir do arquivo de configuração gerado
|
|
|
+ $templateRoles = config('default_franchisee_roles', []);
|
|
|
+
|
|
|
+ if (!empty($templateRoles)) {
|
|
|
foreach ($templateRoles as $templateRole) {
|
|
|
$newRole = UserType::create([
|
|
|
'unit_id' => $unit->id,
|
|
|
- 'system_key' => $templateRole->system_key,
|
|
|
+ 'system_key' => $templateRole['system_key'],
|
|
|
'scope_key' => "unit:{$unit->id}",
|
|
|
- 'slug' => \Illuminate\Support\Str::slug($templateRole->label . '-' . $unit->id),
|
|
|
- 'label' => $templateRole->label,
|
|
|
+ 'slug' => \Illuminate\Support\Str::slug($templateRole['label'] . '-' . $unit->id),
|
|
|
+ 'label' => $templateRole['label'],
|
|
|
'is_system' => false,
|
|
|
'access_scope' => 'unit',
|
|
|
]);
|
|
|
|
|
|
- foreach ($templateRole->permissions as $p) {
|
|
|
+ foreach ($templateRole['permissions'] as $p) {
|
|
|
\App\Models\UserTypePermission::create([
|
|
|
'user_type' => $newRole->slug,
|
|
|
'user_type_id' => $newRole->id,
|
|
|
- 'permission_id' => $p->permission_id,
|
|
|
- 'bits' => $p->bits,
|
|
|
+ 'permission_id' => $p['permission_id'],
|
|
|
+ 'bits' => $p['bits'],
|
|
|
]);
|
|
|
}
|
|
|
}
|