feat: implement permission validation API and hooks for frontend-authz - #3
Open
bra-i-am wants to merge 1 commit into
Open
feat: implement permission validation API and hooks for frontend-authz#3bra-i-am wants to merge 1 commit into
bra-i-am wants to merge 1 commit into
Conversation
bra-i-am
force-pushed
the
bc/port-authz-implementation
branch
from
July 30, 2026 21:06
b09c14f to
f6c9fde
Compare
bra-i-am
force-pushed
the
bc/port-authz-implementation
branch
from
July 30, 2026 21:09
f6c9fde to
ea46dc9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
This PR implements the
@openedx/frontend-authzstandalone package, proposed in openedx/frontend-base#269 (comment) as the solution to openedx/frontend-base#150.The original implementation was ported from openedx/frontend-base#269, which added permission-validation hooks directly into
frontend-base. During review, it was proposed that these utils should live in a standalone package instead, so both MFEs still onfrontend-platform/frontend-buildand those migrated tofrontend-basecan consume the authz utilities without introducing cross-dependencies between base libraries.What's added
src/types.tsPermissionValidationRequestItem— shape of a single permission check sent to the backend (action,scope)PermissionValidationResponseItem— same shape coming back, plusallowed: booleanPermissionValidationQuery— the key/value map the caller builds ({ canEdit: { action: '...', scope: '...' } })PermissionValidationAnswer<Query>— maps every key from the caller's query to a booleansrc/api.tsPERMISSIONS_VALIDATE_PATH— endpoint path constantvalidatePermissions(apiBaseUrl, query)— POSTs to/api/authz/v1/permissions/validate/me, maps response back to caller keys; missing keys default tofalsesrc/hooks.tspermissionsQueryKeys— stable TanStack Query cache key factory for deduplication and invalidationusePermissions(query, featureEnabled, options?)— React hook; whenfeatureEnabledisfalseit skips the API call and returns all keys astrue(gradual rollout safe); whentrueit calls the authz API and spreads permission keys at the top level alongsideisLoading,isError, andisAuthzEnableddocs/how_tos/permissions.md— usage, caching, MFE-level wrapper pattern, best practices, and cache invalidation. Includes a reference to the full list of available actions and scopes..github/workflows/ci.yml— removed thei18n_extractstep inherited from the template;frontend-authzis a headless utility library with no translatable UI strings.How to test locally
This package uses
frontend-build'smodule.config.jsfor local development, which resolves the package directly from source without requiring a build step.1. Clone this repo next to the consuming MFE
# peer directory of frontend-app-authoring git clone https://github.com/bra-i-am/frontend-authz-test frontend-authz2. Configure
module.config.jsin the consuming MFEIn
frontend-app-authoring/module.config.js:3. Wrap
usePermissionsin an MFE-level hookA working integration can be found in
eduNEXT/frontend-app-authoringbranchbc/generalize-authz-validation.4. Verify at runtime
authz.enable_course_authoringin Django adminvalidate/api/authz/v1/permissions/validate/meWhen the flag is off, no request should appear and all permissions default to
true.LLM usage notice
Built with assistance from Claude.