Automatically set the stocktake permission if a user can already add and withdraw from a lot

This commit is contained in:
Jan Böhmer
2026-02-10 23:24:40 +01:00
parent 3c87fe0932
commit 35598df354
2 changed files with 17 additions and 1 deletions

View File

@@ -43,7 +43,7 @@ final class PermissionData implements \JsonSerializable
/**
* The current schema version of the permission data
*/
public const CURRENT_SCHEMA_VERSION = 3;
public const CURRENT_SCHEMA_VERSION = 4;
/**
* Creates a new Permission Data Instance using the given data.

View File

@@ -157,4 +157,20 @@ class PermissionSchemaUpdater
$permissions->setPermissionValue('system', 'show_updates', $new_value);
}
}
private function upgradeSchemaToVersion4(HasPermissionsInterface $holder): void //@phpstan-ignore-line This is called via reflection
{
$permissions = $holder->getPermissions();
//If the reports.generate permission is not defined yet, set it to the value of reports.read
if (!$permissions->isPermissionSet('parts_stock', 'stocktake')) {
//Set the new permission to true only if both add and withdraw are allowed
$new_value = TrinaryLogicHelper::and(
$permissions->getPermissionValue('parts_stock', 'withdraw'),
$permissions->getPermissionValue('parts_stock', 'add')
);
$permissions->setPermissionValue('parts_stock', 'stocktake', $new_value);
}
}
}