Skip to main content

Functions

A function is a cross-cutting responsibility given to a member, distinct from their profile. It answers the question: what may this person administer, and where?

The distinction matters because the directory knows only five profiles: Teacher, Personnel, Student, Relative and Guest. Any population that does not reduce to one of them is modeled with a function.

Built-in functions​

Code (externalId)nameCarried by profileRole
SUPER_ADMINSuperAdminNonePlatform administrator, global scope
ADMIN_LOCALAdminLocalPersonnelAdministrator of one or more organizations
CLASS_ADMINClassAdminTeacherAdministrator of one class

Further functions can be created for populations that the profiles do not distinguish, such as the staff of a supervising authority or the staff of the operator. From the directory's point of view both are plain Personnel; a function is the durable, queryable way to tell them apart.

Structure of the node​

A Function node is attached to a Profile by COMPOSE, and to a member by HAS_FUNCTION.

(:Profile)<-[:COMPOSE]-(:Function)<-[:HAS_FUNCTION]-(:User)
PropertyDescription
externalIdCode of the function, such as ADMIN_LOCAL. This is the matching key.
idTechnical identifier
nameLabel, used to name the function groups that are generated

Scope​

The HAS_FUNCTION relationship carries a scope property: the list of identifiers of the organizations where the function applies. SUPER_ADMIN has none, since its scope is global.

When the function is granted (POST /directory/user/function/:userId), the inherit parameter decides how the scope is computed:

inheritEffect
emptyThe scope is exactly the list supplied
sThe scope is extended to all attached organizations, by following HAS_ATTACHMENT*0..
scAs s, plus the classes (BELONGS*0..1)

This is how a whole network is covered by naming only its parent organization.

The scope is fixed when the function is granted

inherit: "s" materializes the list of descendants at the time of the grant and writes it to the scope property. An organization attached to the parent afterwards is not in it.

The AdmlOfStructures check with inherit=true requires that all descendants be in the scope. A single missing child makes the whole check fail, and the member loses access to the parent as well. Realign the scope after each attachment by granting the function again: the queries of addFunction use MERGE, so repeating the grant is safe.

From function to effective rights​

A function alone grants no right. It serves two purposes: the security filters that query it directly, such as AdmlOfStructures and AdminFilter, and the generation of groups, which are what carry rights.

When a function is granted with a scope, User.addFunction creates one function group per organization in the scope:

MERGE (fg:Group:FunctionGroup { externalId : s.id + '-' + {functionCode}})
ON CREATE SET fg.name = s.name + '-' + f.name, fg.filter = f.name
CREATE UNIQUE s<-[:DEPENDS]-fg<-[:IN {source:'MANUAL'}]-u

Application rights are then attached to these groups, through roles:

Over a network of 200 organizations, one grant produces 200 function groups. Since roles are assigned group by group, assigning them must be scripted.

Queries​

All functions and the profile that carries them:

MATCH (p:Profile)<-[:COMPOSE]-(f:Function)
RETURN p.name AS profile, f.externalId AS code, f.name AS name
ORDER BY f.externalId

All organization administrators:

MATCH (u:User)-[:HAS_FUNCTION]->(f:Function)
WHERE f.name = "AdminLocal"
RETURN u.id AS userId, u.login AS login, f.name AS functionName

Scope of a member for a function:

MATCH (u:User {id: {userId}})-[rf:HAS_FUNCTION]->(f:Function {externalId: {code}})
RETURN f.externalId AS function, LENGTH(rf.scope) AS organizations, rf.scope AS scope

Effective rights brought by a function, to check that it grants neither more nor less than intended:

MATCH (u:User {id: {userId}})-[:IN]->(fg:FunctionGroup)-[:AUTHORIZED]->(r:Role)-[:AUTHORIZE]->(a:Action)
WHERE fg.externalId ENDS WITH {code}
RETURN DISTINCT r.name AS role, a.displayName AS action
ORDER BY role, action

Roots of a scope already granted. The scope holds only the flattened list; the original parent is not stored. It is found by taking the organizations of the scope that have no parent in the scope:

MATCH (u:User {id: {userId}})-[rf:HAS_FUNCTION]->(:Function {externalId: {code}})
WITH rf.scope AS scope
MATCH (s:Structure) WHERE s.id IN scope
OPTIONAL MATCH (s)-[:HAS_ATTACHMENT]->(p:Structure)
WITH scope, s, COLLECT(p.id) AS parents
WHERE NONE(pid IN parents WHERE pid IN scope)
RETURN COLLECT(s.id) AS roots

Attached organizations missing from a scope, which detects the functions to realign after an attachment:

MATCH (u:User)-[rf:HAS_FUNCTION]->(f:Function {externalId: {code}})
WITH u, f, rf.scope AS scope
MATCH (s:Structure) WHERE s.id IN scope
MATCH (s)<-[:HAS_ATTACHMENT]-(child:Structure)
WHERE NOT child.id IN scope
RETURN u.login AS member, COLLECT(DISTINCT child.name) AS outOfScope

Creating a function​

The node must be attached to a profile. Otherwise the grant does nothing and reports no error: addFunction looks the function up with an OPTIONAL MATCH and, if it is absent, attaches nothing.

MATCH (p:Profile {externalId: 'PROFILE_PERSONNEL'})
CREATE p<-[:COMPOSE]-(f:Function {externalId: 'ADMIN_AUTHORITY', id: 'admin-authority', name: 'Authority'})
RETURN f.id AS id

This mirrors Profile.createFunction in the feeder module, which creates ADMIN_LOCAL under Personnel and CLASS_ADMIN under Teacher the same way.

The function is then granted through the standard API, with no change to the core: AddFunctionFilter accepts any non-empty code other than SUPER_ADMIN, provided the caller administers the requested scope.

POST /directory/user/function/:userId
{ "functionCode": "ADMIN_AUTHORITY", "scope": ["<parent-structure-id>"], "inherit": "s" }
Choose the role with care

The levels shipped by the modules, such as read, manage and administer, do not always match the need: a level can lack one action you want, while the next one up adds write access you do not. A custom role (POST /appregistry/role) is often better than the nearest level. Always check the result with the effective rights query above.