Skip to content

Commit

Permalink
Merge pull request #16 from flixtechs-labs/dev
Browse files Browse the repository at this point in the history
fix: collision in generating user policy
  • Loading branch information
SlimGee authored Dec 8, 2023
2 parents 8341bc6 + 7e4d15f commit d1563b5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 55 deletions.
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
"symfony/filesystem": "^6.2.7"
},
"require-dev": {
"laravel/pint": "^1.6.0",
"larastan/larastan": "^2.7",
"laravel/pint": "^1.13.7",
"nunomaduro/collision": "^6.4.0",
"nunomaduro/larastan": "^2.5.1",
"orchestra/testbench": "^7.22.1",
"pestphp/pest": "^1.22.5",
"orchestra/testbench": "^7.37.0",
"pestphp/pest": "^1.23.1",
"pestphp/pest-plugin-laravel": "^1.4",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan-deprecation-rules": "^1.1.2",
"phpstan/phpstan-phpunit": "^1.3.10",
"phpunit/phpunit": "^9.6.4",
"phpstan/extension-installer": "^1.3.1",
"phpstan/phpstan-deprecation-rules": "^1.1.4",
"phpstan/phpstan-phpunit": "^1.3.15",
"phpunit/phpunit": "^9.6.15",
"roave/security-advisories": "dev-latest"
},
"autoload": {
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/LaravelAuthorizerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function handle(): int
return self::SUCCESS;
}

$this->generatePolicy($name, $model);
$this->generatePolicy($name, ucfirst($model));

return self::SUCCESS;
}
Expand Down Expand Up @@ -136,8 +136,8 @@ private function generatePolicy(string $name, string $model): void
strtolower(
Str::afterLast($this->getNamespacedUserModel(), '\\')
)
? $this->getStub()
: $this->getUserPolicyPolicyStub()
? $this->getUserPolicyPolicyStub()
: $this->getStub()
)
);

Expand Down
38 changes: 19 additions & 19 deletions src/Commands/stubs/policy.stub
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class {{ class }}
/**
* Determine whether the user can view any models.
*
* @param \{{ namespacedUserModel }} $user
* @return \Illuminate\Auth\Access\Response|bool
* @param {{ model }} $user
* @return bool
*/
public function viewAny({{ user }} $user): bool
{
Expand All @@ -24,9 +24,9 @@ class {{ class }}
/**
* Determine whether the user can view the model.
*
* @param \{{ namespacedUserModel }} $user
* @param \{{ namespacedModel }} ${{ modelVariable }}
* @return \Illuminate\Auth\Access\Response|bool
* @param {{ user }} $user
* @param {{ model }} ${{ modelVariable }}
* @return bool
*/
public function view({{ user }} $user, {{ model }} ${{ modelVariable }}): bool
{
Expand All @@ -36,8 +36,8 @@ class {{ class }}
/**
* Determine whether the user can create models.
*
* @param \{{ namespacedUserModel }} $user
* @return \Illuminate\Auth\Access\Response|bool
* @param {{ user }} $user
* @return bool
*/
public function create({{ user }} $user): bool
{
Expand All @@ -47,9 +47,9 @@ class {{ class }}
/**
* Determine whether the user can update the model.
*
* @param \{{ namespacedUserModel }} $user
* @param \{{ namespacedModel }} ${{ modelVariable }}
* @return \Illuminate\Auth\Access\Response|bool
* @param {{ user }} $user
* @param {{ model }} ${{ modelVariable }}
* @return bool
*/
public function update({{ user }} $user, {{ model }} ${{ modelVariable }}): bool
{
Expand All @@ -59,9 +59,9 @@ class {{ class }}
/**
* Determine whether the user can delete the model.
*
* @param \{{ namespacedUserModel }} $user
* @param \{{ namespacedModel }} ${{ modelVariable }}
* @return \Illuminate\Auth\Access\Response|bool
* @param {{ user }} $user
* @param {{ model }} ${{ modelVariable }}
* @return bool
*/
public function delete({{ user }} $user, {{ model }} ${{ modelVariable }}): bool
{
Expand All @@ -71,9 +71,9 @@ class {{ class }}
/**
* Determine whether the user can restore the model.
*
* @param \{{ namespacedUserModel }} $user
* @param \{{ namespacedModel }} ${{ modelVariable }}
* @return \Illuminate\Auth\Access\Response|bool
* @param {{ user }} $user
* @param {{ model }} ${{ modelVariable }}
* @return bool
*/
public function restore({{ user }} $user, {{ model }} ${{ modelVariable }}): bool
{
Expand All @@ -83,9 +83,9 @@ class {{ class }}
/**
* Determine whether the user can permanently delete the model.
*
* @param \{{ namespacedUserModel }} $user
* @param \{{ namespacedModel }} ${{ modelVariable }}
* @return \Illuminate\Auth\Access\Response|bool
* @param {{ user }} $user
* @param {{ model }} ${{ modelVariable }}
* @return bool
*/
public function forceDelete({{ user }} $user, {{ model }} ${{ modelVariable }}): bool
{
Expand Down
51 changes: 26 additions & 25 deletions src/Commands/stubs/policy.user.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace {{ namespace }};

use Illuminate\Auth\Access\HandlesAuthorization;
use Illuminate\Auth\Access\Response;
use {{ namespacedUserModel }};

class {{ class }}
Expand All @@ -12,8 +13,8 @@ class {{ class }}
/**
* Determine whether the user can view any models.
*
* @param \{{ namespacedUserModel }} $user
* @return \Illuminate\Auth\Access\Response|bool
* @param {{ model }} $user
* @return Response|bool
*/
public function viewAny({{ user }} $user): bool
{
Expand All @@ -23,20 +24,20 @@ class {{ class }}
/**
* Determine whether the user can view the model.
*
* @param \{{ namespacedUserModel }} $user
* @param \{{ namespacedUserModel }} ${{ modelVariable }}
* @return \Illuminate\Auth\Access\Response|bool
* @param {{ model }} $user
* @param {{ model }} $model
* @return Response|bool
*/
public function view({{ user }} $user, {{ model }} ${{ modelVariable }}): bool
public function view({{ user }} $user, {{ userModel }} $model): bool
{
return $user->can('view {{ modelSingularLowerCase }}', ${{ modelVariable }});
return $user->can('view {{ modelSingularLowerCase }}', $model)
}

/**
* Determine whether the user can create models.
*
* @param \{{ namespacedUserModel }} $user
* @return \Illuminate\Auth\Access\Response|bool
* @param {{ model }} $user
* @return Response|bool
*/
public function create({{ user }} $user): bool
{
Expand All @@ -46,33 +47,33 @@ class {{ class }}
/**
* Determine whether the user can update the model.
*
* @param \{{ namespacedUserModel }} $user
* @param \{{ namespacedUserModel }} ${{ modelVariable }}
* @return \Illuminate\Auth\Access\Response|bool
* @param {{ model }} $user
* @param {{ model }} $model
* @return Response|bool
*/
public function update({{ user }} $user, {{ model }} ${{ modelVariable }}): bool
public function update({{ user }} $user, {{ model }} $model): bool
{
return $user->can('update {{ modelSingularLowerCase }}', ${{ modelVariable }});
return $user->can('update {{ modelSingularLowerCase }}', $model);
}

/**
* Determine whether the user can delete the model.
*
* @param \{{ namespacedUserModel }} $user
* @param \{{ namespacedUserModel }} ${{ modelVariable }}
* @return \Illuminate\Auth\Access\Response|bool
* @param {{ model }} $user
* @param {{ model }} ${{ modelVariable }}
* @return Response|bool
*/
public function delete({{ user }} $user, {{ model }} ${{ modelVariable }}): bool
public function delete({{ user }} $user, {{ model }} $model): bool
{
return $user->can('delete {{ modelSingularLowerCase }}', ${{ modelVariable }});
return $user->can('delete {{ modelSingularLowerCase }}', $model);
}

/**
* Determine whether the user can restore the model.
*
* @param \{{ namespacedUserModel }} $user
* @param \{{ namespacedUserModel }} ${{ modelVariable }}
* @return \Illuminate\Auth\Access\Response|bool
* @param {{ model }} $user
* @param {{ model }} ${{ modelVariable }}
* @return Response|bool
*/
public function restore({{ user }} $user, {{ model }} ${{ modelVariable }}): bool
{
Expand All @@ -82,9 +83,9 @@ class {{ class }}
/**
* Determine whether the user can permanently delete the model.
*
* @param \{{ namespacedUserModel }} $user
* @param \{{ namespacedUserModel }} ${{ modelVariable }}
* @return \Illuminate\Auth\Access\Response|bool
* @param {{ model }} $user
* @param {{ model }} ${{ modelVariable }}
* @return Response|bool
*/
public function forceDelete({{ user }} $user, {{ model }} ${{ modelVariable }}): bool
{
Expand Down

0 comments on commit d1563b5

Please sign in to comment.