fix(public-dashboard): Improve ensurePublicContext in public-dashboards (#17533) - #17534
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the opencti-graphql public dashboard widget execution context to compute user_inside_platform_organization based on the dashboard creator’s organization membership and platform settings, instead of forcing it to true.
Changes:
- Fetches platform settings (
ENTITY_TYPE_SETTINGS) inensurePublicContext. - Computes
context.user_inside_platform_organizationusingisUserInPlatformOrganization(user, settings)for public dashboard widget queries.
Suppressed comments (1)
opencti-platform/opencti-graphql/src/modules/publicDashboard/publicDashboard-domain.ts:335
- This change alters authorization behavior for public dashboard widget queries by recomputing
user_inside_platform_organizationfrom settings + user orgs, but there is no test asserting the behavior for a user outside the platform organization (e.g., platform org configured and dashboard creator not a member). Adding an integration test around a public dashboard query would prevent regressions.
const settings = await getEntityFromCache<BasicStoreSettings>(context, SYSTEM_USER, ENTITY_TYPE_SETTINGS);
context.user_inside_platform_organization = isUserInPlatformOrganization(user, settings);
| const settings = await getEntityFromCache<BasicStoreSettings>(context, SYSTEM_USER, ENTITY_TYPE_SETTINGS); | ||
| context.user_inside_platform_organization = isUserInPlatformOrganization(user, settings); |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #17534 +/- ##
==========================================
+ Coverage 34.11% 35.01% +0.90%
==========================================
Files 3376 3387 +11
Lines 137662 141265 +3603
Branches 37258 38889 +1631
==========================================
+ Hits 46963 49469 +2506
- Misses 90699 91796 +1097
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| vi.mock('../../../../src/database/redis', () => ({ notify: vi.fn() })); | ||
|
|
||
| vi.mock('../../../../src/database/cache', () => ({ getEntitiesMapFromCache: vi.fn() })); | ||
| vi.mock('../../../../src/database/cache', () => ({ |
There was a problem hiding this comment.
One small question on this test update: since the mock returns platform_organization: null , isUserInPlatformOrganization would return true regardless of the user's org membership.. just mentioning it because this test would pass even without the fix. Would it be possible to add a case with platform_organization set and a user who isn't a member, to confirm user_inside_platform_organization resolves to false ?
There was a problem hiding this comment.
I have added a dedicated unit test for isUserInPlatformOrganization covering a non-member user with platform_organization set, which resolves to false as expected. Kept it in a separate file since the distribution tests go through ensurePublicContext, which hardcodes the flag and can't exercise that logic anyway.
Proposed changes
Related issues
How to test this PR
Checklist
Further comments