Bump version to 1.4.6

This commit is contained in:
2026-07-22 01:26:04 +01:00
parent 370ec81c33
commit 9f08ccfea1
20 changed files with 363 additions and 163 deletions
+34 -7
View File
@@ -205,11 +205,17 @@ function getLegacyPermissionTargets(permissionKey) {
if (normalizedKey === 'screens.allow') {
return ['clients.allow'];
}
if (actionKey === 'edit') {
return [`${sectionKey}.update`];
}
if (actionKey === 'update') {
return [`${sectionKey}.update`];
}
if (actionKey === 'view') {
return [`${sectionKey}.read`];
}
if (actionKey === 'manage') {
return [`${sectionKey}.read`, `${sectionKey}.create`, `${sectionKey}.edit`, `${sectionKey}.delete`];
return [`${sectionKey}.read`, `${sectionKey}.create`, `${sectionKey}.update`, `${sectionKey}.delete`];
}
return [normalizedKey].filter(Boolean);
@@ -248,6 +254,14 @@ async function backfillLegacyRbacSchema(pool) {
JOIN permissions p ON p.id = rp.permission_id`
);
const permissionIdByKey = new Map();
for (const row of permissionRows || []) {
const currentKey = getPermissionKey(row);
if (currentKey) {
permissionIdByKey.set(currentKey, Number(row.id));
}
}
const rolePermissionTargets = new Map();
const desiredPermissionKeys = new Set(PERMISSIONS.map(function (permission) {
return permission.key;
@@ -268,7 +282,7 @@ async function backfillLegacyRbacSchema(pool) {
for (const row of rolePermissionRows || []) {
const currentKey = getPermissionKey(row);
const targetKeys = getLegacyPermissionTargets(currentKey);
if (currentKey.endsWith('.view') || currentKey.endsWith('.manage') || currentKey === 'screens.allow') {
if (currentKey.endsWith('.view') || currentKey.endsWith('.manage') || currentKey.endsWith('.edit') || currentKey === 'screens.allow') {
for (const targetKey of targetKeys) {
addRoleTarget(Number(row.role_id), targetKey);
}
@@ -279,8 +293,21 @@ async function backfillLegacyRbacSchema(pool) {
for (const row of permissionRows || []) {
const currentKey = getPermissionKey(row);
if (currentKey.endsWith('.view') || currentKey.endsWith('.manage') || currentKey === 'screens.allow') {
legacyPermissionRowIds.push(Number(row.id));
const permissionId = Number(row.id);
if (currentKey.endsWith('.edit')) {
const targetKey = currentKey.replace(/\.edit$/, '.update');
const targetPermissionId = permissionIdByKey.get(targetKey);
if (targetPermissionId) {
legacyPermissionRowIds.push(permissionId);
} else if (targetKey) {
await pool.query('UPDATE permissions SET permission_key = ? WHERE id = ?', [targetKey, permissionId]);
permissionIdByKey.delete(currentKey);
permissionIdByKey.set(targetKey, permissionId);
}
continue;
}
if (currentKey.endsWith('.view') || currentKey.endsWith('.manage') || currentKey.endsWith('.edit') || currentKey === 'screens.allow') {
legacyPermissionRowIds.push(permissionId);
}
}
@@ -353,11 +380,11 @@ async function backfillLegacyRbacSchema(pool) {
}
const [currentPermissionRows] = await pool.query('SELECT id, permission_key FROM permissions');
const permissionIdByKey = new Map();
const permissionIdByKeyAfterBackfill = new Map();
for (const row of currentPermissionRows || []) {
const currentKey = getPermissionKey(row);
if (currentKey) {
permissionIdByKey.set(currentKey, Number(row.id));
permissionIdByKeyAfterBackfill.set(currentKey, Number(row.id));
}
}
@@ -365,7 +392,7 @@ async function backfillLegacyRbacSchema(pool) {
for (const [roleId, permissionKeys] of rolePermissionTargets.entries()) {
const expandedPermissionKeys = normalizePermissionKeys(Array.from(permissionKeys.values()));
for (const permissionKey of expandedPermissionKeys) {
const permissionId = permissionIdByKey.get(permissionKey);
const permissionId = permissionIdByKeyAfterBackfill.get(permissionKey);
if (!permissionId) {
continue;
}