@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Tempo\Purchasing\Delivery;
|
||||
|
||||
require_once __DIR__.'/NativeAccessCatalogue.php';
|
||||
|
||||
/** Builds a review overlay; never writes to the source host. */
|
||||
final class AccessOverlay
|
||||
{
|
||||
@@ -24,6 +26,11 @@ final class AccessOverlay
|
||||
'purchasing_budget.reinforcement.propose', 'purchasing_budget.reinforcement.review',
|
||||
];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
return self::LABELS + NativeAccessCatalogue::UNIT;
|
||||
}
|
||||
|
||||
public static function prepare(string $host): array
|
||||
{
|
||||
$paths = ['app/Modules/Identity/Services/Permissions.php', 'app/Modules/Identity/Services/IdentityWorkflow.php'];
|
||||
@@ -32,8 +39,10 @@ final class AccessOverlay
|
||||
$source = file_get_contents($host.'/'.$path);
|
||||
$before = hash('sha256', $source);
|
||||
if (str_ends_with($path, '/Permissions.php')) {
|
||||
$source = self::replace($source, "public const UNIT = ['unit.view', 'unit.edit'];", 'public const UNIT = '.var_export(['unit.view', 'unit.edit', ...self::RIGHTS], true).';');
|
||||
$source = self::replace($source, "public const UNIT = ['unit.view', 'unit.edit'];", 'public const UNIT = '.var_export(array_values(array_unique(['unit.view', 'unit.edit', ...self::RIGHTS, ...array_keys(NativeAccessCatalogue::UNIT)])), true).';');
|
||||
$source = self::replace($source, 'public const COMPANY = ', 'public static function companyCatalogue(): array { return [...self::COMPANY, ...'.var_export(NativeAccessCatalogue::COMPANY, true).']; }'."\n\n public const COMPANY = ");
|
||||
} else {
|
||||
$source = str_replace('Permissions::COMPANY', 'Permissions::companyCatalogue()', $source);
|
||||
// Expanding a catalogue must never expand creation-time grants.
|
||||
$source = self::replace($source, 'foreach (Permissions::UNIT as $permission)', "foreach (['unit.view', 'unit.edit'] as \$permission)");
|
||||
$source = self::replace($source,
|
||||
|
||||
Reference in New Issue
Block a user