{"action":"created","issue":{"url":"https://api.github.com/repos/mozilla/api.webmaker.org/issues/105","labels_url":"https://api.github.com/repos/mozilla/api.webmaker.org/issues/105/labels{/name}","comments_url":"https://api.github.com/repos/mozilla/api.webmaker.org/issues/105/comments","events_url":"https://api.github.com/repos/mozilla/api.webmaker.org/issues/105/events","html_url":"https://github.com/mozilla/api.webmaker.org/issues/105","id":91944369,"number":105,"title":"POST to remixes endpoint doesn't create a record for the current user","user":{"login":"toolness","id":124687,"avatar_url":"https://avatars.githubusercontent.com/u/124687?v=3","gravatar_id":"","url":"https://api.github.com/users/toolness","html_url":"https://github.com/toolness","followers_url":"https://api.github.com/users/toolness/followers","following_url":"https://api.github.com/users/toolness/following{/other_user}","gists_url":"https://api.github.com/users/toolness/gists{/gist_id}","starred_url":"https://api.github.com/users/toolness/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/toolness/subscriptions","organizations_url":"https://api.github.com/users/toolness/orgs","repos_url":"https://api.github.com/users/toolness/repos","events_url":"https://api.github.com/users/toolness/events{/privacy}","received_events_url":"https://api.github.com/users/toolness/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-06-30T00:45:31Z","updated_at":"2015-06-30T21:18:04Z","closed_at":null,"body":"I was investigating https://github.com/mozilla/webmaker-android/issues/2300 and I think its cause is in this project. I could easily be wrong, though, as I've never looked at the code for this project *or* webmaker-android until today.\r\n\r\nIt seems that when a new project is created, a subpath of `/users/{user}` is contacted, where `{user}` is the currently logged-in user. This happens to result in [`prerequisites.getUser`](https://github.com/mozilla/api.webmaker.org/blob/a77cc9550c786b56c556525a980afa50c4619bcc/services/api/lib/prerequisites.js#L34-L62) being called, which notices that `{user}` doesn't exist and is the currently logged-in user, and then lazily creates it. The [`getTokenUser`](https://github.com/mozilla/api.webmaker.org/blob/a77cc9550c786b56c556525a980afa50c4619bcc/services/api/lib/prerequisites.js#L64-L90) immediately follows and succeeds, because a DB entry for the current user was just created.\r\n\r\nHowever, when the logged-in user has *not* yet created a project, and instead chooses to remix an existing project, a POST request is issued to `/users/{user}/projects/{project}/remixes`. Here `{user}` is *not* the currently logged-in user--it's the user who created the project that the logged-in user wants to remix. This means that a record for the current user is *not* created, which means that `getTokenUser` fails with `\"User not found\"`.\r\n\r\nIf I'm correct, then I'm not sure what the best solution to the problem is. One is to modify `getTokenUser` to *also* lazily create the currently logged-in user if they can't be found, but I'm not sure if it's ideal, as I've never looked at this codebase until today.\r\n"},"comment":{"url":"https://api.github.com/repos/mozilla/api.webmaker.org/issues/comments/117345486","html_url":"https://github.com/mozilla/api.webmaker.org/issues/105#issuecomment-117345486","issue_url":"https://api.github.com/repos/mozilla/api.webmaker.org/issues/105","id":117345486,"user":{"login":"cadecairos","id":438003,"avatar_url":"https://avatars.githubusercontent.com/u/438003?v=3","gravatar_id":"","url":"https://api.github.com/users/cadecairos","html_url":"https://github.com/cadecairos","followers_url":"https://api.github.com/users/cadecairos/followers","following_url":"https://api.github.com/users/cadecairos/following{/other_user}","gists_url":"https://api.github.com/users/cadecairos/gists{/gist_id}","starred_url":"https://api.github.com/users/cadecairos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cadecairos/subscriptions","organizations_url":"https://api.github.com/users/cadecairos/orgs","repos_url":"https://api.github.com/users/cadecairos/repos","events_url":"https://api.github.com/users/cadecairos/events{/privacy}","received_events_url":"https://api.github.com/users/cadecairos/received_events","type":"User","site_admin":false},"created_at":"2015-06-30T21:18:04Z","updated_at":"2015-06-30T21:18:04Z","body":"@toolness I think I've got a fix for this, just need to write regression tests."}}