Skip to content

Commit

Permalink
Merge pull request #217 from fiere210/ignore-existing-policies-option…
Browse files Browse the repository at this point in the history
…-to-generate-command

Update MakeShieldGenerateCommand.php
  • Loading branch information
bezhanSalleh authored Sep 16, 2023
2 parents f9bf211 + e603683 commit 8ae1a2e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Commands/MakeShieldGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class MakeShieldGenerateCommand extends Command
{--exclude : Exclude the given entities during generation }
{--ignore-config-exclude : Ignore config `<fg=yellow;options=bold>exclude</>` option during generation }
{--minimal : Output minimal amount of info to console}
{--ignore-existing-policies : Ignore generating policies that already exist }
';
// {--seeder : Exclude the given entities during generation }
// the idea is to generate a seeder that can be used on production deployment
Expand Down Expand Up @@ -191,12 +192,18 @@ protected function generateForResources(array $resources): Collection
->values()
->each(function ($entity) {
if ($this->generatorOption === 'policies_and_permissions') {
$this->copyStubToApp(static::getPolicyStub($entity['model']), $this->generatePolicyPath($entity), $this->generatePolicyStubVariables($entity));
$policyPath = $this->generatePolicyPath($entity);
if (!$this->option('ignore-existing-policies') || ($this->option('ignore-existing-policies') && !$this->fileExists($policyPath))) {
$this->copyStubToApp(static::getPolicyStub($entity['model']), $policyPath, $this->generatePolicyStubVariables($entity));
}
FilamentShield::generateForResource($entity);
}

if ($this->generatorOption === 'policies') {
$this->copyStubToApp(static::getPolicyStub($entity['model']), $this->generatePolicyPath($entity), $this->generatePolicyStubVariables($entity));
$policyPath = $this->generatePolicyPath($entity);
if (!$this->option('ignore-existing-policies') || ($this->option('ignore-existing-policies') && !$this->fileExists($policyPath))) {
$this->copyStubToApp(static::getPolicyStub($entity['model']), $policyPath, $this->generatePolicyStubVariables($entity));
}
}

if ($this->generatorOption === 'permissions') {
Expand Down

0 comments on commit 8ae1a2e

Please sign in to comment.