new AccessRule(dataopt)
Create an AccessRule instance. Accepts both the canonical
`{ subjects, permissions }` shape and the legacy
`collections/AccessPolicy` AccessRule shape
(`{ subject, read, write, changePermission }`), so legacy access-policy
editing UIs can round-trip through the typed model.
Parameters:
| Name |
Type |
Attributes |
Description |
data |
object
|
<optional>
|
Initial access rule values.
Properties
| Name |
Type |
Attributes |
Description |
subjects |
Array.<string>
|
<optional>
|
Subjects granted access. |
permissions |
Array.<string>
|
<optional>
|
Granted permissions. |
subject |
string
|
<optional>
|
Legacy single-subject form |
read |
boolean
|
<optional>
|
Legacy read permission flag |
write |
boolean
|
<optional>
|
Legacy write permission flag |
changePermission |
boolean
|
<optional>
|
Legacy changePermission flag |
|
- Source:
Members
changePermission
Whether the rule grants change-permission access.
- Source:
read
Whether the rule grants read access.
- Source:
subject
Return the first subject in the rule.
- Source:
write
Whether the rule grants write access.
- Source:
Methods
hasPermissions() → {boolean}
- Source:
Returns:
`true` when the rule has at least one permission.
-
Type
-
boolean
hasSubject() → {boolean}
- Source:
Returns:
`true` when the rule has at least one subject.
-
Type
-
boolean
isAuthorized(actionopt, subjectopt) → {boolean}
Check whether this rule grants the requested action to a subject.
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
action |
"read"
|
"write"
|
"changePermission"
|
<optional>
|
write
|
Permission to check |
subject |
string
|
Array.<string>
|
null
|
<optional>
|
null
|
Subject or candidate subjects
Defaults to `public` when omitted. |
- Source:
Returns:
`true` when a matching subject has the requested
permission directly or through the DataONE permission hierarchy.
-
Type
-
boolean
isEmpty() → {boolean}
- Source:
Returns:
`true` when the rule lacks a subject or permissions.
-
Type
-
boolean
toElement(doc) → {Element|null}
Serialize the access rule to an `allow` XML element.
Parameters:
| Name |
Type |
Description |
doc |
XMLDocument
|
XML document used to create elements. |
- Source:
Returns:
Serialized XML element, or `null` when empty.
-
Type
-
Element
|
null
toJSON() → {object}
Return a JSON-serializable representation of the access rule.
- Source:
Returns:
Plain access rule data.
-
Type
-
object
validate(pathopt) → {Array.<object>}
Validate the access rule state.
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
path |
string
|
<optional>
|
accessPolicy
|
Base path used in validation errors. Defaults to
`accessPolicy`. |
- Source:
Returns:
Validation errors for invalid fields.
-
Type
-
Array.<object>
fromElement(element) → {AccessRule}
Create an AccessRule from an `allow` XML element.
Parameters:
| Name |
Type |
Description |
element |
Element
|
XML element to parse. |
- Source:
Returns:
Parsed access rule instance.
-
Type
-
AccessRule
getSubjectInfo()
Gets and sets the subject info for the subjects in this access policy.
- Source:
isGroup() → {boolean}
Returns true if the subbject set on this AccessRule is for a group of people.
- Source:
Returns:
-
Type
-
boolean
parse(accessRuleXML) → {JSON}
Translates the access rule XML DOM into a JSON object to be set on the model.
Parameters:
| Name |
Type |
Description |
accessRuleXML |
Element
|
An DOM element that contains a single access rule |
- Source:
Returns:
The Access Rule values to be set on this model
-
Type
-
JSON
parse(element, parseWarningsopt, pathopt) → {AccessRule|null}
Parse an `allow` XML element, dropping it when invalid.
Unknown child nodes and ordering issues are ignored silently.
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
element |
Element
|
null
|
|
|
XML element to parse. |
parseWarnings |
Array.<object>
|
<optional>
|
|
Lossy parse warnings. |
path |
string
|
<optional>
|
accessPolicy
|
Field path used in warnings and validation. |
- Source:
Returns:
Parsed access rule or null when invalid.
-
Type
-
AccessRule
|
null
serialize() → {object}
Takes the values set on this model's attributes and creates an XML string
to be inserted into a DataONEObject's system metadata access policy.
- Source:
Returns:
The access rule XML object or null if not created
-
Type
-
object