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

EES-4913 Allow preview access to Public API data sets #5133

Merged
merged 3 commits into from
Aug 23, 2024
Merged

Conversation

benoutram
Copy link
Collaborator

This PR adds preview access to Public API data set version data using preview tokens.

A preview token can be set for a request using a HTTP request header Preview-Token.

It makes a change to the two authorisation handlers associated with the guards IUserService.CheckCanQueryDataSetVersion and IUserService.CheckCanViewDataSetVersion. They now ensure a valid preview token is present in the request before succeeding where they would have otherwise failed due to the version being in an inaccessible status.

A preview token is valid for the DataSetVersion in the context of the request if there exists a PreviewToken entity with matching Id, which is not expired, and the token has been issued for the same DataSetVersion which must also be in Draft status.

Example usage

Get a data set version

GET http://localhost:5050/api/v1.0/data-sets/3d369101-f7e9-2f72-a8fa-64e1717cd5eb/versions/1.0
Preview-Token: 3f369101-4f36-8774-a183-04910906b704

Get a data set version's changes

GET http://localhost:5050/api/v1.0/data-sets/3d369101-f7e9-2f72-a8fa-64e1717cd5eb/versions/1.0/changes
Preview-Token: 3f369101-4f36-8774-a183-04910906b704

Get a data set’s metadata

GET http://localhost:5050/api/v1.0/data-sets/3d369101-f7e9-2f72-a8fa-64e1717cd5eb/meta?dataSetVersion=1.0
Preview-Token: 3f369101-4f36-8774-a183-04910906b704

Query a data Set

Example for (POST) method but preview tokens can also be used to query a data set (GET).

POST http://localhost:5050/api/v1.0/data-sets/3d369101-f7e9-2f72-a8fa-64e1717cd5eb/query?dataSetVersion=1.0
Content-Type: application/json
Preview-Token: 3f369101-4f36-8774-a183-04910906b704

{
  "criteria": {
   "filters": {
      "in": ["IfDbB"]
    },
    "geographicLevels": {
      "eq": "LA"
    },
    "locations": {
      "in": [
        {
          "level": "LA",
          "id": "QgWPw"
        }
      ]
    },
    "timePeriods": {
      "gte": {
        "period": "2022/2023",
        "code": "AY"
      }
    }
  },
  "indicators" : ["enrolments"]
}

@benoutram benoutram force-pushed the EES-4913 branch 6 times, most recently from 86a932c to 4df8277 Compare August 22, 2024 19:39
@benoutram benoutram requested a review from ntsim August 22, 2024 19:42
@benoutram benoutram merged commit 0a632bf into dev Aug 23, 2024
7 checks passed
@benoutram benoutram deleted the EES-4913 branch August 23, 2024 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants