flarum / issue-archive

0 stars 0 forks source link

Users API POST does not set relationships for Groups #267

Open SeanLMcCullough opened 5 years ago

SeanLMcCullough commented 5 years ago

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
    {
    "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:
    {
    "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 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.

franzliedke commented 5 years ago

Sounds like a reasonable suggestion - thanks for the report, @SeanLMcCullough !

IMO, we should include this in one of the next releases.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We do this to keep the amount of open issues to a manageable minimum. In any case, thanks for taking an interest in this software and contributing by opening the issue in the first place!