Member Junction
    Preparing search index...

    Class AuthorizationEvaluator

    Centralised utility for evaluating MemberJunction authorization rules.

    MemberJunction authorizations form a parent → child tree (e.g. "Schema Management" → "Create Entities" → "Create in UDT Schema"). Granting a parent authorization to a role implicitly covers every descendant operation — see UserCanExecuteWithAncestors.

    Prefer UserCanExecuteWithAncestors for feature-gate checks so that administrators can grant access at whatever granularity fits their policy (root "Schema Management" for all database-designer ops, or a specific leaf for finer control). Use the plain UserCanExecute only when you explicitly need to verify a direct grant with no hierarchy traversal.

    Authorizations and CurrentUser are per-provider state, so methods that need the provider accept an optional provider parameter that takes precedence over the global Metadata.Provider. Pass the provider explicitly when running in multi-provider client setups (parallel server connections); single-provider apps can omit it and rely on the global default.

    Index

    Constructors

    Methods

    • Determines if the current user can execute the given authorization, checking the authorization itself AND every ancestor up the hierarchy.

      Granting "Schema Management" to a role therefore covers all descendant operations such as "Create in UDT Schema".

      Client-side only. On the server, Metadata.CurrentUser is a global singleton — it does not reflect the per-request user context. Use UserCanExecuteWithAncestors with an explicit user parameter instead.

      Throws if no current user is set.

      Parameters

      • auth: AuthorizationInfo

        The authorization to check (typically a leaf/child node).

      • Optionalprovider: IMetadataProvider

        Optional metadata provider whose CurrentUser to evaluate against. Falls back to Metadata.Provider.

      Returns boolean

      true if the current user has auth or any ancestor auth.

    • Determines if user can execute auth by walking up the parent chain.

      The check succeeds if the user has a direct role match on auth, or on any ancestor (parent, grandparent, …). This respects the MemberJunction convention that "users must have this authorization or a parent" to access a feature — granting a broader parent implicitly covers children.

      A visited-set guards against malformed circular parent references.

      Parameters

      • auth: AuthorizationInfo

        The authorization to check (start of the walk).

      • user: UserInfo

        The user whose roles are examined.

      • OptionalallAuthorizations: AuthorizationInfo[]

        Optional pre-fetched list; defaults to Metadata.Authorizations to avoid repeated singleton lookups in hot paths.

      Returns boolean

      true if the user passes the check at any level of the hierarchy.

      const evaluator = new AuthorizationEvaluator();
      const md = new Metadata();
      const auth = md.Authorizations.find(a => a.Name === 'Create in UDT Schema');
      // Returns true if user has 'Create in UDT Schema', 'Create Entities',
      // 'Schema Management', or any other ancestor.
      const allowed = evaluator.UserCanExecuteWithAncestors(auth, contextUser);