{"action":"created","comment":{"url":"https://api.github.com/repos/DirectEmployers/MyJobs/pulls/comments/49235358","id":49235358,"diff_hunk":"@@ -1208,12 +1211,34 @@ def api_edit_user(request, user_id=0):\n             return HttpResponse(json.dumps(ctx),\n                                 content_type=\"application/json\")\n \n+        # Companies must have at least one user assigned to an Admin role.\n+        # Check that -- if this user is edited -- this will be the case.\n+        # 1. Is Admin not in assigned_roles?\n+        if \"Admin\" not in assigned_roles:\n+            # 2. Does this company only have one user assigned to Admin role?\n+            admin_role = (Role\n+                          .objects\n+                          .filter(company=company)\n+                          .filter(name=\"Admin\"))\n+            users_with_admin = User.objects.filter(roles__id=admin_role[0].id)\n+\n+            if len(users_with_admin) <= 1:\n+                # 3. Is that one user this user?\n+                if unicode(users_with_admin[0].id) == user_id:\n+                    ctx[\"success\"] = \"false\"\n+                    ctx[\"message\"] = \"To remove the Admin role from this user \\","path":"myjobs/views.py","position":null,"original_position":45,"commit_id":"91048de8067a3a7ef6b4868756389928e049f7de","original_commit_id":"dc722371c259d7448e013a2c851f7d5895935553","user":{"login":"lemniscate613","id":15107331,"avatar_url":"https://avatars.githubusercontent.com/u/15107331?v=3","gravatar_id":"","url":"https://api.github.com/users/lemniscate613","html_url":"https://github.com/lemniscate613","followers_url":"https://api.github.com/users/lemniscate613/followers","following_url":"https://api.github.com/users/lemniscate613/following{/other_user}","gists_url":"https://api.github.com/users/lemniscate613/gists{/gist_id}","starred_url":"https://api.github.com/users/lemniscate613/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lemniscate613/subscriptions","organizations_url":"https://api.github.com/users/lemniscate613/orgs","repos_url":"https://api.github.com/users/lemniscate613/repos","events_url":"https://api.github.com/users/lemniscate613/events{/privacy}","received_events_url":"https://api.github.com/users/lemniscate613/received_events","type":"User","site_admin":false},"body":"I didn't know you could do that. Thank you. :+1: ","created_at":"2016-01-08T20:38:52Z","updated_at":"2016-01-08T20:38:52Z","html_url":"https://github.com/DirectEmployers/MyJobs/pull/2010#discussion_r49235358","pull_request_url":"https://api.github.com/repos/DirectEmployers/MyJobs/pulls/2010","_links":{"self":{"href":"https://api.github.com/repos/DirectEmployers/MyJobs/pulls/comments/49235358"},"html":{"href":"https://github.com/DirectEmployers/MyJobs/pull/2010#discussion_r49235358"},"pull_request":{"href":"https://api.github.com/repos/DirectEmployers/MyJobs/pulls/2010"}}},"pull_request":{"url":"https://api.github.com/repos/DirectEmployers/MyJobs/pulls/2010","id":55500067,"html_url":"https://github.com/DirectEmployers/MyJobs/pull/2010","diff_url":"https://github.com/DirectEmployers/MyJobs/pull/2010.diff","patch_url":"https://github.com/DirectEmployers/MyJobs/pull/2010.patch","issue_url":"https://api.github.com/repos/DirectEmployers/MyJobs/issues/2010","number":2010,"state":"open","locked":false,"title":"[PD-2046] misc protections","user":{"login":"lemniscate613","id":15107331,"avatar_url":"https://avatars.githubusercontent.com/u/15107331?v=3","gravatar_id":"","url":"https://api.github.com/users/lemniscate613","html_url":"https://github.com/lemniscate613","followers_url":"https://api.github.com/users/lemniscate613/followers","following_url":"https://api.github.com/users/lemniscate613/following{/other_user}","gists_url":"https://api.github.com/users/lemniscate613/gists{/gist_id}","starred_url":"https://api.github.com/users/lemniscate613/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lemniscate613/subscriptions","organizations_url":"https://api.github.com/users/lemniscate613/orgs","repos_url":"https://api.github.com/users/lemniscate613/repos","events_url":"https://api.github.com/users/lemniscate613/events{/privacy}","received_events_url":"https://api.github.com/users/lemniscate613/received_events","type":"User","site_admin":false},"body":"Prevent user from:\r\n* Editing Admin role\r\n* Removing Admin role from the last person with this role in a company","created_at":"2016-01-08T19:27:49Z","updated_at":"2016-01-08T20:38:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"25fe514f128338ef1aadcfa9a3feb87ddae33e2d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/DirectEmployers/MyJobs/pulls/2010/commits","review_comments_url":"https://api.github.com/repos/DirectEmployers/MyJobs/pulls/2010/comments","review_comment_url":"https://api.github.com/repos/DirectEmployers/MyJobs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DirectEmployers/MyJobs/issues/2010/comments","statuses_url":"https://api.github.com/repos/DirectEmployers/MyJobs/statuses/91048de8067a3a7ef6b4868756389928e049f7de","head":{"label":"DirectEmployers:2046_misc_protections","ref":"2046_misc_protections","sha":"91048de8067a3a7ef6b4868756389928e049f7de","user":{"login":"DirectEmployers","id":381171,"avatar_url":"https://avatars.githubusercontent.com/u/381171?v=3","gravatar_id":"","url":"https://api.github.com/users/DirectEmployers","html_url":"https://github.com/DirectEmployers","followers_url":"https://api.github.com/users/DirectEmployers/followers","following_url":"https://api.github.com/users/DirectEmployers/following{/other_user}","gists_url":"https://api.github.com/users/DirectEmployers/gists{/gist_id}","starred_url":"https://api.github.com/users/DirectEmployers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DirectEmployers/subscriptions","organizations_url":"https://api.github.com/users/DirectEmployers/orgs","repos_url":"https://api.github.com/users/DirectEmployers/repos","events_url":"https://api.github.com/users/DirectEmployers/events{/privacy}","received_events_url":"https://api.github.com/users/DirectEmployers/received_events","type":"Organization","site_admin":false},"repo":{"id":2867982,"name":"MyJobs","full_name":"DirectEmployers/MyJobs","owner":{"login":"DirectEmployers","id":381171,"avatar_url":"https://avatars.githubusercontent.com/u/381171?v=3","gravatar_id":"","url":"https://api.github.com/users/DirectEmployers","html_url":"https://github.com/DirectEmployers","followers_url":"https://api.github.com/users/DirectEmployers/followers","following_url":"https://api.github.com/users/DirectEmployers/following{/other_user}","gists_url":"https://api.github.com/users/DirectEmployers/gists{/gist_id}","starred_url":"https://api.github.com/users/DirectEmployers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DirectEmployers/subscriptions","organizations_url":"https://api.github.com/users/DirectEmployers/orgs","repos_url":"https://api.github.com/users/DirectEmployers/repos","events_url":"https://api.github.com/users/DirectEmployers/events{/privacy}","received_events_url":"https://api.github.com/users/DirectEmployers/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DirectEmployers/MyJobs","description":"Multi-user website designed to assist job seekers in their search for employment","fork":false,"url":"https://api.github.com/repos/DirectEmployers/MyJobs","forks_url":"https://api.github.com/repos/DirectEmployers/MyJobs/forks","keys_url":"https://api.github.com/repos/DirectEmployers/MyJobs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DirectEmployers/MyJobs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DirectEmployers/MyJobs/teams","hooks_url":"https://api.github.com/repos/DirectEmployers/MyJobs/hooks","issue_events_url":"https://api.github.com/repos/DirectEmployers/MyJobs/issues/events{/number}","events_url":"https://api.github.com/repos/DirectEmployers/MyJobs/events","assignees_url":"https://api.github.com/repos/DirectEmployers/MyJobs/assignees{/user}","branches_url":"https://api.github.com/repos/DirectEmployers/MyJobs/branches{/branch}","tags_url":"https://api.github.com/repos/DirectEmployers/MyJobs/tags","blobs_url":"https://api.github.com/repos/DirectEmployers/MyJobs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DirectEmployers/MyJobs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DirectEmployers/MyJobs/git/refs{/sha}","trees_url":"https://api.github.com/repos/DirectEmployers/MyJobs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DirectEmployers/MyJobs/statuses/{sha}","languages_url":"https://api.github.com/repos/DirectEmployers/MyJobs/languages","stargazers_url":"https://api.github.com/repos/DirectEmployers/MyJobs/stargazers","contributors_url":"https://api.github.com/repos/DirectEmployers/MyJobs/contributors","subscribers_url":"https://api.github.com/repos/DirectEmployers/MyJobs/subscribers","subscription_url":"https://api.github.com/repos/DirectEmployers/MyJobs/subscription","commits_url":"https://api.github.com/repos/DirectEmployers/MyJobs/commits{/sha}","git_commits_url":"https://api.github.com/repos/DirectEmployers/MyJobs/git/commits{/sha}","comments_url":"https://api.github.com/repos/DirectEmployers/MyJobs/comments{/number}","issue_comment_url":"https://api.github.com/repos/DirectEmployers/MyJobs/issues/comments{/number}","contents_url":"https://api.github.com/repos/DirectEmployers/MyJobs/contents/{+path}","compare_url":"https://api.github.com/repos/DirectEmployers/MyJobs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DirectEmployers/MyJobs/merges","archive_url":"https://api.github.com/repos/DirectEmployers/MyJobs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DirectEmployers/MyJobs/downloads","issues_url":"https://api.github.com/repos/DirectEmployers/MyJobs/issues{/number}","pulls_url":"https://api.github.com/repos/DirectEmployers/MyJobs/pulls{/number}","milestones_url":"https://api.github.com/repos/DirectEmployers/MyJobs/milestones{/number}","notifications_url":"https://api.github.com/repos/DirectEmployers/MyJobs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DirectEmployers/MyJobs/labels{/name}","releases_url":"https://api.github.com/repos/DirectEmployers/MyJobs/releases{/id}","created_at":"2011-11-28T15:22:36Z","updated_at":"2015-12-23T15:59:16Z","pushed_at":"2016-01-08T20:38:20Z","git_url":"git://github.com/DirectEmployers/MyJobs.git","ssh_url":"git@github.com:DirectEmployers/MyJobs.git","clone_url":"https://github.com/DirectEmployers/MyJobs.git","svn_url":"https://github.com/DirectEmployers/MyJobs","homepage":"http://my.jobs","size":34848,"stargazers_count":6,"watchers_count":6,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":10,"mirror_url":null,"open_issues_count":8,"forks":10,"open_issues":8,"watchers":6,"default_branch":"quality-control"}},"base":{"label":"DirectEmployers:quality-control","ref":"quality-control","sha":"ea1c2fa791603c0e40ff152f1d4d81d8d4e96f46","user":{"login":"DirectEmployers","id":381171,"avatar_url":"https://avatars.githubusercontent.com/u/381171?v=3","gravatar_id":"","url":"https://api.github.com/users/DirectEmployers","html_url":"https://github.com/DirectEmployers","followers_url":"https://api.github.com/users/DirectEmployers/followers","following_url":"https://api.github.com/users/DirectEmployers/following{/other_user}","gists_url":"https://api.github.com/users/DirectEmployers/gists{/gist_id}","starred_url":"https://api.github.com/users/DirectEmployers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DirectEmployers/subscriptions","organizations_url":"https://api.github.com/users/DirectEmployers/orgs","repos_url":"https://api.github.com/users/DirectEmployers/repos","events_url":"https://api.github.com/users/DirectEmployers/events{/privacy}","received_events_url":"https://api.github.com/users/DirectEmployers/received_events","type":"Organization","site_admin":false},"repo":{"id":2867982,"name":"MyJobs","full_name":"DirectEmployers/MyJobs","owner":{"login":"DirectEmployers","id":381171,"avatar_url":"https://avatars.githubusercontent.com/u/381171?v=3","gravatar_id":"","url":"https://api.github.com/users/DirectEmployers","html_url":"https://github.com/DirectEmployers","followers_url":"https://api.github.com/users/DirectEmployers/followers","following_url":"https://api.github.com/users/DirectEmployers/following{/other_user}","gists_url":"https://api.github.com/users/DirectEmployers/gists{/gist_id}","starred_url":"https://api.github.com/users/DirectEmployers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DirectEmployers/subscriptions","organizations_url":"https://api.github.com/users/DirectEmployers/orgs","repos_url":"https://api.github.com/users/DirectEmployers/repos","events_url":"https://api.github.com/users/DirectEmployers/events{/privacy}","received_events_url":"https://api.github.com/users/DirectEmployers/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DirectEmployers/MyJobs","description":"Multi-user website designed to assist job seekers in their search for employment","fork":false,"url":"https://api.github.com/repos/DirectEmployers/MyJobs","forks_url":"https://api.github.com/repos/DirectEmployers/MyJobs/forks","keys_url":"https://api.github.com/repos/DirectEmployers/MyJobs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DirectEmployers/MyJobs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DirectEmployers/MyJobs/teams","hooks_url":"https://api.github.com/repos/DirectEmployers/MyJobs/hooks","issue_events_url":"https://api.github.com/repos/DirectEmployers/MyJobs/issues/events{/number}","events_url":"https://api.github.com/repos/DirectEmployers/MyJobs/events","assignees_url":"https://api.github.com/repos/DirectEmployers/MyJobs/assignees{/user}","branches_url":"https://api.github.com/repos/DirectEmployers/MyJobs/branches{/branch}","tags_url":"https://api.github.com/repos/DirectEmployers/MyJobs/tags","blobs_url":"https://api.github.com/repos/DirectEmployers/MyJobs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DirectEmployers/MyJobs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DirectEmployers/MyJobs/git/refs{/sha}","trees_url":"https://api.github.com/repos/DirectEmployers/MyJobs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DirectEmployers/MyJobs/statuses/{sha}","languages_url":"https://api.github.com/repos/DirectEmployers/MyJobs/languages","stargazers_url":"https://api.github.com/repos/DirectEmployers/MyJobs/stargazers","contributors_url":"https://api.github.com/repos/DirectEmployers/MyJobs/contributors","subscribers_url":"https://api.github.com/repos/DirectEmployers/MyJobs/subscribers","subscription_url":"https://api.github.com/repos/DirectEmployers/MyJobs/subscription","commits_url":"https://api.github.com/repos/DirectEmployers/MyJobs/commits{/sha}","git_commits_url":"https://api.github.com/repos/DirectEmployers/MyJobs/git/commits{/sha}","comments_url":"https://api.github.com/repos/DirectEmployers/MyJobs/comments{/number}","issue_comment_url":"https://api.github.com/repos/DirectEmployers/MyJobs/issues/comments{/number}","contents_url":"https://api.github.com/repos/DirectEmployers/MyJobs/contents/{+path}","compare_url":"https://api.github.com/repos/DirectEmployers/MyJobs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DirectEmployers/MyJobs/merges","archive_url":"https://api.github.com/repos/DirectEmployers/MyJobs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DirectEmployers/MyJobs/downloads","issues_url":"https://api.github.com/repos/DirectEmployers/MyJobs/issues{/number}","pulls_url":"https://api.github.com/repos/DirectEmployers/MyJobs/pulls{/number}","milestones_url":"https://api.github.com/repos/DirectEmployers/MyJobs/milestones{/number}","notifications_url":"https://api.github.com/repos/DirectEmployers/MyJobs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DirectEmployers/MyJobs/labels{/name}","releases_url":"https://api.github.com/repos/DirectEmployers/MyJobs/releases{/id}","created_at":"2011-11-28T15:22:36Z","updated_at":"2015-12-23T15:59:16Z","pushed_at":"2016-01-08T20:38:20Z","git_url":"git://github.com/DirectEmployers/MyJobs.git","ssh_url":"git@github.com:DirectEmployers/MyJobs.git","clone_url":"https://github.com/DirectEmployers/MyJobs.git","svn_url":"https://github.com/DirectEmployers/MyJobs","homepage":"http://my.jobs","size":34848,"stargazers_count":6,"watchers_count":6,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":10,"mirror_url":null,"open_issues_count":8,"forks":10,"open_issues":8,"watchers":6,"default_branch":"quality-control"}},"_links":{"self":{"href":"https://api.github.com/repos/DirectEmployers/MyJobs/pulls/2010"},"html":{"href":"https://github.com/DirectEmployers/MyJobs/pull/2010"},"issue":{"href":"https://api.github.com/repos/DirectEmployers/MyJobs/issues/2010"},"comments":{"href":"https://api.github.com/repos/DirectEmployers/MyJobs/issues/2010/comments"},"review_comments":{"href":"https://api.github.com/repos/DirectEmployers/MyJobs/pulls/2010/comments"},"review_comment":{"href":"https://api.github.com/repos/DirectEmployers/MyJobs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DirectEmployers/MyJobs/pulls/2010/commits"},"statuses":{"href":"https://api.github.com/repos/DirectEmployers/MyJobs/statuses/91048de8067a3a7ef6b4868756389928e049f7de"}}}}