Skip to content

Commit

Permalink
Merge branch '3.next' into 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jan 13, 2025
2 parents 6e880cb + 956d612 commit ed52f1a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/Command/PolicyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,16 @@ public function templateData(Arguments $arguments): array
$suffix = 'Table';
}

$imports = [];
$className = $data['namespace'] . '\\' . $name;
if ($type === 'table') {
$className = "{$data['namespace']}\Model\\Table\\{$name}{$suffix}";
$imports[] = 'Cake\ORM\SelectQuery';
} elseif ($type === 'entity') {
$className = "{$data['namespace']}\Model\\Entity\\{$name}";
$imports[] = $className;
}
$imports[] = 'Authorization\\IdentityInterface';

$variable = Inflector::variable($name);
if ($variable === 'user') {
Expand All @@ -106,6 +110,7 @@ public function templateData(Arguments $arguments): array
'suffix' => $suffix,
'variable_name' => $variable,
'classname' => $className,
'imports' => $imports,
];

return $vars + $data;
Expand Down
10 changes: 10 additions & 0 deletions templates/bake/element/table_methods.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Apply user access controls to a query for index actions
*
* @param \Authorization\IdentityInterface $user The user.
* @param \Cake\ORM\SelectQuery $query The query to apply authorization conditions to.
* @return bool
*/
public function scopeIndex(IdentityInterface $user, SelectQuery $query): SelectQuery
{
}
6 changes: 2 additions & 4 deletions templates/bake/policy.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ declare(strict_types=1);
namespace {{ namespace }}\Policy;
{% set imports = [
'Authorization\\IdentityInterface',
classname,
] %}
{% for import in imports|sort %}
use {{ import }};
{% endfor %}
Expand All @@ -33,5 +29,7 @@ class {{ name }}{{ suffix }}Policy
{
{% if type == 'entity' %}
{{- _view.element('Authorization.entity_methods') -}}
{% elseif type == 'table' %}
{{- _view.element('Authorization.table_methods') -}}
{% endif %}
}
12 changes: 11 additions & 1 deletion tests/comparisons/BookmarksTablePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@
namespace TestApp\Policy;

use Authorization\IdentityInterface;
use TestApp\Model\Table\BookmarksTable;
use Cake\ORM\SelectQuery;

/**
* Bookmarks policy
*/
class BookmarksTablePolicy
{
/**
* Apply user access controls to a query for index actions
*
* @param \Authorization\IdentityInterface $user The user.
* @param \Cake\ORM\SelectQuery $query The query to apply authorization conditions to.
* @return bool
*/
public function scopeIndex(IdentityInterface $user, SelectQuery $query): SelectQuery
{
}
}
12 changes: 11 additions & 1 deletion tests/comparisons/TestPluginUsersTablePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@
namespace TestPlugin\Policy;

use Authorization\IdentityInterface;
use TestPlugin\Model\Table\UsersTable;
use Cake\ORM\SelectQuery;

/**
* Users policy
*/
class UsersTablePolicy
{
/**
* Apply user access controls to a query for index actions
*
* @param \Authorization\IdentityInterface $user The user.
* @param \Cake\ORM\SelectQuery $query The query to apply authorization conditions to.
* @return bool
*/
public function scopeIndex(IdentityInterface $user, SelectQuery $query): SelectQuery
{
}
}
1 change: 0 additions & 1 deletion tests/comparisons/ThingPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace TestApp\Policy;

use Authorization\IdentityInterface;
use TestApp\Thing;

/**
* Thing policy
Expand Down

0 comments on commit ed52f1a

Please sign in to comment.