AccessPolicy class

Maps named features to the minimum MembershipTier required to access them.

Define the policy once at startup and consult it wherever access-control decisions are needed:

final policy = AccessPolicy();
policy.define('export_pdf',  MembershipTier.pro);
policy.define('sso',         MembershipTier.enterprise);

// Check a specific user's tier:
if (policy.canAccess('export_pdf', userTier)) {
  exportToPdf();
}

// List everything a pro user can do:
final features = policy.featuresAvailableTo(MembershipTier.pro);

Constructors

AccessPolicy()
Creates an empty policy. Features must be defined before querying.

Properties

allDefinedFeatures List<String>
Returns all explicitly defined feature names.
no setter
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Whether the policy has no defined features.
no setter
length int
The number of features defined in this policy.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
snapshot Map<String, MembershipTier>
Returns a copy of the underlying policy map (immutable snapshot).
no setter

Methods

canAccess(String featureName, MembershipTier userTier) bool
Returns true if userTier meets or exceeds the required tier for featureName.
clear() → void
Removes all defined features (useful in tests).
define(String featureName, MembershipTier requiredTier) → void
Registers featureName as requiring at least requiredTier for access.
defineAll(Map<String, MembershipTier> definitions) → void
Registers multiple definitions at once.
featuresAvailableTo(MembershipTier tier) List<String>
Returns all feature names that tier can access given this policy, including features that are open (undefined) would need to be known externally — this method returns only explicitly defined features that tier qualifies for.
featuresLockedFor(MembershipTier tier) List<String>
Returns all feature names that tier cannot access.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
requiredTierFor(String featureName) MembershipTier?
Returns the minimum MembershipTier required to access featureName, or null if the feature is not in the policy (open access).
toString() String
A string representation of this object.
inherited
undefine(String featureName) → void
Removes a previously defined feature from the policy.

Operators

operator ==(Object other) bool
The equality operator.
inherited