{"action":"created","comment":{"url":"https://api.github.com/repos/zendesk/samson/pulls/comments/41561761","id":41561761,"diff_hunk":"@@ -0,0 +1,15 @@\n+class UserProjectRole < ActiveRecord::Base\n+  include HasProjectRole\n+  belongs_to :project\n+  belongs_to :user\n+\n+  validates_presence_of :project, :user\n+  validates :role_id, inclusion: { in: ProjectRole.all.map(&:id) }\n+  validates_uniqueness_of :project_id, scope: :user_id\n+\n+  def self.update_user_role(id, attributes)","path":"app/models/user_project_role.rb","position":10,"original_position":10,"commit_id":"b38f35f54d38c5ae46a49a116ad615ea310f2a22","original_commit_id":"b38f35f54d38c5ae46a49a116ad615ea310f2a22","user":{"login":"steved","id":13248,"avatar_url":"https://avatars.githubusercontent.com/u/13248?v=3","gravatar_id":"","url":"https://api.github.com/users/steved","html_url":"https://github.com/steved","followers_url":"https://api.github.com/users/steved/followers","following_url":"https://api.github.com/users/steved/following{/other_user}","gists_url":"https://api.github.com/users/steved/gists{/gist_id}","starred_url":"https://api.github.com/users/steved/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steved/subscriptions","organizations_url":"https://api.github.com/users/steved/orgs","repos_url":"https://api.github.com/users/steved/repos","events_url":"https://api.github.com/users/steved/events{/privacy}","received_events_url":"https://api.github.com/users/steved/received_events","type":"User","site_admin":false},"body":"I kind of get the usefulness, but this is also okay in controllers:\r\n\r\n```\r\nrole = ProjectRole.find(id)\r\nif project_role.update(role_params)\r\n  success\r\nelse\r\n  fail\r\nend\r\n```","created_at":"2015-10-08T20:06:51Z","updated_at":"2015-10-08T20:06:51Z","html_url":"https://github.com/zendesk/samson/pull/560#discussion_r41561761","pull_request_url":"https://api.github.com/repos/zendesk/samson/pulls/560","_links":{"self":{"href":"https://api.github.com/repos/zendesk/samson/pulls/comments/41561761"},"html":{"href":"https://github.com/zendesk/samson/pull/560#discussion_r41561761"},"pull_request":{"href":"https://api.github.com/repos/zendesk/samson/pulls/560"}}},"pull_request":{"url":"https://api.github.com/repos/zendesk/samson/pulls/560","id":46528200,"html_url":"https://github.com/zendesk/samson/pull/560","diff_url":"https://github.com/zendesk/samson/pull/560.diff","patch_url":"https://github.com/zendesk/samson/pull/560.patch","issue_url":"https://api.github.com/repos/zendesk/samson/issues/560","number":560,"state":"open","locked":false,"title":"Introduce project level access control [SAMSON-169]","user":{"login":"sbrnunes","id":2833020,"avatar_url":"https://avatars.githubusercontent.com/u/2833020?v=3","gravatar_id":"","url":"https://api.github.com/users/sbrnunes","html_url":"https://github.com/sbrnunes","followers_url":"https://api.github.com/users/sbrnunes/followers","following_url":"https://api.github.com/users/sbrnunes/following{/other_user}","gists_url":"https://api.github.com/users/sbrnunes/gists{/gist_id}","starred_url":"https://api.github.com/users/sbrnunes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbrnunes/subscriptions","organizations_url":"https://api.github.com/users/sbrnunes/orgs","repos_url":"https://api.github.com/users/sbrnunes/repos","events_url":"https://api.github.com/users/sbrnunes/events{/privacy}","received_events_url":"https://api.github.com/users/sbrnunes/received_events","type":"User","site_admin":false},"body":"Continuing the work started by @jonmoter: adding ability to grant users admin-level permissions to a single project, rather than globally.\r\n\r\nReviewed the database model (renamed table ProjectRole to UserProjectRole), created ProjectRole \"enum\" as a first class citizen, containing all project-level roles.\r\n\r\nReviewed the authorisation \"filters\" when accessing project related controllers:\r\n- System level admins / super-admins can still access the projects\r\n- Non system level admins can now access a project if assigned the role of project admin\r\n\r\nAdded support for changing users project-level roles through the UI:\r\n- By drilling down to a specific User details page from the Users page accessible through the Admin menu (accessible to system-level admins and super-admins)\r\n- By clicking on the new Users tab on the Project settings page (accessible only to project admins)\r\n\r\n/cc @zendesk/samson \r\n\r\n### Steps to reproduce\r\n- Login as a deployer / viewer\r\n- Confirm that the User does not have admin rights for a specific project\r\n- Login as an admin / super-admin, and make the previous User admin for the previous project\r\n- Login again with the first User\r\n- Confirm that the User has now admin rights for the same project, can see the Users tab and change the project-level roles for another User\r\n\r\n### Tasks\r\n - [x] UI to show/add/remove user permissions on Project Settings page\r\n - [x] UI to show/add/remove project permissions on Users admin page\r\n\r\n### References\r\n- [SAMSON-169](https://zendesk.atlassian.net/browse/SAMSON-169)\r\n\r\n### Risks\r\n- Changes to the behaviour of authorisation filters (confirm no security holes were added)\r\n\r\n### Screenshots\r\n- User details page in the Admin section\r\n![screenshot 2015-09-22 16 52 51](https://cloud.githubusercontent.com/assets/2833020/10023563/b595d8b2-614a-11e5-87c2-392c604c350c.png)\r\n\r\n- User role just updated\r\n![screenshot 2015-09-22 16 53 26](https://cloud.githubusercontent.com/assets/2833020/10023564/b59a933e-614a-11e5-9a10-0dcbab1acc99.png)\r\n\r\n- Users tab in the Project settings page\r\n![screenshot 2015-09-22 16 54 05](https://cloud.githubusercontent.com/assets/2833020/10023565/b59d6c3a-614a-11e5-88be-022d6ee0bbe0.png)\r\n","created_at":"2015-10-01T14:10:41Z","updated_at":"2015-10-08T20:06:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d714ab4033c3c84c302a64305dd359458bb7e7b6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/zendesk/samson/pulls/560/commits","review_comments_url":"https://api.github.com/repos/zendesk/samson/pulls/560/comments","review_comment_url":"https://api.github.com/repos/zendesk/samson/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zendesk/samson/issues/560/comments","statuses_url":"https://api.github.com/repos/zendesk/samson/statuses/b38f35f54d38c5ae46a49a116ad615ea310f2a22","head":{"label":"zendesk:sbrnunes/add-project-level-access-control","ref":"sbrnunes/add-project-level-access-control","sha":"b38f35f54d38c5ae46a49a116ad615ea310f2a22","user":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"repo":{"id":20208662,"name":"samson","full_name":"zendesk/samson","owner":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zendesk/samson","description":"Web interface for deployments","fork":false,"url":"https://api.github.com/repos/zendesk/samson","forks_url":"https://api.github.com/repos/zendesk/samson/forks","keys_url":"https://api.github.com/repos/zendesk/samson/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zendesk/samson/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zendesk/samson/teams","hooks_url":"https://api.github.com/repos/zendesk/samson/hooks","issue_events_url":"https://api.github.com/repos/zendesk/samson/issues/events{/number}","events_url":"https://api.github.com/repos/zendesk/samson/events","assignees_url":"https://api.github.com/repos/zendesk/samson/assignees{/user}","branches_url":"https://api.github.com/repos/zendesk/samson/branches{/branch}","tags_url":"https://api.github.com/repos/zendesk/samson/tags","blobs_url":"https://api.github.com/repos/zendesk/samson/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zendesk/samson/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zendesk/samson/git/refs{/sha}","trees_url":"https://api.github.com/repos/zendesk/samson/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zendesk/samson/statuses/{sha}","languages_url":"https://api.github.com/repos/zendesk/samson/languages","stargazers_url":"https://api.github.com/repos/zendesk/samson/stargazers","contributors_url":"https://api.github.com/repos/zendesk/samson/contributors","subscribers_url":"https://api.github.com/repos/zendesk/samson/subscribers","subscription_url":"https://api.github.com/repos/zendesk/samson/subscription","commits_url":"https://api.github.com/repos/zendesk/samson/commits{/sha}","git_commits_url":"https://api.github.com/repos/zendesk/samson/git/commits{/sha}","comments_url":"https://api.github.com/repos/zendesk/samson/comments{/number}","issue_comment_url":"https://api.github.com/repos/zendesk/samson/issues/comments{/number}","contents_url":"https://api.github.com/repos/zendesk/samson/contents/{+path}","compare_url":"https://api.github.com/repos/zendesk/samson/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zendesk/samson/merges","archive_url":"https://api.github.com/repos/zendesk/samson/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zendesk/samson/downloads","issues_url":"https://api.github.com/repos/zendesk/samson/issues{/number}","pulls_url":"https://api.github.com/repos/zendesk/samson/pulls{/number}","milestones_url":"https://api.github.com/repos/zendesk/samson/milestones{/number}","notifications_url":"https://api.github.com/repos/zendesk/samson/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zendesk/samson/labels{/name}","releases_url":"https://api.github.com/repos/zendesk/samson/releases{/id}","created_at":"2014-05-27T05:55:57Z","updated_at":"2015-10-08T07:40:10Z","pushed_at":"2015-10-08T17:46:47Z","git_url":"git://github.com/zendesk/samson.git","ssh_url":"git@github.com:zendesk/samson.git","clone_url":"https://github.com/zendesk/samson.git","svn_url":"https://github.com/zendesk/samson","homepage":null,"size":113906,"stargazers_count":503,"watchers_count":503,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":74,"mirror_url":null,"open_issues_count":40,"forks":74,"open_issues":40,"watchers":503,"default_branch":"master"}},"base":{"label":"zendesk:master","ref":"master","sha":"8d75f1f3f5b54c1a4c972045272f26e47cf12b15","user":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"repo":{"id":20208662,"name":"samson","full_name":"zendesk/samson","owner":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zendesk/samson","description":"Web interface for deployments","fork":false,"url":"https://api.github.com/repos/zendesk/samson","forks_url":"https://api.github.com/repos/zendesk/samson/forks","keys_url":"https://api.github.com/repos/zendesk/samson/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zendesk/samson/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zendesk/samson/teams","hooks_url":"https://api.github.com/repos/zendesk/samson/hooks","issue_events_url":"https://api.github.com/repos/zendesk/samson/issues/events{/number}","events_url":"https://api.github.com/repos/zendesk/samson/events","assignees_url":"https://api.github.com/repos/zendesk/samson/assignees{/user}","branches_url":"https://api.github.com/repos/zendesk/samson/branches{/branch}","tags_url":"https://api.github.com/repos/zendesk/samson/tags","blobs_url":"https://api.github.com/repos/zendesk/samson/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zendesk/samson/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zendesk/samson/git/refs{/sha}","trees_url":"https://api.github.com/repos/zendesk/samson/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zendesk/samson/statuses/{sha}","languages_url":"https://api.github.com/repos/zendesk/samson/languages","stargazers_url":"https://api.github.com/repos/zendesk/samson/stargazers","contributors_url":"https://api.github.com/repos/zendesk/samson/contributors","subscribers_url":"https://api.github.com/repos/zendesk/samson/subscribers","subscription_url":"https://api.github.com/repos/zendesk/samson/subscription","commits_url":"https://api.github.com/repos/zendesk/samson/commits{/sha}","git_commits_url":"https://api.github.com/repos/zendesk/samson/git/commits{/sha}","comments_url":"https://api.github.com/repos/zendesk/samson/comments{/number}","issue_comment_url":"https://api.github.com/repos/zendesk/samson/issues/comments{/number}","contents_url":"https://api.github.com/repos/zendesk/samson/contents/{+path}","compare_url":"https://api.github.com/repos/zendesk/samson/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zendesk/samson/merges","archive_url":"https://api.github.com/repos/zendesk/samson/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zendesk/samson/downloads","issues_url":"https://api.github.com/repos/zendesk/samson/issues{/number}","pulls_url":"https://api.github.com/repos/zendesk/samson/pulls{/number}","milestones_url":"https://api.github.com/repos/zendesk/samson/milestones{/number}","notifications_url":"https://api.github.com/repos/zendesk/samson/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zendesk/samson/labels{/name}","releases_url":"https://api.github.com/repos/zendesk/samson/releases{/id}","created_at":"2014-05-27T05:55:57Z","updated_at":"2015-10-08T07:40:10Z","pushed_at":"2015-10-08T17:46:47Z","git_url":"git://github.com/zendesk/samson.git","ssh_url":"git@github.com:zendesk/samson.git","clone_url":"https://github.com/zendesk/samson.git","svn_url":"https://github.com/zendesk/samson","homepage":null,"size":113906,"stargazers_count":503,"watchers_count":503,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":74,"mirror_url":null,"open_issues_count":40,"forks":74,"open_issues":40,"watchers":503,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zendesk/samson/pulls/560"},"html":{"href":"https://github.com/zendesk/samson/pull/560"},"issue":{"href":"https://api.github.com/repos/zendesk/samson/issues/560"},"comments":{"href":"https://api.github.com/repos/zendesk/samson/issues/560/comments"},"review_comments":{"href":"https://api.github.com/repos/zendesk/samson/pulls/560/comments"},"review_comment":{"href":"https://api.github.com/repos/zendesk/samson/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zendesk/samson/pulls/560/commits"},"statuses":{"href":"https://api.github.com/repos/zendesk/samson/statuses/b38f35f54d38c5ae46a49a116ad615ea310f2a22"}}}}