ecamp / ecamp/ecamp3

Implement Hitobito event participants endpoint

Open
#10,424 0 comments 0 reactions 1 assignee Claimed by @eliaSchenker View on GitHub
Ready for implementation type: API
Dominant language
PHP
Stars
156
Forks
72
Avg merge
12h 43m
Merged PRs (30d)
203

Description

The get event participants endpoint allows eCamp users to retrieve leaders and co-leaders of a Hitobito event they have access to.

```jsonc
// GET /api/hitobito//events//participants

// Response
{
"_links": {
"self": {
"href": "/api/hitobito/pbsmidata/events/123/participants"
}
},
"totalItems": 3,
"_embedded": {
"items": [
{
"firstName": "Ellen",
"lastName": "Bloch",
"nickname": "Quo",
"email": "bloch.ellen@hitobito.example.com"
},
{
"firstname": "Lee",
"legalName": "Frauen",
"nickname": "Maiores",
"email": "frauen_lee@hitobito.example.com"
},
{
"firstname": "Cindy",
"legalName": "Schwalm",
"nickname": "Et",
"email": "schwalm_cindy@hitobito.example.com"
}
]
}
}
```

## Implementation

1. Retrieve / verify access token
- See https://github.com/ecamp/ecamp3/issues/10400
2. Check that the user has access to the specified event
- See https://github.com/ecamp/ecamp3/issues/10419
3. Retrieve all event participants from Hitobito

```
GET /api/event_participations
?include=roles,participant
&filter[event_id][eq]=
&fields[event_participations]=active
&fields[people]=first_name,last_name,nickname,email
&page[number]=
&page[size]=20
```
Example Response
```jsonc
{
"data": [
{
"id": "20",
"type": "event_participations",
"attributes": {
"active": true,
},
"relationships": {
// ...
"participant": {
"data": {
"type": "people",
"id": "119"
}
},
"roles": {
"data": [
{
"type": "event_roles",
"id": "20"
}
]
}
}
}
],
"included": [
{
"id": "119",
"type": "people",
"attributes": {
"first_name": "Edgar",
"last_name": "Falter",
"nickname": "Facere",
"email": "edgar_falter@hitobito.example.com"
},
"relationships": { /* ... */ }
},
{
"id": "20",
"type": "event_roles",
"attributes": {
"participation_id": 20,
"type": "Event::Role::Participant",
"label": null
},
"relationships": { /* .. */ }
}
],
"links": {
// ...
"next": "/api/event_participations?fields%5Bpeople%5D=first_name%2Clast_name%2Cnickname%2Cemail&filter%5Bevent_id%5D%5Beq%5D=2&include=roles%2Cparticipant&page%5Bnumber%5D=2&page%5Bsize%5D20" // not set if there are no more pages
},
"meta": {}
}
```

7. For every retrieved page, perform the following steps:
1. Go through each participation
2. Check whether **one of** the corresponding event roles has one of the following `attributes.type` (person is co-leader or leader)
- `Event::Role::Leader`
- `Event::Role::AssistantLeader`
- `Event::Role::Cook`
- `Event::Role::Helper`
- `Event::Role::Treasurer`
- `Event::Role::Speaker`
- `Event::Course::Role::Leader`
- `Event::Course::Role::ClassLeader`
- `Event::Course::Role::Advisor`
- `Event::Course::Role::Helper`
- `Event::Camp::Role::AssistantLeader`
- `Event::Camp::Role::Helper`
- `Event::Camp::Role::LeaderMountainSecurity`
- `Event::Camp::Role::LeaderSnowSecurity`
- `Event::Camp::Role::LeaderWaterSecurity`
- `Event::Camp::Role::Leader`
- `Event::Camp::Role::Abteilungsleitung`
- `Event::Camp::Role::Coach`
- `Event::Camp::Role::AdvisorMountainSecurity`
- `Event::Camp::Role::AdvisorSnowSecurity`
- `Event::Camp::Role::AdvisorWaterSecurity`
3. Check whether the participation has `attributes.active = true`
1. If not, discard the participation
4. Save the corresponding person's `first_name`, `last_name`, `nickname` and `email`
8. If the response contains `links.next`, increment the `page` and repeat
9. Return all fetched participations, including each person's `first_name`, `last_name`, `nickname` and `email` as described in the example response above

> Implementation Note: As with the event access control, make sure that the roles that identify a user as a co-leader of an event is configurable per different Hitobito provider, so that new supported instances (i.e. CeviDB) can be easily added in the future.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.