Skip to main content

Groups

Every set of members is a Group node, with an additional label for its kind.

LabelKind
ProfileGroupMembers of one profile within an organization or a class. Created automatically.
FunctionalGroupGroups that reflect how the organization works: management, administrative staff, lead instructors
FunctionGroupMembers who hold a function in an organization, such as its administrators
ManualGroupGroups created and maintained by hand
ManualGroup used as a broadcast listA manual group whose members are filled automatically from other groups or organizations

Profile groups​

Members belong to profile groups.

  • A profile group depends on an organization or on a class (DEPENDS).
  • A class belongs to an organization (BELONGS).
  • A profile group carries one profile: Teacher, Personnel, Student or Relative (HAS_PROFILE).

Creating the profiles:

CREATE (p:Profile {externalId: "PROFILE_TEACHER", name: "Teacher"});
CREATE (p:Profile {externalId: "PROFILE_PERSONNEL", name: "Personnel"});
CREATE (p:Profile {externalId: "PROFILE_STUDENT", name: "Student"});
CREATE (p:Profile {externalId: "PROFILE_RELATIVE", name: "Relative"});

Linking a profile group to its profile and to its organization:

:params {
structureId: 'b3380c81-e5c7-49fa-9058-a5afce4cd1ea',
profileName: 'Teacher',
profileGroupName: 'Teacher Group'
}

MATCH (pg:ProfileGroup { name: $profileGroupName })
MERGE (p:Profile { name: $profileName })
CREATE (pg)-[:HAS_PROFILE]->(p);

MATCH (s:Structure { id: $structureId })
MATCH (pg:ProfileGroup { name: $profileGroupName })
CREATE (pg)-[:DEPENDS]->(s);

Removing the link to the organization:

MATCH (a:ProfileGroup { name: $profileGroupName })-[r:DEPENDS]->(b:Structure { id: $structureId })
DELETE r;

Functional groups​

Functional groups include the management team, the administrative staff and the lead instructors of classes (HeadTeacher).

Function groups​

The main function group is the one that holds the administrators of an organization, AdminLocal.

These groups are not created by hand. They are generated when a function is granted: User.addFunction creates one per organization in the scope of the function, with the externalId <structureId>-<functionCode> and the name <structure>-<functionName>. Application roles are attached to these groups; the function alone grants nothing. Granting a function over a network of 200 organizations therefore produces 200 function groups.

Details of the groups​

This query returns each group with its organizations and classes, its labels, its communication rule and its number of members, and derives a subtype:

MATCH (s:Structure)<-[:BELONGS*0..1]-()<-[:DEPENDS]-(g:Group)
OPTIONAL MATCH (g)-[:DEPENDS]->(c:Class)
WITH g,
collect({name: c.name, id: c.id}) as classes,
collect(distinct {name: s.name, id: s.id}) as structures,
head([x IN labels(g) WHERE x <> 'Visible' AND x <> 'Group']) as type
RETURN DISTINCT g.id as id,
g.name as name,
g.displayName as displayName,
g.filter as filter,
labels(g) as labels,
type,
g.users as internalCommunicationRule,
g.lockDelete AS lockDelete,
coalesce(g.nbUsers, 0) as nbUsers,
CASE WHEN any(x IN classes WHERE x.name IS NOT NULL AND x.id IS NOT NULL) THEN classes END as classes,
CASE WHEN any(x IN structures WHERE x.name IS NOT NULL AND x.id IS NOT NULL) THEN structures END as structures,
CASE
WHEN (g:ProfileGroup)-[:DEPENDS]-(:Structure) THEN 'StructureGroup'
WHEN (g:ProfileGroup)-[:DEPENDS]->(:Class) THEN 'ClassGroup'
WHEN EXISTS(g.subType) THEN g.subType
WHEN (g:ManualGroup) AND (
g.autolinkTargetAllStructs = true OR
size(coalesce(g.autolinkUsersFromGroups, [])) > 0 OR
size(coalesce(g.autolinkTargetStructs, [])) > 0
) THEN 'BroadcastGroup'
END as subType;

Members of a group​

MATCH (g:Group { id: $groupId })
MATCH (u:User)-[:IN]->(g)
RETURN u

Adding a member to a group​

MATCH (u:User { id: $userId }), (f:Group { id: $groupId })
WHERE 'ManualGroup' IN labels(f) OR 'FunctionalGroup' IN labels(f)
MERGE (u)-[:IN { source: 'MANUAL' }]->(f)
WITH f, u
WHERE 'FunctionalGroup' IN labels(f)
SET u.groups = [gId IN coalesce(u.groups, []) WHERE gId <> f.externalId] + f.externalId

Step by step:

  1. The member and the group are found by their identifiers.
  2. Only manual and functional groups are accepted.
  3. MERGE creates the IN relationship if it does not exist, marked source: 'MANUAL', so that adding the same member twice changes nothing.
  4. For a functional group only, the groups property of the member is updated: the external identifier of the group is removed if present, then appended, which keeps the list free of duplicates.

For a member whose groups is ["G1", "G2"] added to a functional group with the external identifier G3, the relationship is created and groups becomes ["G1", "G2", "G3"].