Skip to content

Commit

Permalink
Initial docs for sync assignment functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyel committed Feb 29, 2024
1 parent 6c15450 commit 0746f70
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/cloud-functions/create-new-family.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Hosted on: Admin Firebase Project

Trigger:
Trigger: HTTPs Callable
2 changes: 1 addition & 1 deletion docs/cloud-functions/create-student-account.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Hosted on: Admin Firebase Project

Trigger:
Trigger: HTTPs Callable
10 changes: 10 additions & 0 deletions docs/cloud-functions/sync-assignment-created.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@
Hosted on: Admin Firebase Project

Trigger: `document.created` on `/users/{userId}/assignments/{assignmentId}`

This function will trigger when an assignment is created in a user's assignments subcollection. It serves to update all the places where the assignment is being listed and counted, namely the user's assignments object in the `/users/{userId}` document and the administration's stats document.

When an assignment is created, the function will update the user's `assignmentsAssigned` object with the new assignment ID.

The function will also update the administration's stats document at `/administrations/{administrationId}/stats/completion`. This document keeps track of the number of students who have have been assigned, started, and completed the assignment. This function will update both the total number of students assigned, as well as the number of students from the user's particular organization that have been assigned the administration.

::: tip
The document IDs in the `/users/{userId}/assignments` collection will always match with the administration they refer to, so when a new file is created we can assume that it is a new assignment to the user.
:::
12 changes: 11 additions & 1 deletion docs/cloud-functions/sync-assignment-deleted.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@

Hosted on: Admin Firebase Project

Trigger:
Trigger: `document.deleted` on `/users/{userId}/assignments/{assignmentId}`

This function will trigger when an assignment is deleted in a user's assignments subcollection. It serves to update all the places where the assignment is being listed and counted, namely the user's assignments object in the `/users/{userId}` document and the administration's stats document.

When an assignment is deleted, the function will update the user's `assignmentsAssigned` object to remove the assignment ID if found.

The function will also update the administration's stats document at `/administrations/{administrationId}/stats/completion` to no longer count this student. This document keeps track of the number of students who have have been assigned, started, and completed the assignment. This function will update both the total number of students assigned, as well as the number of students from the user's particular organization that have been assigned the administration.

::: tip
The document IDs in the `/users/{userId}/assignments` collection will always match with the administration they refer to, so when a new file is created we can assume that it is a new assignment to the user.
:::
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
Hosted on: Admin Firebase Project

Trigger: `document.written` on `administrations/{administrationId}`

This function is designed to sync globally defined adminstrations with user-specific assignments.

Administrations are globally defined, while assignments are specific to each user. This function determines all assigned users and syncs the globally defined adminstration data with their local assignment data.

It also checks to see that the list of assigned orgs is exhaustive. By "exhaustive," we mean that any organization in the administration's org list must have each of it's dependent organizations explicitly listed in the same administration's org list. For example, if district1 is in the `districts` list and district1 contains schools A and B. Then schools A and B should also be in the `schools` list of the administration. Likewise if school A contains classes alpha and beta, then classes alpha and beta should also be in the administration's `classes` list. This function ensures that org lists are exhaustive. Because this function both writes to and is triggered by changes to the administration document, we check to prevent infinite loops where document change -> function trigger -> document change, and so on.
4 changes: 4 additions & 0 deletions docs/cloud-functions/sync-assignments-on-user-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
Hosted on: Admin Firebase project

Trigger: `document.written` on `/users/{userId}`

This function is designed to sync globally defined administrations with user-sepcific assignments.

This function will trigger when user documents (`/user/{userId}`) are written to. This function will perform actions only on documents with the userType field set to `student`. If so, the function will check the user's organizations. If they've changed, the function will add or remove assignments corresponding to the changed organizations. For example, if the user is assigned an administration from school1, then is removed from school1, this function will trigger, detect that removal, and remove the assignment that was assigned to school1. Similarly, if the user was not originally assigned to school1 then added to the organization, this function will trigger and add the assignment to the user's `/user/{userId}/assignments` subcollection.
11 changes: 7 additions & 4 deletions docs/workflows/assignment-creation.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tags: Array of metadata tags for this administration
administrationId: Optional ID of an existing administration. If provided, this function will update an existing administration.
```

This function will create a new administration document in the `/administrations/` collection in the [Admin Database](/databases/admin). The fields `createdBy` and `dateCreated` will be populated automatically with the calling user's roarUid and the current date respectively. Other feilds will be filled in with the given values from the function's input.
This function will create a new administration document in the `/administrations/` collection in the [Admin Database](../databases/admin.md). The fields `createdBy` and `dateCreated` will be populated automatically with the calling user's roarUid and the current date respectively. Other feilds will be filled in with the given values from the function's input.

When the `administrationId` is provided, this function will update an existing administration document matching the id.

Expand All @@ -35,7 +35,10 @@ An administration that is already in progress is unable to be edited.

Assignments are assigned to users via organizations. When an administration is created, it will be assigned to all users in the organizations that are specified. They are assigned exaustively. For example, if a student belongs to a school with a parent district, administrations assigned to that parent district will also be assigned to that student.

Administration: A master copy of an administration. This stores information about administration specifics such as parameters for variants, assigned organizations, group level statistics, et cetera.
Assignment: A local copy of an adminstration, specific to each user. Assignments are stored in individual user's subcollection `/user/{userId}/assignments/{administrationId}`. Refers to information about the individual student's progress, runIds, et cetera.
::: tip
In this context, an **administration** is a master copy of an administration. This stores information about administration specifics such as parameters for variants, assigned organizations, group level statistics, et cetera. An **assignment** is a local copy of an adminstration, specific to each user. Assignments are stored in individual user's subcollection `/user/{userId}/assignments/{administrationId}`. Refers to information about the individual student's progress, runIds, et cetera.
:::

Once the firekit function has run and the administration document is created, the cloud function [`syncAssignmentsOnAdministrationUpdate`](../sync-assignments-on-administration-update.md) will fire. This cloud function triggers anytime a document in the `/administrations/{administrationId}` collection is written to. The function will sync user's assignments with the updated administration. If the assignment is being updated, every user assignment document will be updated with the new information. If it is a new administration, it will create a new document in the user's assignments subcollection.

This assignment is handled automatically by the firekit functions `syncAssignmentsOnAdministrationUpdate`, `syncAssignmentsOnUserUpdate`, and `syncAssignmentsCreated`.
If the assignment document had to be created, the [`syncAssignmentCreated`](../cloud-functions/sync-assignment-created.md) function will fire. This will update the administration's stats collection, as well as syncing the user's `assignedAssignments` object in the `/users/{userId}` document.
2 changes: 2 additions & 0 deletions docs/workflows/authentication.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Authentication

Documentation under contruction.

0 comments on commit 0746f70

Please sign in to comment.