diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..930be90 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +docker +.vscode \ No newline at end of file diff --git a/.gitignore b/.gitignore index dcfc65e..b39bae1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ -phpunit.xml reports sandbox vendor composer.lock .idea/ +workbench +.phpunit.result.cache \ No newline at end of file diff --git a/composer.json b/composer.json index fe3a387..e2b0a49 100644 --- a/composer.json +++ b/composer.json @@ -54,11 +54,7 @@ "minimum-stability": "dev", "prefer-stable": true, "autoload-dev": { - "psr-4": { - "Workbench\\App\\": "workbench/app/", - "Workbench\\Database\\Factories\\": "workbench/database/factories/", - "Workbench\\Database\\Seeders\\": "workbench/database/seeders/" - } + "psr-4": {} }, "scripts": { "post-autoload-dump": [ @@ -75,6 +71,10 @@ ], "lint": [ "@php vendor/bin/pint --ansi" + ], + "test": [ + "@clear", + "@php vendor/bin/phpunit" ] } -} +} \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index 4a49487..0000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,22 +0,0 @@ - - - - - src/ - - - - - tests - - - - - - - \ No newline at end of file diff --git a/src/Traits/HasPermissions.php b/src/Traits/HasPermissions.php index fc94b21..a8d90e9 100644 --- a/src/Traits/HasPermissions.php +++ b/src/Traits/HasPermissions.php @@ -8,7 +8,7 @@ trait HasPermissions { public function hasPermission(string $permission): bool { - $allpermissions = $this->allPermissions(); + $allpermissions = $this->permissions(); if ($allpermissions->contains('slug', '*')) { return true; // If any permission is '*', all permissions are granted @@ -31,7 +31,7 @@ trait HasPermissions ); } - public function permissions() + public function individualPermissions() { return $this->morphToMany( config('roles.models.permission'), @@ -40,6 +40,16 @@ trait HasPermissions ); } + public function permissions() + { + $rolePerms = $this->rolePermissions()->get(); + $directPerms = $this->permissions()->get(); + + return $rolePerms + ->merge($directPerms) + ->unique('id'); + } + public function assignPermission($permission) { $permission_class = config('roles.models.permission'); @@ -85,32 +95,4 @@ trait HasPermissions return true; } - - /** - * Get all permissions directly assigned or inherited via roles. - * - * @return Collection - */ - public function allPermissions() - { - // Directly assigned permissions - $direct = $this->permissions()->get(); - - // Permissions via roles (if the roles() relation exists) - if (method_exists($this, 'roles')) { - $rolePermissions = $this->roles() - ->with('permissions') - ->get() - ->pluck('permissions') - ->flatten(); - } else { - $rolePermissions = collect(); - } - - // Merge and dedupe by 'id' - return $direct - ->merge($rolePermissions) - ->unique('id') - ->values(); - } } diff --git a/testbench.yaml b/testbench.yaml deleted file mode 100644 index 23e4015..0000000 --- a/testbench.yaml +++ /dev/null @@ -1,33 +0,0 @@ -laravel: '@testbench' - -providers: - # - Workbench\App\Providers\WorkbenchServiceProvider - -migrations: - - workbench/database/migrations - -seeders: - - Workbench\Database\Seeders\DatabaseSeeder - -workbench: - start: '/' - install: true - health: false - discovers: - web: true - api: true - commands: true - components: false - factories: true - views: false - build: - - asset-publish - - create-sqlite-db - - db-wipe - - migrate-fresh - assets: - - laravel-assets - sync: - - from: storage - to: workbench/storage - reverse: true