Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(api) Enrich incoming statements #410

Merged
merged 1 commit into from
Aug 30, 2023

Conversation

Leobouloc
Copy link
Contributor

@Leobouloc Leobouloc commented Aug 8, 2023

Purpose

The xAPI specification states that statements SHOULD or MUST be enriched with the following fields:

Currently, only the "id" field is being added. This PR aims improve compliance by enriching incoming statments with the fields above. Adding "authority" is also a necessary step to implement permissions.

Proposal

The main change besides enrichment is testing. Currently, tests check that incoming and retrieved statements are equal. The proposal changes this in an equivalency. Proposed equivalency between statements is defined as:

    To be equivalent, they must be identical on all fields not modified on input by the
    LRS and idententical on other fields when these fields are present in both
    statements. For example, if an "authority" field is present in only one statement,
    they may still be equivalent.
  • write and test an equivalency function
  • write enrichment functions for each field and add them to POST and PUT functions
  • adapt existing tests to test for equivalency
  • write tests for enrichment

NB: This proposal creates a new tests/helpers.py file for utilities common to multiple test files. We may refactor tests to include statement generation in this file (for example).

@Leobouloc Leobouloc force-pushed the feature/enrich-incoming-statements branch from b9fb2b1 to a803fe8 Compare August 8, 2023 14:29
@wilbrdt wilbrdt added this to the 4.0 milestone Aug 9, 2023
@wilbrdt wilbrdt requested review from SergioSim and wilbrdt August 9, 2023 07:22
Copy link
Contributor

@wilbrdt wilbrdt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alt text

src/ralph/api/routers/statements.py Show resolved Hide resolved
src/ralph/utils.py Outdated Show resolved Hide resolved
src/ralph/utils.py Outdated Show resolved Hide resolved
src/ralph/utils.py Outdated Show resolved Hide resolved
src/ralph/utils.py Outdated Show resolved Hide resolved
tests/test_helpers.py Outdated Show resolved Hide resolved
@Leobouloc Leobouloc force-pushed the feature/enrich-incoming-statements branch 3 times, most recently from a5293ad to 03ef116 Compare August 11, 2023 18:23
Copy link
Collaborator

@SergioSim SergioSim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nice!
Have only minor questions/suggestions)
Maybe we could include stored in the forwarded statements? WDYT?
Also, do we need to add the version field in the returned statements from a get request?
image

src/ralph/api/routers/statements.py Outdated Show resolved Hide resolved
src/ralph/api/routers/statements.py Outdated Show resolved Hide resolved
src/ralph/api/routers/statements.py Outdated Show resolved Hide resolved
src/ralph/api/routers/statements.py Outdated Show resolved Hide resolved
src/ralph/api/routers/statements.py Outdated Show resolved Hide resolved
src/ralph/api/routers/statements.py Outdated Show resolved Hide resolved
src/ralph/utils.py Outdated Show resolved Hide resolved
@Leobouloc Leobouloc force-pushed the feature/enrich-incoming-statements branch 2 times, most recently from e4a7538 to f1cdd67 Compare August 28, 2023 12:29
@Leobouloc
Copy link
Contributor Author

Also, do we need to add the version field in the returned statements from a get request?

Not sure I understand. Are you suggesting we remove this field if it is stored in a statement ?

@SergioSim
Copy link
Collaborator

Also, do we need to add the version field in the returned statements from a get request?

Not sure I understand. Are you suggesting we remove this field if it is stored in a statement ?

It's related to enriching outcoming statements (get request) with the version number, as in the spec:

Statements returned by an LRS MUST retain the version they are accepted with. If they lack a version, the version MUST be set to 1.0.0.

I think, we could add the version field prior statement storage, or, we could not enforce the storage of the version number and add it dynamically to the statements returned from a get request.

@Leobouloc
Copy link
Contributor Author

I think, we could add the version field prior statement storage, or, we could not enforce the storage of the version number and add it dynamically to the statements returned from a get request.

Mhmm, I'm not sure how to interpret the spec since the version parameter is marked as "Not Recommended" (here: https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#24-statement-properties).

@SergioSim
Copy link
Collaborator

I think, we could add the version field prior statement storage, or, we could not enforce the storage of the version number and add it dynamically to the statements returned from a get request.

Mhmm, I'm not sure how to interpret the spec since the version parameter is marked as "Not Recommended" (here: https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#24-statement-properties).

It's indeed not recommended for learning record providers to send statements containing the version field:

Learning Record Providers SHOULD NOT set the Statement version.

However, in my understanding, this doesn't contradict the LRS requirement to return statements with a version field.

@Leobouloc
Copy link
Contributor Author

Leobouloc commented Aug 28, 2023

I think, we could add the version field prior statement storage, or, we could not enforce the storage of the version number and add it dynamically to the statements returned from a get request.

Mhmm, I'm not sure how to interpret the spec since the version parameter is marked as "Not Recommended" (here: https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#24-statement-properties).

It's indeed not recommended for learning record providers to send statements containing the version field:

Learning Record Providers SHOULD NOT set the Statement version.

However, in my understanding, this doesn't contradict the LRS requirement to return statements with a version field.

I see. Then perhaps we can open a separate issue, as seems to be beyond the scope of the current PR.

EDIT: Issue opened here: #424

@Leobouloc Leobouloc force-pushed the feature/enrich-incoming-statements branch 2 times, most recently from 8a659df to 336b5ba Compare August 29, 2023 14:42
Copy link
Collaborator

@SergioSim SergioSim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome) 👍
Have only a few final minor questions/suggestions)
image

src/ralph/api/routers/statements.py Outdated Show resolved Hide resolved
src/ralph/api/routers/statements.py Outdated Show resolved Hide resolved
src/ralph/api/routers/statements.py Outdated Show resolved Hide resolved
src/ralph/api/routers/statements.py Outdated Show resolved Hide resolved
tests/test_helpers.py Outdated Show resolved Hide resolved
tests/test_helpers.py Outdated Show resolved Hide resolved
tests/helpers.py Outdated Show resolved Hide resolved
Copy link
Contributor

@wilbrdt wilbrdt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alt text

Copy link
Collaborator

@SergioSim SergioSim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM) 👍
Just the CI linter complains for some reason, could you check it?
image

The xAPI specification indicates to infer the fields `authority`, `stored`,
`timestamp` and `id` (discouraging use of `version`), when recieving statements.
This commit implements this requirement, thus paving the way to proper
permissions management (through `authority`).
@Leobouloc Leobouloc force-pushed the feature/enrich-incoming-statements branch from e59a2ce to 814c411 Compare August 30, 2023 12:44
@Leobouloc Leobouloc enabled auto-merge (rebase) August 30, 2023 12:48
@Leobouloc Leobouloc merged commit b62f87d into master Aug 30, 2023
@Leobouloc Leobouloc deleted the feature/enrich-incoming-statements branch August 30, 2023 12:51
@Leobouloc Leobouloc restored the feature/enrich-incoming-statements branch September 12, 2023 13:22
@jmaupetit jmaupetit deleted the feature/enrich-incoming-statements branch October 5, 2023 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants