{"action":"created","comment":{"url":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/comments/72711823","id":72711823,"diff_hunk":"@@ -18,38 +20,51 @@ module.exports = (datastore) => ({\n             const scmUrl = request.payload.scmUrl;\n             const Pipeline = new Model.Pipeline(datastore);\n             const pipelineId = Pipeline.generateId({ scmUrl });\n+            const username = request.auth.credentials.username;\n+            const User = new Model.User(datastore, password);\n \n-            /* eslint-disable consistent-return */\n-            Pipeline.get(pipelineId, (error, data) => {\n-                if (error) {\n-                    return reply(boom.wrap(error));\n-                }\n-                if (data) {\n-                    return reply(boom.conflict('scmUrl needs to be unique'));\n-                }\n-\n-                Pipeline.create(request.payload, (err, result) => {\n-                    if (err) {\n-                        return reply(boom.wrap(err));\n+            async.waterfall([\n+                (next) => User.getPermissions({\n+                    username,\n+                    scmUrl\n+                }, next),\n+                (permissions, next) => {\n+                    if (!permissions.admin) {\n+                        return reply(boom.unauthorized(`User ${username}\n+                            is not an admin of this repo`));\n                     }\n \n-                    const location = urlLib.format({\n-                        host: request.headers.host,\n-                        port: request.headers.port,\n-                        protocol: request.server.info.protocol,\n-                        pathname: `${request.path}/${result.id}`\n-                    });\n+                    return Pipeline.get(pipelineId, next);\n+                },\n+                (data, next) => {\n+                    if (data) {\n+                        return reply(boom.conflict('scmUrl needs to be unique'));\n+                    }\n+                    const admins = {};\n \n-                    Pipeline.sync({\n-                        scmUrl\n-                    }, (e) => {\n-                        if (e) {\n-                            return reply(boom.wrap(e));\n-                        }\n+                    admins[username] = true;\n+                    const pipelineConfig = hoek.merge(request.payload, { admins });","path":"plugins/pipelines/create.js","position":65,"original_position":65,"commit_id":"f23ba1a6cf2d1d33cf1be48ee74fc17346e4d6ca","original_commit_id":"f23ba1a6cf2d1d33cf1be48ee74fc17346e4d6ca","user":{"login":"d2lam","id":3401924,"avatar_url":"https://avatars.githubusercontent.com/u/3401924?v=3","gravatar_id":"","url":"https://api.github.com/users/d2lam","html_url":"https://github.com/d2lam","followers_url":"https://api.github.com/users/d2lam/followers","following_url":"https://api.github.com/users/d2lam/following{/other_user}","gists_url":"https://api.github.com/users/d2lam/gists{/gist_id}","starred_url":"https://api.github.com/users/d2lam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/d2lam/subscriptions","organizations_url":"https://api.github.com/users/d2lam/orgs","repos_url":"https://api.github.com/users/d2lam/repos","events_url":"https://api.github.com/users/d2lam/events{/privacy}","received_events_url":"https://api.github.com/users/d2lam/received_events","type":"User","site_admin":false},"body":"True","created_at":"2016-07-28T22:04:41Z","updated_at":"2016-07-28T22:04:41Z","html_url":"https://github.com/screwdriver-cd/screwdriver/pull/53#discussion_r72711823","pull_request_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/53","_links":{"self":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/comments/72711823"},"html":{"href":"https://github.com/screwdriver-cd/screwdriver/pull/53#discussion_r72711823"},"pull_request":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/53"}}},"pull_request":{"url":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/53","id":79104820,"html_url":"https://github.com/screwdriver-cd/screwdriver/pull/53","diff_url":"https://github.com/screwdriver-cd/screwdriver/pull/53.diff","patch_url":"https://github.com/screwdriver-cd/screwdriver/pull/53.patch","issue_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues/53","number":53,"state":"open","locked":false,"title":"Check user permissions, attach user during pipeline creation","user":{"login":"tkyi","id":3230529,"avatar_url":"https://avatars.githubusercontent.com/u/3230529?v=3","gravatar_id":"","url":"https://api.github.com/users/tkyi","html_url":"https://github.com/tkyi","followers_url":"https://api.github.com/users/tkyi/followers","following_url":"https://api.github.com/users/tkyi/following{/other_user}","gists_url":"https://api.github.com/users/tkyi/gists{/gist_id}","starred_url":"https://api.github.com/users/tkyi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkyi/subscriptions","organizations_url":"https://api.github.com/users/tkyi/orgs","repos_url":"https://api.github.com/users/tkyi/repos","events_url":"https://api.github.com/users/tkyi/events{/privacy}","received_events_url":"https://api.github.com/users/tkyi/received_events","type":"User","site_admin":false},"body":"This pull request will check if a user has admin access to a given repo and run pipeline create if they do; requires `getPermissions` to be added to Models first\r\n\r\nWaiting on https://github.com/screwdriver-cd/models/pull/23","created_at":"2016-07-27T21:55:44Z","updated_at":"2016-07-28T22:04:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"431621e0807ab27b5b54331375fe1ff42964dc00","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/53/commits","review_comments_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/53/comments","review_comment_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/comments{/number}","comments_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues/53/comments","statuses_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/statuses/f23ba1a6cf2d1d33cf1be48ee74fc17346e4d6ca","head":{"label":"screwdriver-cd:attach_user","ref":"attach_user","sha":"f23ba1a6cf2d1d33cf1be48ee74fc17346e4d6ca","user":{"login":"screwdriver-cd","id":19417863,"avatar_url":"https://avatars.githubusercontent.com/u/19417863?v=3","gravatar_id":"","url":"https://api.github.com/users/screwdriver-cd","html_url":"https://github.com/screwdriver-cd","followers_url":"https://api.github.com/users/screwdriver-cd/followers","following_url":"https://api.github.com/users/screwdriver-cd/following{/other_user}","gists_url":"https://api.github.com/users/screwdriver-cd/gists{/gist_id}","starred_url":"https://api.github.com/users/screwdriver-cd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/screwdriver-cd/subscriptions","organizations_url":"https://api.github.com/users/screwdriver-cd/orgs","repos_url":"https://api.github.com/users/screwdriver-cd/repos","events_url":"https://api.github.com/users/screwdriver-cd/events{/privacy}","received_events_url":"https://api.github.com/users/screwdriver-cd/received_events","type":"Organization","site_admin":false},"repo":{"id":59517730,"name":"screwdriver","full_name":"screwdriver-cd/screwdriver","owner":{"login":"screwdriver-cd","id":19417863,"avatar_url":"https://avatars.githubusercontent.com/u/19417863?v=3","gravatar_id":"","url":"https://api.github.com/users/screwdriver-cd","html_url":"https://github.com/screwdriver-cd","followers_url":"https://api.github.com/users/screwdriver-cd/followers","following_url":"https://api.github.com/users/screwdriver-cd/following{/other_user}","gists_url":"https://api.github.com/users/screwdriver-cd/gists{/gist_id}","starred_url":"https://api.github.com/users/screwdriver-cd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/screwdriver-cd/subscriptions","organizations_url":"https://api.github.com/users/screwdriver-cd/orgs","repos_url":"https://api.github.com/users/screwdriver-cd/repos","events_url":"https://api.github.com/users/screwdriver-cd/events{/privacy}","received_events_url":"https://api.github.com/users/screwdriver-cd/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/screwdriver-cd/screwdriver","description":"Screwdriver API powered by Hapi.js","fork":false,"url":"https://api.github.com/repos/screwdriver-cd/screwdriver","forks_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/forks","keys_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/teams","hooks_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/hooks","issue_events_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues/events{/number}","events_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/events","assignees_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/assignees{/user}","branches_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/branches{/branch}","tags_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/tags","blobs_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/refs{/sha}","trees_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/statuses/{sha}","languages_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/languages","stargazers_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/stargazers","contributors_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/contributors","subscribers_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/subscribers","subscription_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/subscription","commits_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/commits{/sha}","git_commits_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/commits{/sha}","comments_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/comments{/number}","issue_comment_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues/comments{/number}","contents_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/contents/{+path}","compare_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/merges","archive_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/downloads","issues_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues{/number}","pulls_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls{/number}","milestones_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/milestones{/number}","notifications_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/labels{/name}","releases_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/releases{/id}","deployments_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/deployments","created_at":"2016-05-23T20:55:35Z","updated_at":"2016-07-27T21:52:57Z","pushed_at":"2016-07-28T22:03:56Z","git_url":"git://github.com/screwdriver-cd/screwdriver.git","ssh_url":"git@github.com:screwdriver-cd/screwdriver.git","clone_url":"https://github.com/screwdriver-cd/screwdriver.git","svn_url":"https://github.com/screwdriver-cd/screwdriver","homepage":"https://hub.docker.com/r/screwdrivercd/screwdriver/","size":98,"stargazers_count":2,"watchers_count":2,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":8,"forks":1,"open_issues":8,"watchers":2,"default_branch":"master"}},"base":{"label":"screwdriver-cd:master","ref":"master","sha":"9cf240e15ceebf2fc2172b8eea1772247c1b96d2","user":{"login":"screwdriver-cd","id":19417863,"avatar_url":"https://avatars.githubusercontent.com/u/19417863?v=3","gravatar_id":"","url":"https://api.github.com/users/screwdriver-cd","html_url":"https://github.com/screwdriver-cd","followers_url":"https://api.github.com/users/screwdriver-cd/followers","following_url":"https://api.github.com/users/screwdriver-cd/following{/other_user}","gists_url":"https://api.github.com/users/screwdriver-cd/gists{/gist_id}","starred_url":"https://api.github.com/users/screwdriver-cd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/screwdriver-cd/subscriptions","organizations_url":"https://api.github.com/users/screwdriver-cd/orgs","repos_url":"https://api.github.com/users/screwdriver-cd/repos","events_url":"https://api.github.com/users/screwdriver-cd/events{/privacy}","received_events_url":"https://api.github.com/users/screwdriver-cd/received_events","type":"Organization","site_admin":false},"repo":{"id":59517730,"name":"screwdriver","full_name":"screwdriver-cd/screwdriver","owner":{"login":"screwdriver-cd","id":19417863,"avatar_url":"https://avatars.githubusercontent.com/u/19417863?v=3","gravatar_id":"","url":"https://api.github.com/users/screwdriver-cd","html_url":"https://github.com/screwdriver-cd","followers_url":"https://api.github.com/users/screwdriver-cd/followers","following_url":"https://api.github.com/users/screwdriver-cd/following{/other_user}","gists_url":"https://api.github.com/users/screwdriver-cd/gists{/gist_id}","starred_url":"https://api.github.com/users/screwdriver-cd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/screwdriver-cd/subscriptions","organizations_url":"https://api.github.com/users/screwdriver-cd/orgs","repos_url":"https://api.github.com/users/screwdriver-cd/repos","events_url":"https://api.github.com/users/screwdriver-cd/events{/privacy}","received_events_url":"https://api.github.com/users/screwdriver-cd/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/screwdriver-cd/screwdriver","description":"Screwdriver API powered by Hapi.js","fork":false,"url":"https://api.github.com/repos/screwdriver-cd/screwdriver","forks_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/forks","keys_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/teams","hooks_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/hooks","issue_events_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues/events{/number}","events_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/events","assignees_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/assignees{/user}","branches_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/branches{/branch}","tags_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/tags","blobs_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/refs{/sha}","trees_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/statuses/{sha}","languages_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/languages","stargazers_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/stargazers","contributors_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/contributors","subscribers_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/subscribers","subscription_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/subscription","commits_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/commits{/sha}","git_commits_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/commits{/sha}","comments_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/comments{/number}","issue_comment_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues/comments{/number}","contents_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/contents/{+path}","compare_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/merges","archive_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/downloads","issues_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues{/number}","pulls_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls{/number}","milestones_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/milestones{/number}","notifications_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/labels{/name}","releases_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/releases{/id}","deployments_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/deployments","created_at":"2016-05-23T20:55:35Z","updated_at":"2016-07-27T21:52:57Z","pushed_at":"2016-07-28T22:03:56Z","git_url":"git://github.com/screwdriver-cd/screwdriver.git","ssh_url":"git@github.com:screwdriver-cd/screwdriver.git","clone_url":"https://github.com/screwdriver-cd/screwdriver.git","svn_url":"https://github.com/screwdriver-cd/screwdriver","homepage":"https://hub.docker.com/r/screwdrivercd/screwdriver/","size":98,"stargazers_count":2,"watchers_count":2,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":8,"forks":1,"open_issues":8,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/53"},"html":{"href":"https://github.com/screwdriver-cd/screwdriver/pull/53"},"issue":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues/53"},"comments":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues/53/comments"},"review_comments":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/53/comments"},"review_comment":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/53/commits"},"statuses":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/statuses/f23ba1a6cf2d1d33cf1be48ee74fc17346e4d6ca"}}}}
{"actor":{"display_login":"d2lam"}}