@griddo/ax 12.8.5-rc.0 → 12.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/__tests__/hooks/users.test.tsx +36 -1
- package/src/hooks/users.tsx +18 -17
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griddo/ax",
|
|
3
3
|
"description": "Griddo Author Experience",
|
|
4
|
-
"version": "12.8.5
|
|
4
|
+
"version": "12.8.5",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
|
|
7
7
|
"Diego M. Béjar <diego.bejar@secuoyas.com>",
|
|
@@ -201,5 +201,5 @@
|
|
|
201
201
|
"publishConfig": {
|
|
202
202
|
"access": "public"
|
|
203
203
|
},
|
|
204
|
-
"gitHead": "
|
|
204
|
+
"gitHead": "6dd8dc744531ea19a56ccf05bfcbbb908073fe5a"
|
|
205
205
|
}
|
|
@@ -4,7 +4,7 @@ import "@testing-library/jest-dom";
|
|
|
4
4
|
import * as reactRedux from "react-redux";
|
|
5
5
|
|
|
6
6
|
import { usePermissionsForPage } from "@ax/hooks";
|
|
7
|
-
import type { PageAccessGrantsSummary } from "@ax/types";
|
|
7
|
+
import type { IPageLanguage, PageAccessGrantsSummary } from "@ax/types";
|
|
8
8
|
|
|
9
9
|
import { renderHook } from "@testing-library/react";
|
|
10
10
|
|
|
@@ -388,4 +388,39 @@ describe("usePermissionsForPage hook", () => {
|
|
|
388
388
|
expect(result.current.edit).toBe(false);
|
|
389
389
|
});
|
|
390
390
|
});
|
|
391
|
+
|
|
392
|
+
describe("8. Drafts (sc-119759)", () => {
|
|
393
|
+
it("should not restrict a page missing from the translation group when user has no pagePermissions", () => {
|
|
394
|
+
// El draft nunca aparece en pageLanguages: el backend filtra draft_from_page IS NULL
|
|
395
|
+
const pageLanguages = [
|
|
396
|
+
{ pageId: 100, languageId: 1 },
|
|
397
|
+
{ pageId: 200, languageId: 2 },
|
|
398
|
+
] as unknown as IPageLanguage[];
|
|
399
|
+
setupMockState({ users: { currentUser: mockUser, roles: [mockRole] } });
|
|
400
|
+
|
|
401
|
+
const { result } = renderHook(() =>
|
|
402
|
+
usePermissionsForPage(1, 555, { edit: "edit_page" }, undefined, pageLanguages),
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
expect(result.current.edit).toBe(true);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
it("should keep denying a page missing from the group when user IS restricted by pagePermissions", () => {
|
|
409
|
+
const userWithPagePerms = {
|
|
410
|
+
...mockUser,
|
|
411
|
+
pagePermissions: [{ siteId: 1, pageIds: [100] }],
|
|
412
|
+
};
|
|
413
|
+
const pageLanguages = [
|
|
414
|
+
{ pageId: 100, languageId: 1 },
|
|
415
|
+
{ pageId: 200, languageId: 2 },
|
|
416
|
+
] as unknown as IPageLanguage[];
|
|
417
|
+
setupMockState({ users: { currentUser: userWithPagePerms, roles: [mockRole] } });
|
|
418
|
+
|
|
419
|
+
const { result } = renderHook(() =>
|
|
420
|
+
usePermissionsForPage(1, 555, { edit: "edit_page" }, undefined, pageLanguages),
|
|
421
|
+
);
|
|
422
|
+
|
|
423
|
+
expect(result.current.edit).toBe(false);
|
|
424
|
+
});
|
|
425
|
+
});
|
|
391
426
|
});
|
package/src/hooks/users.tsx
CHANGED
|
@@ -190,20 +190,24 @@ const usePermissionsForPage = <T extends Record<string, string | string[]>>(
|
|
|
190
190
|
return undefined;
|
|
191
191
|
};
|
|
192
192
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
193
|
+
// La restricción por grupo de traducción solo aplica a usuarios limitados por
|
|
194
|
+
// pagePermissions. Sin esa restricción el grupo no debe denegar nada: para un draft
|
|
195
|
+
// pageLanguages es el grupo de su página original —el backend resuelve el borrador a su
|
|
196
|
+
// original y filtra draft_from_page IS NULL—, así que su propio id nunca aparece ahí.
|
|
197
|
+
const hasAccessToTranslationGroup =
|
|
198
|
+
pageLanguages?.length && currentUser.pagePermissions?.length
|
|
199
|
+
? (() => {
|
|
200
|
+
const isPartOfGroup = pageLanguages.some((lang) => getLanguagePageId(lang) === pageId);
|
|
201
|
+
if (!isPartOfGroup) {
|
|
202
|
+
return false; // pageId is not in this translation group
|
|
203
|
+
}
|
|
199
204
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
205
|
+
// Get all pageIds in this translation group
|
|
206
|
+
const translationPageIds = pageLanguages
|
|
207
|
+
.map((lang) => getLanguagePageId(lang))
|
|
208
|
+
.filter((id): id is number => id !== undefined);
|
|
204
209
|
|
|
205
|
-
|
|
206
|
-
if (currentUser.pagePermissions?.length) {
|
|
210
|
+
// Check if user has access to ANY of the translation pageIds
|
|
207
211
|
const siteEntry = currentUser.pagePermissions.find(
|
|
208
212
|
(entry) => entry.siteId === siteId || entry.siteId === "global",
|
|
209
213
|
);
|
|
@@ -211,11 +215,8 @@ const usePermissionsForPage = <T extends Record<string, string | string[]>>(
|
|
|
211
215
|
return false;
|
|
212
216
|
}
|
|
213
217
|
return translationPageIds.some((translationPageId) => siteEntry.pageIds.includes(translationPageId));
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return true; // No pagePermissions restrictions, allow access
|
|
217
|
-
})()
|
|
218
|
-
: undefined;
|
|
218
|
+
})()
|
|
219
|
+
: undefined;
|
|
219
220
|
|
|
220
221
|
// If pageId is part of a translation group, use the translation group access result
|
|
221
222
|
const isPagePermissionRestricted =
|