MESH-Research / knowledge-commons-works

The next-generation research repository for the Knowledge Commons (formerly Humanities Commons)
https://hcommons.org
MIT License
4 stars 0 forks source link

Implement Commons API endpoint for user data #208

Closed monotasker closed 10 months ago

monotasker commented 1 year ago

We need to implement an API endpoint on the Commons that serves user data to Invenio.

Could be something like:

hcommons.org/api/members/

With a JSON response object.

This is assuming

  1. we're not querying an ActivityPub outbox. (since that would be for activity events?)
  2. we're not providing information about activity (e.g., recent activity) (since we'll publish that with ActivityPub outbox?)
monotasker commented 1 year ago

Current (projected) format for JSON responses is an object with keys for data to be updated:

{'id': 'my_commons_id',
 'primary_email': 'myaddress@myserver.edu`,
 'name': 'Jane Goodall', 
 'preferredUsername': 'Jane',
 'groups': [
    {'name': 'chimpanzees', 'type': 'topical', 'role': 'administrator'},
    {'name': 'admin', 'type': 'administrative', 'role': 'administrator'},
    {'name': 'msu', 'type': 'organization', 'role': 'curator'},
    {'name': 'hcommons', 'type': 'commons', 'role': 'member'}
  ],
 'institutional_affiliations': [
    {'id': 'MSU'},
    {'id': 'British Academy'}
 ],
 'preferred_language': 'en',
 'profile_visibility': 'true',
 'email_visibility': 'false'
 }

Response is stateless. Not changes, but the current state of user's data on Commons. (So 'groups' gives complete current list of groups.)

mikethicke commented 10 months ago

Endpoint is at https://hcommons-dev.org/wp-json/commons/v1/users/:username .

The API is using token authentication, so you need to set the authorization header to Bearer <token> . Token is set in .env .

Response format:

{
    "username": "<WordPress username>",
    "email": "<registered email>",
    "name": "<WordPress display name>",
    "first_name": "<first name>",
    "last_name": "<last name>",
    "institutional_affiliation": "<affiliation---only one value is tracked>",
    "groups": [
        {
            "id": <group_id (int)>,
            "name": "<group display name>",
            "role": "<member|moderator|admin>" (Note: We don't actually seem to use the moderator role, though it exists)
        },
        {
            "id": 1002890,
            "name": "MDPx",
            "role": "member"
        },
       ....
}

Notes:

mikethicke commented 10 months ago

https://github.com/MESH-Research/hc-custom/commit/7e9896d83e5e7fcdf36b0afa2f541da319cb42b6