{"action":"created","comment":{"url":"https://api.github.com/repos/ocf/utils/pulls/comments/43470773","id":43470773,"diff_hunk":"@@ -15,60 +15,98 @@ from ocflib.ucb.groups import (\n     signatories_for_group,\n     groups_by_student_signat,\n )\n-from ocflib.misc.shell import red\n+from ocflib.misc.shell import red, yellow\n from tabulate import tabulate\n \n \n-def print_table(title, columns, headers):\n+def print_table(title, columns, headers, subtitle=None):\n     \"\"\"Pretty print a table of groups or signatories.\"\"\"\n-    bar = '=' * len(title)\n     print(title)\n+    if subtitle:\n+        print(subtitle)\n+        bar_len = max(len(title), len(subtitle))\n+    else:\n+        bar_len = len(title)\n+    bar = '=' * bar_len\n     print(bar)\n     print(tabulate(columns, headers=headers))\n \n \n-def show_groups_by_signat_username(username):\n-    \"\"\"Show group signatory status of an OCF user.\"\"\"\n+def show_by_username(username):\n+    \"\"\"Show signatory info about an individual or group account.\"\"\"\n     attrs = search.user_attrs(username)\n     if attrs is None:\n-        print(red(\"Username not found.\"))\n-        return\n-    elif 'calnetUid' not in attrs:\n-        print(red(\"CalNet UID not found.\"))\n+        print(red(\"User not found.\"))\n         return\n \n-    show_groups_by_student_signat(int(attrs['calnetUid'][0]))\n+    uid = attrs.get('calnetUid', [None])[0]\n+    oid = attrs.get('callinkOid', [None])[0]\n+\n+    if uid and oid:\n+        print(yellow(\"Both CalNet UID and CalLink OID are defined for \" +\n+            \"this account.\"))\n+        show_groups_by_student_signat(int(uid))\n+        print()\n+        show_signatories_for_group(int(oid))\n+    elif uid:\n+        show_groups_by_student_signat(int(uid))\n+    elif oid:\n+        show_signatories_for_group(int(oid))\n+    else:\n+        print(red(\"This account has no CalNet UID or CalLink OID.\"))\n \n def show_signatories_for_group(oid, signatories=None):\n     \"\"\"Show all signatories for a group.\"\"\"\n     if signatories is None:\n         signatories = signatories_for_group(oid)\n+    group = group_by_oid(oid)\n \n-    if not signatories:\n-        print(red(\"No signatories found.\"))\n+    if not signatories and not group:\n+        print(red(\"CalLink OID {} not found.\".format(oid)))\n         return\n-\n-    name = group_by_oid(oid)['name']\n-    title = \"{} ({})\".format(name, oid)\n-    columns = [(attrs['name'], uid) for (uid, attrs) in signatories.items()]\n+    elif not signatories:\n+        print(red(\"CalLink OID {} currently has no signatories.\".format(oid)))\n+        return\n+    elif not group:\n+        print(yellow((\"CalLink OID {} has signatories but is currently not \" +\n+            \"active on CalLink.\").format(oid)))\n+\n+    if group:\n+        if group['accounts']:\n+            subtitle = \"Group accounts: {}\".format(', '.join(group['accounts']))\n+        else:\n+            subtitle = None\n+        title = '{} ({})'.format(group['name'], oid)\n+    else:\n+        subtitle = None\n+        title = \"Unkown group ({})\".format(oid)\n+\n+    columns = [(attrs['name'], uid) for uid, attrs in signatories.items()]\n     headers = ('Signatory', 'UID')\n \n-    print_table(title, columns, headers)\n+    print_table(title, columns, headers, subtitle=subtitle)\n \n \n def show_groups_by_student_signat(uid, groups=None):\n     \"\"\"Show signatory status of a person on CalLink.\"\"\"\n+    name = directory.name_by_calnet_uid(uid)\n+\n+    if not name:\n+        print(red(\"CalNet UID {} not found.\").format(uid))\n+        return\n+\n     if groups is None:\n         groups = groups_by_student_signat(uid)\n \n     if not groups:\n-        print(red(\"No active student groups found.\"))\n+        print(red(\"CalNet UID {} not a signatory of any active student \" +\n+            \"groups.\").format(uid))\n         return\n \n-    name = directory.name_by_calnet_uid(uid)\n-    title = \"{} ({})\".format(name, uid)\n-    columns = [(attrs['name'], uid) for (uid, attrs) in groups.items()]\n-    headers = ('Group', 'OID')\n+    title = '{} ({})'.format(name, uid)\n+    columns = [(attrs['name'], ', '.join(attrs['accounts']) or 'n/a', oid) for\n+            oid, attrs in groups.items()]","path":"staff/acct/signat","position":116,"original_position":116,"commit_id":"6df57b84ab429720b44978472472636e6738855a","original_commit_id":"6df57b84ab429720b44978472472636e6738855a","user":{"login":"matthew-mcallister","id":6722367,"avatar_url":"https://avatars.githubusercontent.com/u/6722367?v=3","gravatar_id":"","url":"https://api.github.com/users/matthew-mcallister","html_url":"https://github.com/matthew-mcallister","followers_url":"https://api.github.com/users/matthew-mcallister/followers","following_url":"https://api.github.com/users/matthew-mcallister/following{/other_user}","gists_url":"https://api.github.com/users/matthew-mcallister/gists{/gist_id}","starred_url":"https://api.github.com/users/matthew-mcallister/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthew-mcallister/subscriptions","organizations_url":"https://api.github.com/users/matthew-mcallister/orgs","repos_url":"https://api.github.com/users/matthew-mcallister/repos","events_url":"https://api.github.com/users/matthew-mcallister/events{/privacy}","received_events_url":"https://api.github.com/users/matthew-mcallister/received_events","type":"User","site_admin":false},"body":"Sorry, I just auto-linebreak after 79 characters. Feel free to apply coding standards.","created_at":"2015-10-30T04:22:26Z","updated_at":"2015-10-30T04:22:26Z","html_url":"https://github.com/ocf/utils/pull/5#discussion_r43470773","pull_request_url":"https://api.github.com/repos/ocf/utils/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/ocf/utils/pulls/comments/43470773"},"html":{"href":"https://github.com/ocf/utils/pull/5#discussion_r43470773"},"pull_request":{"href":"https://api.github.com/repos/ocf/utils/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/ocf/utils/pulls/5","id":49225626,"html_url":"https://github.com/ocf/utils/pull/5","diff_url":"https://github.com/ocf/utils/pull/5.diff","patch_url":"https://github.com/ocf/utils/pull/5.patch","issue_url":"https://api.github.com/repos/ocf/utils/issues/5","number":5,"state":"open","locked":false,"title":"Improvements to signat","user":{"login":"matthew-mcallister","id":6722367,"avatar_url":"https://avatars.githubusercontent.com/u/6722367?v=3","gravatar_id":"","url":"https://api.github.com/users/matthew-mcallister","html_url":"https://github.com/matthew-mcallister","followers_url":"https://api.github.com/users/matthew-mcallister/followers","following_url":"https://api.github.com/users/matthew-mcallister/following{/other_user}","gists_url":"https://api.github.com/users/matthew-mcallister/gists{/gist_id}","starred_url":"https://api.github.com/users/matthew-mcallister/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthew-mcallister/subscriptions","organizations_url":"https://api.github.com/users/matthew-mcallister/orgs","repos_url":"https://api.github.com/users/matthew-mcallister/repos","events_url":"https://api.github.com/users/matthew-mcallister/events{/privacy}","received_events_url":"https://api.github.com/users/matthew-mcallister/received_events","type":"User","site_admin":false},"body":"Handles some weird cases which just came up. Also now shows OCF accounts for student groups.","created_at":"2015-10-30T02:44:41Z","updated_at":"2015-10-30T04:22:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"549f7d45362fcbb7f2ba02634ff5e88ef33c5580","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ocf/utils/pulls/5/commits","review_comments_url":"https://api.github.com/repos/ocf/utils/pulls/5/comments","review_comment_url":"https://api.github.com/repos/ocf/utils/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ocf/utils/issues/5/comments","statuses_url":"https://api.github.com/repos/ocf/utils/statuses/6df57b84ab429720b44978472472636e6738855a","head":{"label":"matthew-mcallister:signat-tweaks","ref":"signat-tweaks","sha":"6df57b84ab429720b44978472472636e6738855a","user":{"login":"matthew-mcallister","id":6722367,"avatar_url":"https://avatars.githubusercontent.com/u/6722367?v=3","gravatar_id":"","url":"https://api.github.com/users/matthew-mcallister","html_url":"https://github.com/matthew-mcallister","followers_url":"https://api.github.com/users/matthew-mcallister/followers","following_url":"https://api.github.com/users/matthew-mcallister/following{/other_user}","gists_url":"https://api.github.com/users/matthew-mcallister/gists{/gist_id}","starred_url":"https://api.github.com/users/matthew-mcallister/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthew-mcallister/subscriptions","organizations_url":"https://api.github.com/users/matthew-mcallister/orgs","repos_url":"https://api.github.com/users/matthew-mcallister/repos","events_url":"https://api.github.com/users/matthew-mcallister/events{/privacy}","received_events_url":"https://api.github.com/users/matthew-mcallister/received_events","type":"User","site_admin":false},"repo":{"id":45167899,"name":"utils","full_name":"matthew-mcallister/utils","owner":{"login":"matthew-mcallister","id":6722367,"avatar_url":"https://avatars.githubusercontent.com/u/6722367?v=3","gravatar_id":"","url":"https://api.github.com/users/matthew-mcallister","html_url":"https://github.com/matthew-mcallister","followers_url":"https://api.github.com/users/matthew-mcallister/followers","following_url":"https://api.github.com/users/matthew-mcallister/following{/other_user}","gists_url":"https://api.github.com/users/matthew-mcallister/gists{/gist_id}","starred_url":"https://api.github.com/users/matthew-mcallister/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthew-mcallister/subscriptions","organizations_url":"https://api.github.com/users/matthew-mcallister/orgs","repos_url":"https://api.github.com/users/matthew-mcallister/repos","events_url":"https://api.github.com/users/matthew-mcallister/events{/privacy}","received_events_url":"https://api.github.com/users/matthew-mcallister/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/matthew-mcallister/utils","description":"User and staff utilities for the Open Computing Facility","fork":true,"url":"https://api.github.com/repos/matthew-mcallister/utils","forks_url":"https://api.github.com/repos/matthew-mcallister/utils/forks","keys_url":"https://api.github.com/repos/matthew-mcallister/utils/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matthew-mcallister/utils/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matthew-mcallister/utils/teams","hooks_url":"https://api.github.com/repos/matthew-mcallister/utils/hooks","issue_events_url":"https://api.github.com/repos/matthew-mcallister/utils/issues/events{/number}","events_url":"https://api.github.com/repos/matthew-mcallister/utils/events","assignees_url":"https://api.github.com/repos/matthew-mcallister/utils/assignees{/user}","branches_url":"https://api.github.com/repos/matthew-mcallister/utils/branches{/branch}","tags_url":"https://api.github.com/repos/matthew-mcallister/utils/tags","blobs_url":"https://api.github.com/repos/matthew-mcallister/utils/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matthew-mcallister/utils/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matthew-mcallister/utils/git/refs{/sha}","trees_url":"https://api.github.com/repos/matthew-mcallister/utils/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matthew-mcallister/utils/statuses/{sha}","languages_url":"https://api.github.com/repos/matthew-mcallister/utils/languages","stargazers_url":"https://api.github.com/repos/matthew-mcallister/utils/stargazers","contributors_url":"https://api.github.com/repos/matthew-mcallister/utils/contributors","subscribers_url":"https://api.github.com/repos/matthew-mcallister/utils/subscribers","subscription_url":"https://api.github.com/repos/matthew-mcallister/utils/subscription","commits_url":"https://api.github.com/repos/matthew-mcallister/utils/commits{/sha}","git_commits_url":"https://api.github.com/repos/matthew-mcallister/utils/git/commits{/sha}","comments_url":"https://api.github.com/repos/matthew-mcallister/utils/comments{/number}","issue_comment_url":"https://api.github.com/repos/matthew-mcallister/utils/issues/comments{/number}","contents_url":"https://api.github.com/repos/matthew-mcallister/utils/contents/{+path}","compare_url":"https://api.github.com/repos/matthew-mcallister/utils/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matthew-mcallister/utils/merges","archive_url":"https://api.github.com/repos/matthew-mcallister/utils/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matthew-mcallister/utils/downloads","issues_url":"https://api.github.com/repos/matthew-mcallister/utils/issues{/number}","pulls_url":"https://api.github.com/repos/matthew-mcallister/utils/pulls{/number}","milestones_url":"https://api.github.com/repos/matthew-mcallister/utils/milestones{/number}","notifications_url":"https://api.github.com/repos/matthew-mcallister/utils/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matthew-mcallister/utils/labels{/name}","releases_url":"https://api.github.com/repos/matthew-mcallister/utils/releases{/id}","created_at":"2015-10-29T07:42:23Z","updated_at":"2015-10-29T07:42:24Z","pushed_at":"2015-10-30T02:42:45Z","git_url":"git://github.com/matthew-mcallister/utils.git","ssh_url":"git@github.com:matthew-mcallister/utils.git","clone_url":"https://github.com/matthew-mcallister/utils.git","svn_url":"https://github.com/matthew-mcallister/utils","homepage":"https://www.ocf.berkeley.edu/","size":600,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ocf:master","ref":"master","sha":"a08f7c10db71c446eabe087d094106f4591efff7","user":{"login":"ocf","id":1504667,"avatar_url":"https://avatars.githubusercontent.com/u/1504667?v=3","gravatar_id":"","url":"https://api.github.com/users/ocf","html_url":"https://github.com/ocf","followers_url":"https://api.github.com/users/ocf/followers","following_url":"https://api.github.com/users/ocf/following{/other_user}","gists_url":"https://api.github.com/users/ocf/gists{/gist_id}","starred_url":"https://api.github.com/users/ocf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ocf/subscriptions","organizations_url":"https://api.github.com/users/ocf/orgs","repos_url":"https://api.github.com/users/ocf/repos","events_url":"https://api.github.com/users/ocf/events{/privacy}","received_events_url":"https://api.github.com/users/ocf/received_events","type":"Organization","site_admin":false},"repo":{"id":20369692,"name":"utils","full_name":"ocf/utils","owner":{"login":"ocf","id":1504667,"avatar_url":"https://avatars.githubusercontent.com/u/1504667?v=3","gravatar_id":"","url":"https://api.github.com/users/ocf","html_url":"https://github.com/ocf","followers_url":"https://api.github.com/users/ocf/followers","following_url":"https://api.github.com/users/ocf/following{/other_user}","gists_url":"https://api.github.com/users/ocf/gists{/gist_id}","starred_url":"https://api.github.com/users/ocf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ocf/subscriptions","organizations_url":"https://api.github.com/users/ocf/orgs","repos_url":"https://api.github.com/users/ocf/repos","events_url":"https://api.github.com/users/ocf/events{/privacy}","received_events_url":"https://api.github.com/users/ocf/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ocf/utils","description":"User and staff utilities for the Open Computing Facility","fork":false,"url":"https://api.github.com/repos/ocf/utils","forks_url":"https://api.github.com/repos/ocf/utils/forks","keys_url":"https://api.github.com/repos/ocf/utils/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ocf/utils/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ocf/utils/teams","hooks_url":"https://api.github.com/repos/ocf/utils/hooks","issue_events_url":"https://api.github.com/repos/ocf/utils/issues/events{/number}","events_url":"https://api.github.com/repos/ocf/utils/events","assignees_url":"https://api.github.com/repos/ocf/utils/assignees{/user}","branches_url":"https://api.github.com/repos/ocf/utils/branches{/branch}","tags_url":"https://api.github.com/repos/ocf/utils/tags","blobs_url":"https://api.github.com/repos/ocf/utils/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ocf/utils/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ocf/utils/git/refs{/sha}","trees_url":"https://api.github.com/repos/ocf/utils/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ocf/utils/statuses/{sha}","languages_url":"https://api.github.com/repos/ocf/utils/languages","stargazers_url":"https://api.github.com/repos/ocf/utils/stargazers","contributors_url":"https://api.github.com/repos/ocf/utils/contributors","subscribers_url":"https://api.github.com/repos/ocf/utils/subscribers","subscription_url":"https://api.github.com/repos/ocf/utils/subscription","commits_url":"https://api.github.com/repos/ocf/utils/commits{/sha}","git_commits_url":"https://api.github.com/repos/ocf/utils/git/commits{/sha}","comments_url":"https://api.github.com/repos/ocf/utils/comments{/number}","issue_comment_url":"https://api.github.com/repos/ocf/utils/issues/comments{/number}","contents_url":"https://api.github.com/repos/ocf/utils/contents/{+path}","compare_url":"https://api.github.com/repos/ocf/utils/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ocf/utils/merges","archive_url":"https://api.github.com/repos/ocf/utils/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ocf/utils/downloads","issues_url":"https://api.github.com/repos/ocf/utils/issues{/number}","pulls_url":"https://api.github.com/repos/ocf/utils/pulls{/number}","milestones_url":"https://api.github.com/repos/ocf/utils/milestones{/number}","notifications_url":"https://api.github.com/repos/ocf/utils/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ocf/utils/labels{/name}","releases_url":"https://api.github.com/repos/ocf/utils/releases{/id}","created_at":"2014-06-01T02:50:07Z","updated_at":"2015-10-29T19:41:12Z","pushed_at":"2015-10-30T02:44:42Z","git_url":"git://github.com/ocf/utils.git","ssh_url":"git@github.com:ocf/utils.git","clone_url":"https://github.com/ocf/utils.git","svn_url":"https://github.com/ocf/utils","homepage":"https://www.ocf.berkeley.edu/","size":600,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ocf/utils/pulls/5"},"html":{"href":"https://github.com/ocf/utils/pull/5"},"issue":{"href":"https://api.github.com/repos/ocf/utils/issues/5"},"comments":{"href":"https://api.github.com/repos/ocf/utils/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/ocf/utils/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/ocf/utils/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ocf/utils/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/ocf/utils/statuses/6df57b84ab429720b44978472472636e6738855a"}}}}