create permissions for reports and widgets
This commit is contained in:
		@@ -6,6 +6,8 @@ use App\Models\Auth\Permission;
 | 
				
			|||||||
use App\Models\Auth\Role;
 | 
					use App\Models\Auth\Role;
 | 
				
			||||||
use App\Models\Module\Module;
 | 
					use App\Models\Module\Module;
 | 
				
			||||||
use App\Models\Module\ModuleHistory;
 | 
					use App\Models\Module\ModuleHistory;
 | 
				
			||||||
 | 
					use App\Utilities\Reports;
 | 
				
			||||||
 | 
					use App\Utilities\Widgets;
 | 
				
			||||||
use Illuminate\Console\Command;
 | 
					use Illuminate\Console\Command;
 | 
				
			||||||
use Illuminate\Support\Str;
 | 
					use Illuminate\Support\Str;
 | 
				
			||||||
use Symfony\Component\Console\Input\InputArgument;
 | 
					use Symfony\Component\Console\Input\InputArgument;
 | 
				
			||||||
@@ -56,10 +58,6 @@ class InstallCommand extends Command
 | 
				
			|||||||
            'description' => trans('modules.installed', ['module' => $alias]),
 | 
					            'description' => trans('modules.installed', ['module' => $alias]),
 | 
				
			||||||
        ]);
 | 
					        ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!empty($module->get('settings'))) {
 | 
					 | 
				
			||||||
            $this->updatePermissions($module);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $this->call('cache:clear');
 | 
					        $this->call('cache:clear');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Update database
 | 
					        // Update database
 | 
				
			||||||
@@ -67,6 +65,10 @@ class InstallCommand extends Command
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        event(new \App\Events\Module\Installed($alias, $company_id));
 | 
					        event(new \App\Events\Module\Installed($alias, $company_id));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!empty($module->get('reports')) || !empty($module->get('widgets')) || !empty($module->get('settings'))) {
 | 
				
			||||||
 | 
					            $this->updatePermissions($module);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        session()->forget('company_id');
 | 
					        session()->forget('company_id');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!empty($old_company_id)) {
 | 
					        if (!empty($old_company_id)) {
 | 
				
			||||||
@@ -93,17 +95,53 @@ class InstallCommand extends Command
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        $permissions = [];
 | 
					        $permissions = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $permissions[] = Permission::firstOrCreate([
 | 
					        if (!empty($module->get('reports'))) {
 | 
				
			||||||
            'name' => 'read-' . $module->getAlias() . '-settings',
 | 
					            foreach ($module->get('reports') as $class) {
 | 
				
			||||||
            'display_name' => 'Read ' . $module->getName() . ' Settings',
 | 
					                if (!class_exists($class)) {
 | 
				
			||||||
            'description' => 'Read ' . $module->getName() . ' Settings',
 | 
					                    continue;
 | 
				
			||||||
        ]);
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $permissions[] = Permission::firstOrCreate([
 | 
					                $name = Reports::getPermission($class);
 | 
				
			||||||
            'name' => 'update-' . $module->getAlias() . '-settings',
 | 
					                $display_name = (new $class())->getDefaultName();
 | 
				
			||||||
            'display_name' => 'Update ' . $module->getName() . ' Settings',
 | 
					
 | 
				
			||||||
            'description' => 'Update ' . $module->getName() . ' Settings',
 | 
					                $permissions[] = Permission::firstOrCreate([
 | 
				
			||||||
        ]);
 | 
					                    'name' => $name,
 | 
				
			||||||
 | 
					                    'display_name' => 'Read ' . $module->getName() . ' Reports ' . $display_name,
 | 
				
			||||||
 | 
					                    'description' => 'Read ' . $module->getName() . ' Reports ' . $display_name,
 | 
				
			||||||
 | 
					                ]);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!empty($module->get('widgets'))) {
 | 
				
			||||||
 | 
					            foreach ($module->get('widgets') as $class) {
 | 
				
			||||||
 | 
					                if (!class_exists($class)) {
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                $name = Widgets::getPermission($class);
 | 
				
			||||||
 | 
					                $display_name = (new $class())->getDefaultName();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                $permissions[] = Permission::firstOrCreate([
 | 
				
			||||||
 | 
					                    'name' => $name,
 | 
				
			||||||
 | 
					                    'display_name' => 'Read ' . $module->getName() . ' Widgets ' . $display_name,
 | 
				
			||||||
 | 
					                    'description' => 'Read ' . $module->getName() . ' Widgets ' . $display_name,
 | 
				
			||||||
 | 
					                ]);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!empty($module->get('settings'))) {
 | 
				
			||||||
 | 
					            $permissions[] = Permission::firstOrCreate([
 | 
				
			||||||
 | 
					                'name' => 'read-' . $module->getAlias() . '-settings',
 | 
				
			||||||
 | 
					                'display_name' => 'Read ' . $module->getName() . ' Settings',
 | 
				
			||||||
 | 
					                'description' => 'Read ' . $module->getName() . ' Settings',
 | 
				
			||||||
 | 
					            ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $permissions[] = Permission::firstOrCreate([
 | 
				
			||||||
 | 
					                'name' => 'update-' . $module->getAlias() . '-settings',
 | 
				
			||||||
 | 
					                'display_name' => 'Update ' . $module->getName() . ' Settings',
 | 
				
			||||||
 | 
					                'description' => 'Update ' . $module->getName() . ' Settings',
 | 
				
			||||||
 | 
					            ]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Attach permission to roles
 | 
					        // Attach permission to roles
 | 
				
			||||||
        $roles = Role::all()->filter(function ($r) {
 | 
					        $roles = Role::all()->filter(function ($r) {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										
											BIN
										
									
								
								public/files/import/chart-of-accounts.xlsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								public/files/import/chart-of-accounts.xlsx
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user