{"action":"created","comment":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/30771157","id":30771157,"diff_hunk":"@@ -0,0 +1,85 @@\n+\"\"\"Run nightly, this script will activate any pending embargoes that have\n+elapsed the pending approval time and make public and registrations whose\n+embargo end dates have been passed.\n+\"\"\"\n+\n+import datetime\n+import logging\n+import sys\n+\n+from modularodm import Q\n+\n+from framework.auth import Auth\n+from website import models, settings\n+from website.app import init_app\n+from website.project.model import NodeLog\n+from scripts import utils as scripts_utils\n+\n+\n+logger = logging.getLogger(__name__)\n+logging.basicConfig(level=logging.INFO)\n+\n+\n+def main(dry_run=True):\n+    pending_embargoes = models.Embargo.find(Q('state', 'eq', models.Embargo.UNAPPROVED))\n+    for embargo in pending_embargoes:\n+        if should_be_embargoed(embargo):\n+            if dry_run:\n+                logger.warn('Dry run mode')\n+            parent_registration = models.Node.find_one(Q('embargo', 'eq', embargo))\n+            logger.warn(\n+                'Embargo {0} approved. Activating embargo for registration {1}'\n+                .format(embargo._id, parent_registration._id)\n+            )\n+            if not dry_run:\n+                embargo.state = models.Embargo.ACTIVE\n+                parent_registration.add_log(\n+                    action=NodeLog.EMBARGO_APPROVED,\n+                    params={\n+                        'registration_id': parent_registration._id,\n+                        'embargo_id': embargo._id,\n+                    },\n+                    auth=Auth(parent_registration.embargo.initiated_by),\n+                    log_date=datetime.datetime.utcnow(),\n+                    save=False,\n+                )\n+                embargo.save()\n+\n+    active_embargoes = models.Embargo.find(Q('state', 'eq', models.Embargo.ACTIVE))\n+    for embargo in active_embargoes:\n+        if embargo.end_date < datetime.datetime.utcnow():\n+            parent_registration = models.Node.find_one(Q('embargo', 'eq', embargo))\n+            if dry_run:\n+                logger.warn('Dry run mode')\n+            parent_registration = models.Node.find_one(Q('embargo', 'eq', embargo))\n+            logger.warn(\n+                'Embargo {0} complete. Making registration {1} public'\n+                .format(embargo._id, parent_registration._id)\n+            )\n+            if not dry_run:\n+                parent_registration.set_privacy('public')","path":"scripts/embargo_registrations.py","position":60,"original_position":60,"commit_id":"e0fb4e3ecc27d5cddcab2ccbc712769bfaef002f","original_commit_id":"e0fb4e3ecc27d5cddcab2ccbc712769bfaef002f","user":{"login":"sloria","id":2379650,"avatar_url":"https://avatars.githubusercontent.com/u/2379650?v=3","gravatar_id":"","url":"https://api.github.com/users/sloria","html_url":"https://github.com/sloria","followers_url":"https://api.github.com/users/sloria/followers","following_url":"https://api.github.com/users/sloria/following{/other_user}","gists_url":"https://api.github.com/users/sloria/gists{/gist_id}","starred_url":"https://api.github.com/users/sloria/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sloria/subscriptions","organizations_url":"https://api.github.com/users/sloria/orgs","repos_url":"https://api.github.com/users/sloria/repos","events_url":"https://api.github.com/users/sloria/events{/privacy}","received_events_url":"https://api.github.com/users/sloria/received_events","type":"User","site_admin":false},"body":"This should be done in a Toku transaction.","created_at":"2015-05-21T03:49:59Z","updated_at":"2015-05-21T03:49:59Z","html_url":"https://github.com/CenterForOpenScience/osf.io/pull/2647#discussion_r30771157","pull_request_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/2647","_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/30771157"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/2647#discussion_r30771157"},"pull_request":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/2647"}}},"pull_request":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/2647","id":34829551,"html_url":"https://github.com/CenterForOpenScience/osf.io/pull/2647","diff_url":"https://github.com/CenterForOpenScience/osf.io/pull/2647.diff","patch_url":"https://github.com/CenterForOpenScience/osf.io/pull/2647.patch","issue_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/2647","number":2647,"state":"open","locked":false,"title":"[feature] add registration embargo","user":{"login":"HarryRybacki","id":2614670,"avatar_url":"https://avatars.githubusercontent.com/u/2614670?v=3","gravatar_id":"","url":"https://api.github.com/users/HarryRybacki","html_url":"https://github.com/HarryRybacki","followers_url":"https://api.github.com/users/HarryRybacki/followers","following_url":"https://api.github.com/users/HarryRybacki/following{/other_user}","gists_url":"https://api.github.com/users/HarryRybacki/gists{/gist_id}","starred_url":"https://api.github.com/users/HarryRybacki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HarryRybacki/subscriptions","organizations_url":"https://api.github.com/users/HarryRybacki/orgs","repos_url":"https://api.github.com/users/HarryRybacki/repos","events_url":"https://api.github.com/users/HarryRybacki/events{/privacy}","received_events_url":"https://api.github.com/users/HarryRybacki/received_events","type":"User","site_admin":false},"body":"## Purpose\r\n\r\nCurrently users that want to make a registration public are required to do so at the time they change the settings of the registration. A user wanting to wait some duration before making their registration public after making this decision must set a reminder (not through the OSF), go back to the registration settings once reminded, and manually set it to public at that time. This is prone to user error e.g. setting a reminder incorrectly, forgetfulness, or changing their mind.\r\n\r\nUsers have requested that when making a registration public they would be provided with a user defined embargo period.\r\n\r\n## Changes\r\n\r\nWhen a user wants to register a project, they will have to choose between making the new registration either **public immediately** or request that it be entered into an **embargo period** at the end of which the registration will be made public.\r\n\r\nIf the user requests an embargo period, all admins on the project *at the time the request is initiated* will be emailed for approval or disapproval of the request. One admin can disapprove the embargo, deleting the registration and stopping the process. All admins are required to approve the embargo make it active immediately. Alternatively, if no admin has disapproved but not all admins have approved after a predefined time (set in defaults.py) a cron job will automatically  activate pending embargoes.\r\n\r\nOnce an embargo has been activated, the only way to cancel it is to request a retraction for the registration it is associated with.\r\n\r\n## Side-Effects\r\n\r\nThis PR touches many places throughout the code base. Aside from the obvious dangers of adding to Node, adjusting the project templates, and adding routes there are many little gotchas that could crop up.\r\n\r\nRegistrations that are private at the time this feature is released will be grandfathered into the old registration policy and will not be required to set an embargo date. \r\n\r\n## Notes:\r\nDepends on PR #2533\r\n","created_at":"2015-05-06T15:37:22Z","updated_at":"2015-05-21T03:49:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"71525ecf3dfaaffad81b12d2a36aecf018b4e084","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/2647/commits","review_comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/2647/comments","review_comment_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/2647/comments","statuses_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/e0fb4e3ecc27d5cddcab2ccbc712769bfaef002f","head":{"label":"HarryRybacki:feature/add_registration_embargo","ref":"feature/add_registration_embargo","sha":"e0fb4e3ecc27d5cddcab2ccbc712769bfaef002f","user":{"login":"HarryRybacki","id":2614670,"avatar_url":"https://avatars.githubusercontent.com/u/2614670?v=3","gravatar_id":"","url":"https://api.github.com/users/HarryRybacki","html_url":"https://github.com/HarryRybacki","followers_url":"https://api.github.com/users/HarryRybacki/followers","following_url":"https://api.github.com/users/HarryRybacki/following{/other_user}","gists_url":"https://api.github.com/users/HarryRybacki/gists{/gist_id}","starred_url":"https://api.github.com/users/HarryRybacki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HarryRybacki/subscriptions","organizations_url":"https://api.github.com/users/HarryRybacki/orgs","repos_url":"https://api.github.com/users/HarryRybacki/repos","events_url":"https://api.github.com/users/HarryRybacki/events{/privacy}","received_events_url":"https://api.github.com/users/HarryRybacki/received_events","type":"User","site_admin":false},"repo":{"id":30415497,"name":"osf.io","full_name":"HarryRybacki/osf.io","owner":{"login":"HarryRybacki","id":2614670,"avatar_url":"https://avatars.githubusercontent.com/u/2614670?v=3","gravatar_id":"","url":"https://api.github.com/users/HarryRybacki","html_url":"https://github.com/HarryRybacki","followers_url":"https://api.github.com/users/HarryRybacki/followers","following_url":"https://api.github.com/users/HarryRybacki/following{/other_user}","gists_url":"https://api.github.com/users/HarryRybacki/gists{/gist_id}","starred_url":"https://api.github.com/users/HarryRybacki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HarryRybacki/subscriptions","organizations_url":"https://api.github.com/users/HarryRybacki/orgs","repos_url":"https://api.github.com/users/HarryRybacki/repos","events_url":"https://api.github.com/users/HarryRybacki/events{/privacy}","received_events_url":"https://api.github.com/users/HarryRybacki/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/HarryRybacki/osf.io","description":"Facilitating Open Science","fork":true,"url":"https://api.github.com/repos/HarryRybacki/osf.io","forks_url":"https://api.github.com/repos/HarryRybacki/osf.io/forks","keys_url":"https://api.github.com/repos/HarryRybacki/osf.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HarryRybacki/osf.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HarryRybacki/osf.io/teams","hooks_url":"https://api.github.com/repos/HarryRybacki/osf.io/hooks","issue_events_url":"https://api.github.com/repos/HarryRybacki/osf.io/issues/events{/number}","events_url":"https://api.github.com/repos/HarryRybacki/osf.io/events","assignees_url":"https://api.github.com/repos/HarryRybacki/osf.io/assignees{/user}","branches_url":"https://api.github.com/repos/HarryRybacki/osf.io/branches{/branch}","tags_url":"https://api.github.com/repos/HarryRybacki/osf.io/tags","blobs_url":"https://api.github.com/repos/HarryRybacki/osf.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HarryRybacki/osf.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HarryRybacki/osf.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/HarryRybacki/osf.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HarryRybacki/osf.io/statuses/{sha}","languages_url":"https://api.github.com/repos/HarryRybacki/osf.io/languages","stargazers_url":"https://api.github.com/repos/HarryRybacki/osf.io/stargazers","contributors_url":"https://api.github.com/repos/HarryRybacki/osf.io/contributors","subscribers_url":"https://api.github.com/repos/HarryRybacki/osf.io/subscribers","subscription_url":"https://api.github.com/repos/HarryRybacki/osf.io/subscription","commits_url":"https://api.github.com/repos/HarryRybacki/osf.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/HarryRybacki/osf.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/HarryRybacki/osf.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/HarryRybacki/osf.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/HarryRybacki/osf.io/contents/{+path}","compare_url":"https://api.github.com/repos/HarryRybacki/osf.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HarryRybacki/osf.io/merges","archive_url":"https://api.github.com/repos/HarryRybacki/osf.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HarryRybacki/osf.io/downloads","issues_url":"https://api.github.com/repos/HarryRybacki/osf.io/issues{/number}","pulls_url":"https://api.github.com/repos/HarryRybacki/osf.io/pulls{/number}","milestones_url":"https://api.github.com/repos/HarryRybacki/osf.io/milestones{/number}","notifications_url":"https://api.github.com/repos/HarryRybacki/osf.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HarryRybacki/osf.io/labels{/name}","releases_url":"https://api.github.com/repos/HarryRybacki/osf.io/releases{/id}","created_at":"2015-02-06T14:18:39Z","updated_at":"2015-04-20T13:52:21Z","pushed_at":"2015-05-20T19:44:40Z","git_url":"git://github.com/HarryRybacki/osf.io.git","ssh_url":"git@github.com:HarryRybacki/osf.io.git","clone_url":"https://github.com/HarryRybacki/osf.io.git","svn_url":"https://github.com/HarryRybacki/osf.io","homepage":"http://osf.io","size":87598,"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":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"develop"}},"base":{"label":"CenterForOpenScience:develop","ref":"develop","sha":"2b3be8ecc74e61c5ae68a74faafbb77d144a8201","user":{"login":"CenterForOpenScience","id":3344584,"avatar_url":"https://avatars.githubusercontent.com/u/3344584?v=3","gravatar_id":"","url":"https://api.github.com/users/CenterForOpenScience","html_url":"https://github.com/CenterForOpenScience","followers_url":"https://api.github.com/users/CenterForOpenScience/followers","following_url":"https://api.github.com/users/CenterForOpenScience/following{/other_user}","gists_url":"https://api.github.com/users/CenterForOpenScience/gists{/gist_id}","starred_url":"https://api.github.com/users/CenterForOpenScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CenterForOpenScience/subscriptions","organizations_url":"https://api.github.com/users/CenterForOpenScience/orgs","repos_url":"https://api.github.com/users/CenterForOpenScience/repos","events_url":"https://api.github.com/users/CenterForOpenScience/events{/privacy}","received_events_url":"https://api.github.com/users/CenterForOpenScience/received_events","type":"Organization","site_admin":false},"repo":{"id":10199599,"name":"osf.io","full_name":"CenterForOpenScience/osf.io","owner":{"login":"CenterForOpenScience","id":3344584,"avatar_url":"https://avatars.githubusercontent.com/u/3344584?v=3","gravatar_id":"","url":"https://api.github.com/users/CenterForOpenScience","html_url":"https://github.com/CenterForOpenScience","followers_url":"https://api.github.com/users/CenterForOpenScience/followers","following_url":"https://api.github.com/users/CenterForOpenScience/following{/other_user}","gists_url":"https://api.github.com/users/CenterForOpenScience/gists{/gist_id}","starred_url":"https://api.github.com/users/CenterForOpenScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CenterForOpenScience/subscriptions","organizations_url":"https://api.github.com/users/CenterForOpenScience/orgs","repos_url":"https://api.github.com/users/CenterForOpenScience/repos","events_url":"https://api.github.com/users/CenterForOpenScience/events{/privacy}","received_events_url":"https://api.github.com/users/CenterForOpenScience/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CenterForOpenScience/osf.io","description":"Facilitating Open Science","fork":false,"url":"https://api.github.com/repos/CenterForOpenScience/osf.io","forks_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/forks","keys_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/teams","hooks_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/hooks","issue_events_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/events{/number}","events_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/events","assignees_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/assignees{/user}","branches_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/branches{/branch}","tags_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/tags","blobs_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/{sha}","languages_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/languages","stargazers_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/stargazers","contributors_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/contributors","subscribers_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/subscribers","subscription_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/subscription","commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/contents/{+path}","compare_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/merges","archive_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/downloads","issues_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues{/number}","pulls_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls{/number}","milestones_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/milestones{/number}","notifications_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/labels{/name}","releases_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/releases{/id}","created_at":"2013-05-21T15:53:37Z","updated_at":"2015-05-20T22:52:47Z","pushed_at":"2015-05-21T03:25:12Z","git_url":"git://github.com/CenterForOpenScience/osf.io.git","ssh_url":"git@github.com:CenterForOpenScience/osf.io.git","clone_url":"https://github.com/CenterForOpenScience/osf.io.git","svn_url":"https://github.com/CenterForOpenScience/osf.io","homepage":"http://osf.io","size":209665,"stargazers_count":103,"watchers_count":103,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":87,"mirror_url":null,"open_issues_count":406,"forks":87,"open_issues":406,"watchers":103,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/2647"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/2647"},"issue":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/2647"},"comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/2647/comments"},"review_comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/2647/comments"},"review_comment":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/2647/commits"},"statuses":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/e0fb4e3ecc27d5cddcab2ccbc712769bfaef002f"}}}}