Skip to content

Commit ed52f1a

Browse files
committed
Merge branch '3.next' into 3.x
2 parents 6e880cb + 956d612 commit ed52f1a

File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-7
lines changed

src/Command/PolicyCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,16 @@ public function templateData(Arguments $arguments): array
8888
$suffix = 'Table';
8989
}
9090

91+
$imports = [];
9192
$className = $data['namespace'] . '\\' . $name;
9293
if ($type === 'table') {
9394
$className = "{$data['namespace']}\Model\\Table\\{$name}{$suffix}";
95+
$imports[] = 'Cake\ORM\SelectQuery';
9496
} elseif ($type === 'entity') {
9597
$className = "{$data['namespace']}\Model\\Entity\\{$name}";
98+
$imports[] = $className;
9699
}
100+
$imports[] = 'Authorization\\IdentityInterface';
97101

98102
$variable = Inflector::variable($name);
99103
if ($variable === 'user') {
@@ -106,6 +110,7 @@ public function templateData(Arguments $arguments): array
106110
'suffix' => $suffix,
107111
'variable_name' => $variable,
108112
'classname' => $className,
113+
'imports' => $imports,
109114
];
110115

111116
return $vars + $data;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Apply user access controls to a query for index actions
3+
*
4+
* @param \Authorization\IdentityInterface $user The user.
5+
* @param \Cake\ORM\SelectQuery $query The query to apply authorization conditions to.
6+
* @return bool
7+
*/
8+
public function scopeIndex(IdentityInterface $user, SelectQuery $query): SelectQuery
9+
{
10+
}

templates/bake/policy.twig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ declare(strict_types=1);
1818
1919
namespace {{ namespace }}\Policy;
2020
21-
{% set imports = [
22-
'Authorization\\IdentityInterface',
23-
classname,
24-
] %}
2521
{% for import in imports|sort %}
2622
use {{ import }};
2723
{% endfor %}
@@ -33,5 +29,7 @@ class {{ name }}{{ suffix }}Policy
3329
{
3430
{% if type == 'entity' %}
3531
{{- _view.element('Authorization.entity_methods') -}}
32+
{% elseif type == 'table' %}
33+
{{- _view.element('Authorization.table_methods') -}}
3634
{% endif %}
3735
}

tests/comparisons/BookmarksTablePolicy.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@
44
namespace TestApp\Policy;
55

66
use Authorization\IdentityInterface;
7-
use TestApp\Model\Table\BookmarksTable;
7+
use Cake\ORM\SelectQuery;
88

99
/**
1010
* Bookmarks policy
1111
*/
1212
class BookmarksTablePolicy
1313
{
14+
/**
15+
* Apply user access controls to a query for index actions
16+
*
17+
* @param \Authorization\IdentityInterface $user The user.
18+
* @param \Cake\ORM\SelectQuery $query The query to apply authorization conditions to.
19+
* @return bool
20+
*/
21+
public function scopeIndex(IdentityInterface $user, SelectQuery $query): SelectQuery
22+
{
23+
}
1424
}

tests/comparisons/TestPluginUsersTablePolicy.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@
44
namespace TestPlugin\Policy;
55

66
use Authorization\IdentityInterface;
7-
use TestPlugin\Model\Table\UsersTable;
7+
use Cake\ORM\SelectQuery;
88

99
/**
1010
* Users policy
1111
*/
1212
class UsersTablePolicy
1313
{
14+
/**
15+
* Apply user access controls to a query for index actions
16+
*
17+
* @param \Authorization\IdentityInterface $user The user.
18+
* @param \Cake\ORM\SelectQuery $query The query to apply authorization conditions to.
19+
* @return bool
20+
*/
21+
public function scopeIndex(IdentityInterface $user, SelectQuery $query): SelectQuery
22+
{
23+
}
1424
}

tests/comparisons/ThingPolicy.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
namespace TestApp\Policy;
55

66
use Authorization\IdentityInterface;
7-
use TestApp\Thing;
87

98
/**
109
* Thing policy

0 commit comments

Comments
 (0)