Users API POST does not set relationships for Groups
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
## Bug Report
**Current Behavior**
When sending a POST request to the users API for creating a new user, relationships appear to be ignored. To set relationships on new users, a follow-up PATCH request has to be called to add the relationships.
**Steps to Reproduce**
1. Request POST /api/users
```json
{
"data": {
"type": "users",
"attributes": {
"username": "joebloggs",
"email": "some@email.com",
"password": "ThisIsSomePassword",
"isEmailConfirmed": true,
"isActivated": true
},
"relationships": {
"groups": {
"data": [{
"type": "groups",
"id": "5"
}]
}
}
}
}
```
2. API Response:
```json
{
"data":{
"type":"users",
"id":"35",
"attributes":{
"username":"joebloggs",
"avatarUrl":null,
"bio":null,
"joinTime":"2018-10-04T22:17:11+00:00",
"discussionsCount":0,
"commentsCount":0,
"canEdit":true,
"canDelete":true,
"lastSeenTime":null,
"isActivated":true,
"email":"some@email.com",
"readTime":null,
"unreadNotificationsCount":0,
"newNotificationsCount":0,
"preferences":{
"notify_discussionRenamed_alert":true,
"notify_postLiked_alert":true,
"notify_discussionLocked_alert":true,
"notify_postMentioned_alert":true,
"notify_postMentioned_email":false,
"notify_userMentioned_alert":true,
"notify_userMentioned_email":false,
"notify_newPost_alert":true,
"notify_newPost_email":true,
"followAfterReply":false,
"discloseOnline":true,
"indexProfile":true,
"locale":null
},
"newFlagsCount":0,
"suspendUntil":null,
"canSuspend":true
}
}
}
```
3. A follow-up GET to /api/users/:id shows that no relationships have been set:
```
{
"data":{
"type":"users",
"id":"35",
"attributes":{
"username":"joebloggs",
"avatarUrl":null,
"bio":null,
"joinTime":"2018-10-04T22:17:11+00:00",
"discussionsCount":0,
"commentsCount":0,
"canEdit":true,
"canDelete":true,
"lastSeenTime":null,
"isActivated":true,
"email":"some@email.com",
"suspendUntil":null,
"canSuspend":true
},
"relationships":{
"groups":{
"data":[
]
}
}
}
}
```
**Expected Behavior**
The user should immediately have its relationships assigned to avoid additional client / API connector complexity in API call chaining for linking users to Groups, etc.
**Environment**
- Flarum version: 0.1.0-beta.7
- Webserver: nginx
- Hosting environment: AWS EC2
- PHP version: 7.2.5
- Browser: Chrome, Postman, MSXML2.http
```
Flarum core 0.1.0-beta.7
PHP 7.2.5
Loaded extensions: Core, date, libxml, openssl, pcre, zlib, filter, hash, pcntl, readline, Reflection, SPL, session, standard, bz2, calendar, ctype, curl, dom, mbstring, fileinfo, ftp, gd, gettext, iconv, intl, json, exif, mysqlnd, PDO, pgsql, Phar, posix, shmop, SimpleXML, sockets, sqlite3, sysvmsg, sysvsem, sysvshm, tokenizer, xml, xmlwriter, xsl, mysqli, pdo_mysql, pdo_pgsql, pdo_sqlite, wddx, xmlreader, zip
EXT flarum-approval v0.1.0-beta.7
EXT flarum-bbcode v0.1.0-beta.5
EXT flarum-emoji v0.1.0-beta.6
EXT flarum-english v0.1.0-beta.7
EXT flarum-flags v0.1.0-beta.7
EXT flarum-likes v0.1.0-beta.6
EXT flarum-lock v0.1.0-beta.7
EXT flarum-markdown v0.1.0-beta.5
EXT flarum-mentions v0.1.0-beta.7
EXT flarum-sticky v0.1.0-beta.7
EXT flarum-subscriptions v0.1.0-beta.6
EXT flarum-suspend v0.1.0-beta.7
EXT flarum-tags v0.1.0-beta.8
Base URL: --redacted--
Installation path: /srv/--redacted--/www
```
**Additional Context**
I am unsure if this is intentional or not, though for ease of API integration, POST should be able to create relationships immediately rather than having to do a subsequent PATCH request.
Contributor guide
Research direction
Start by reproducing POST /api/users with the documented groups relationship, then use the follow-up GET /api/users/:id to confirm the relationship is absent. Trace the users API relationship handling and compare POST behavior with the PATCH request described in the report; done means newly created users retain their submitted groups relationship without a second request.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100