diff --git a/app/Http/Controllers/AuditLogsController.php b/app/Http/Controllers/AuditLogsController.php index f8d7d78..b96777d 100644 --- a/app/Http/Controllers/AuditLogsController.php +++ b/app/Http/Controllers/AuditLogsController.php @@ -9,16 +9,33 @@ class AuditLogsController extends Controller { + protected $user; + + public function __construct() + { + $this->user = Auth::guard('web')->user(); + } + /** * Display a listing of the resource. */ public function index() { + // Check if the authenticated user has the required permission to view audit logs + if (is_null($this->user) || !$this->user->can('audit-logs.read')) { + abort(403, 'Sorry! You are not allowed to view audit logs.'); + } + return view('logs::audit'); } public function datatable(Request $request) { + // Check if the authenticated user has the required permission to view audit logs + if (is_null($this->user) || !$this->user->can('audit-logs.read')) { + abort(403, 'Sorry! You are not allowed to view audit logs.'); + } + // Retrieve data from the database $query = Activity::query(); @@ -97,6 +114,5 @@ 'totalCount' => $filteredRecords, 'data' => $data, ]); - } } diff --git a/app/Http/Controllers/SystemLogsController.php b/app/Http/Controllers/SystemLogsController.php index fcd157b..9b8b408 100644 --- a/app/Http/Controllers/SystemLogsController.php +++ b/app/Http/Controllers/SystemLogsController.php @@ -10,10 +10,12 @@ use Jackiedo\LogReader\LogReader; class SystemLogsController extends Controller { protected $reader; + protected $user; public function __construct(LogReader $reader) { $this->reader = $reader; + $this->user = Auth::guard('web')->user(); } /** @@ -21,10 +23,20 @@ class SystemLogsController extends Controller */ public function index() { + // Check if the authenticated user has the required permission to view system logs + if (is_null($this->user) || !$this->user->can('system-logs.read')) { + abort(403, 'Sorry! You are not allowed to view system logs.'); + } + return view('logs::system'); } public function datatable(Request $request){ + // Check if the authenticated user has the required permission to view system logs + if (is_null($this->user) || !$this->user->can('system-logs.read')) { + abort(403, 'Sorry! You are not allowed to view system logs.'); + } + $data = collect(); $this->reader->setLogPath(storage_path('logs')); try { diff --git a/database/seeders/LogsDatabaseSeeder.php b/database/seeders/LogsDatabaseSeeder.php index 33733bf..d3917c4 100644 --- a/database/seeders/LogsDatabaseSeeder.php +++ b/database/seeders/LogsDatabaseSeeder.php @@ -11,6 +11,8 @@ class LogsDatabaseSeeder extends Seeder */ public function run(): void { - // $this->call([]); + $this->call([ + PermissionSeeder::class + ]); } } diff --git a/database/seeders/PermissionSeeder.php b/database/seeders/PermissionSeeder.php new file mode 100644 index 0000000..350aa06 --- /dev/null +++ b/database/seeders/PermissionSeeder.php @@ -0,0 +1,51 @@ +data(); + + foreach ($data as $value) { + $group = PermissionGroup::updateOrCreate([ + 'name' => $value['name'], + 'slug' => Str::slug($value['name']) + ]); + + foreach ($this->crudActions($group->name) as $action) { + $data[] = ['name' => $action, 'group' => $group->id]; + } + } + } + + public function data() + { + return [ + ['name' => 'system-logs'], + ['name' => 'audit-logs'], + ]; + } + + public function crudActions($name) + { + $actions = []; + // list of permission actions + $crud = ['create', 'read', 'update', 'delete','export', 'authorize', 'report','restore']; + + + foreach ($crud as $value) { + $actions[] = $name . '.' . $value; + } + + return $actions; + } + } diff --git a/resources/views/layouts/master.blade.php b/resources/views/layouts/master.blade.php deleted file mode 100644 index 9ef4060..0000000 --- a/resources/views/layouts/master.blade.php +++ /dev/null @@ -1,29 +0,0 @@ - - - -
- - - - - -