{"action":"created","comment":{"url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/pulls/comments/186900047","pull_request_review_id":118571966,"id":186900047,"diff_hunk":"@@ -294,45 +340,78 @@ private void sendWithdrawEmail(Study study, String externalId, Account account,\n     }\n \n     /**\n-     * Email the participant's signed consent agreement to the user's email address.\n-     * @param study\n-     * @param subpopGuid\n-     * @param participant\n+     * Resend the participant's signed consent agreement via the user's email address or their phone number. \n+     * It is an error to call this method if no channel exists to send the consent to the user.\n      */\n-    public void emailConsentAgreement(Study study, SubpopulationGuid subpopGuid, StudyParticipant participant) {\n+    public void resendConsentAgreement(Study study, SubpopulationGuid subpopGuid, StudyParticipant participant) {\n         checkNotNull(study);\n         checkNotNull(subpopGuid);\n         checkNotNull(participant);\n \n         ConsentSignature consentSignature = getConsentSignature(study, subpopGuid, participant.getId());\n         SharingScope sharingScope = participant.getSharingScope();\n         Subpopulation subpop = subpopService.getSubpopulation(study.getStudyIdentifier(), subpopGuid);\n-        \n         String studyConsentDocument = studyConsentService.getActiveConsent(subpop).getDocumentContent();\n \n+        boolean verifiedEmail = (participant.getEmail() != null\n+                && Boolean.TRUE.equals(participant.getEmailVerified()));\n+        boolean verifiedPhone = (participant.getPhone() != null\n+                && Boolean.TRUE.equals(participant.getPhoneVerified()));\n+        \n         ConsentPdf consentPdf = new ConsentPdf(study, participant.getTimeZone(), participant.getEmail(),\n                 consentSignature, sharingScope, studyConsentDocument, xmlTemplateWithSignatureBlock);            \n         \n-        BasicEmailProvider.Builder builder = new BasicEmailProvider.Builder()\n-                .withStudy(study)\n-                .withEmailTemplate(study.getSignedConsentTemplate())\n-                .withBinaryAttachment(\"consent.pdf\", MimeType.PDF, consentPdf.getBytes())\n-                .withRecipientEmail(participant.getEmail());\n-        addStudyConsentRecipients(study, builder);\n-        // If the user doesn't have an email, we won't send anything. Note that as of this refactor, \n-        // we're not verifying the email address. Change this when SMS is added.\n-        BasicEmailProvider provider = builder.build();\n-        if (!provider.getRecipientEmails().isEmpty()) {\n+        if (verifiedEmail) {\n+            BasicEmailProvider provider = new BasicEmailProvider.Builder()\n+                    .withStudy(study)\n+                    .withEmailTemplate(study.getSignedConsentTemplate())\n+                    .withBinaryAttachment(\"consent.pdf\", MimeType.PDF, consentPdf.getBytes())\n+                    .withRecipientEmail(participant.getEmail()).build();\n             sendMailService.sendEmail(provider);\n+        } else if (verifiedPhone) {\n+            sendConsentViaSMS(study, subpop, participant, consentPdf);\n+        } else {\n+            throw new BadRequestException(\"Participant does not have a valid email address or phone number\");\n+        }\n+    }\n+    \n+    private void sendConsentViaSMS(Study study, Subpopulation subpop, StudyParticipant participant,\n+            ConsentPdf consentPdf) {\n+        String shortUrl = null;\n+        try {\n+            String fileName = getSignedConsentUrl();\n+            DateTime expiresOn = getDownloadExpiration();\n+            s3Helper.writeBytesToS3(USERSIGNED_CONSENTS_BUCKET, fileName, consentPdf.getBytes());\n+            URL url = s3Helper.generatePresignedUrl(USERSIGNED_CONSENTS_BUCKET, fileName, expiresOn, HttpMethod.GET);\n+            shortUrl = urlShortenerService.shortenUrl(url.toString(), SIGNED_CONSENT_DOWNLOAD_EXPIRE_IN_SECONDS);\n+        } catch(IOException e) {\n+            throw new BridgeServiceException(e);\n         }\n+        SmsMessageProvider provider = new SmsMessageProvider.Builder()\n+                .withStudy(study)\n+                .withPhone(participant.getPhone())\n+                .withExpirationPeriod(EXPIRATION_PERIOD_KEY, SIGNED_CONSENT_DOWNLOAD_EXPIRE_IN_SECONDS)\n+                .withPromotionType()","path":"app/org/sagebionetworks/bridge/services/ConsentService.java","position":240,"original_position":240,"commit_id":"c62cc3356e96fc81c5f5c82c10c5a16d8ebf9d77","original_commit_id":"c62cc3356e96fc81c5f5c82c10c5a16d8ebf9d77","user":{"login":"alxdarksage","id":5589085,"avatar_url":"https://avatars3.githubusercontent.com/u/5589085?v=4","gravatar_id":"","url":"https://api.github.com/users/alxdarksage","html_url":"https://github.com/alxdarksage","followers_url":"https://api.github.com/users/alxdarksage/followers","following_url":"https://api.github.com/users/alxdarksage/following{/other_user}","gists_url":"https://api.github.com/users/alxdarksage/gists{/gist_id}","starred_url":"https://api.github.com/users/alxdarksage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alxdarksage/subscriptions","organizations_url":"https://api.github.com/users/alxdarksage/orgs","repos_url":"https://api.github.com/users/alxdarksage/repos","events_url":"https://api.github.com/users/alxdarksage/events{/privacy}","received_events_url":"https://api.github.com/users/alxdarksage/received_events","type":"User","site_admin":false},"body":"Changed to transaction","created_at":"2018-05-08T23:55:35Z","updated_at":"2018-05-08T23:55:36Z","html_url":"https://github.com/Sage-Bionetworks/BridgePF/pull/1701#discussion_r186900047","pull_request_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/pulls/1701","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/pulls/comments/186900047"},"html":{"href":"https://github.com/Sage-Bionetworks/BridgePF/pull/1701#discussion_r186900047"},"pull_request":{"href":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/pulls/1701"}},"in_reply_to_id":186603327},"pull_request":{"url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/pulls/1701","id":185870301,"html_url":"https://github.com/Sage-Bionetworks/BridgePF/pull/1701","diff_url":"https://github.com/Sage-Bionetworks/BridgePF/pull/1701.diff","patch_url":"https://github.com/Sage-Bionetworks/BridgePF/pull/1701.patch","issue_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/issues/1701","number":1701,"state":"open","locked":false,"title":"Send signed consent agreements via SMS","user":{"login":"alxdarksage","id":5589085,"avatar_url":"https://avatars3.githubusercontent.com/u/5589085?v=4","gravatar_id":"","url":"https://api.github.com/users/alxdarksage","html_url":"https://github.com/alxdarksage","followers_url":"https://api.github.com/users/alxdarksage/followers","following_url":"https://api.github.com/users/alxdarksage/following{/other_user}","gists_url":"https://api.github.com/users/alxdarksage/gists{/gist_id}","starred_url":"https://api.github.com/users/alxdarksage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alxdarksage/subscriptions","organizations_url":"https://api.github.com/users/alxdarksage/orgs","repos_url":"https://api.github.com/users/alxdarksage/repos","events_url":"https://api.github.com/users/alxdarksage/events{/privacy}","received_events_url":"https://api.github.com/users/alxdarksage/received_events","type":"User","site_admin":false},"body":"I substantially cleaned up the ConsentServiceMockTest class. I would kind of like to combine it with ConsentServiceTest and get rid of that class, while I'm in there. So maybe don't review yet.","created_at":"2018-05-04T00:26:21Z","updated_at":"2018-05-08T23:55:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"22cde93b2340f459b416758a2890221ccad72589","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/pulls/1701/commits","review_comments_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/pulls/1701/comments","review_comment_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/issues/1701/comments","statuses_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/statuses/c62cc3356e96fc81c5f5c82c10c5a16d8ebf9d77","head":{"label":"alxdarksage:sms-consents","ref":"sms-consents","sha":"c62cc3356e96fc81c5f5c82c10c5a16d8ebf9d77","user":{"login":"alxdarksage","id":5589085,"avatar_url":"https://avatars3.githubusercontent.com/u/5589085?v=4","gravatar_id":"","url":"https://api.github.com/users/alxdarksage","html_url":"https://github.com/alxdarksage","followers_url":"https://api.github.com/users/alxdarksage/followers","following_url":"https://api.github.com/users/alxdarksage/following{/other_user}","gists_url":"https://api.github.com/users/alxdarksage/gists{/gist_id}","starred_url":"https://api.github.com/users/alxdarksage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alxdarksage/subscriptions","organizations_url":"https://api.github.com/users/alxdarksage/orgs","repos_url":"https://api.github.com/users/alxdarksage/repos","events_url":"https://api.github.com/users/alxdarksage/events{/privacy}","received_events_url":"https://api.github.com/users/alxdarksage/received_events","type":"User","site_admin":false},"repo":{"id":45479946,"name":"BridgePF","full_name":"alxdarksage/BridgePF","owner":{"login":"alxdarksage","id":5589085,"avatar_url":"https://avatars3.githubusercontent.com/u/5589085?v=4","gravatar_id":"","url":"https://api.github.com/users/alxdarksage","html_url":"https://github.com/alxdarksage","followers_url":"https://api.github.com/users/alxdarksage/followers","following_url":"https://api.github.com/users/alxdarksage/following{/other_user}","gists_url":"https://api.github.com/users/alxdarksage/gists{/gist_id}","starred_url":"https://api.github.com/users/alxdarksage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alxdarksage/subscriptions","organizations_url":"https://api.github.com/users/alxdarksage/orgs","repos_url":"https://api.github.com/users/alxdarksage/repos","events_url":"https://api.github.com/users/alxdarksage/events{/privacy}","received_events_url":"https://api.github.com/users/alxdarksage/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/alxdarksage/BridgePF","description":"Server software for Bridge-based mobile applications","fork":true,"url":"https://api.github.com/repos/alxdarksage/BridgePF","forks_url":"https://api.github.com/repos/alxdarksage/BridgePF/forks","keys_url":"https://api.github.com/repos/alxdarksage/BridgePF/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alxdarksage/BridgePF/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alxdarksage/BridgePF/teams","hooks_url":"https://api.github.com/repos/alxdarksage/BridgePF/hooks","issue_events_url":"https://api.github.com/repos/alxdarksage/BridgePF/issues/events{/number}","events_url":"https://api.github.com/repos/alxdarksage/BridgePF/events","assignees_url":"https://api.github.com/repos/alxdarksage/BridgePF/assignees{/user}","branches_url":"https://api.github.com/repos/alxdarksage/BridgePF/branches{/branch}","tags_url":"https://api.github.com/repos/alxdarksage/BridgePF/tags","blobs_url":"https://api.github.com/repos/alxdarksage/BridgePF/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alxdarksage/BridgePF/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alxdarksage/BridgePF/git/refs{/sha}","trees_url":"https://api.github.com/repos/alxdarksage/BridgePF/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alxdarksage/BridgePF/statuses/{sha}","languages_url":"https://api.github.com/repos/alxdarksage/BridgePF/languages","stargazers_url":"https://api.github.com/repos/alxdarksage/BridgePF/stargazers","contributors_url":"https://api.github.com/repos/alxdarksage/BridgePF/contributors","subscribers_url":"https://api.github.com/repos/alxdarksage/BridgePF/subscribers","subscription_url":"https://api.github.com/repos/alxdarksage/BridgePF/subscription","commits_url":"https://api.github.com/repos/alxdarksage/BridgePF/commits{/sha}","git_commits_url":"https://api.github.com/repos/alxdarksage/BridgePF/git/commits{/sha}","comments_url":"https://api.github.com/repos/alxdarksage/BridgePF/comments{/number}","issue_comment_url":"https://api.github.com/repos/alxdarksage/BridgePF/issues/comments{/number}","contents_url":"https://api.github.com/repos/alxdarksage/BridgePF/contents/{+path}","compare_url":"https://api.github.com/repos/alxdarksage/BridgePF/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alxdarksage/BridgePF/merges","archive_url":"https://api.github.com/repos/alxdarksage/BridgePF/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alxdarksage/BridgePF/downloads","issues_url":"https://api.github.com/repos/alxdarksage/BridgePF/issues{/number}","pulls_url":"https://api.github.com/repos/alxdarksage/BridgePF/pulls{/number}","milestones_url":"https://api.github.com/repos/alxdarksage/BridgePF/milestones{/number}","notifications_url":"https://api.github.com/repos/alxdarksage/BridgePF/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alxdarksage/BridgePF/labels{/name}","releases_url":"https://api.github.com/repos/alxdarksage/BridgePF/releases{/id}","deployments_url":"https://api.github.com/repos/alxdarksage/BridgePF/deployments","created_at":"2015-11-03T16:35:11Z","updated_at":"2018-05-07T17:11:20Z","pushed_at":"2018-05-08T23:23:41Z","git_url":"git://github.com/alxdarksage/BridgePF.git","ssh_url":"git@github.com:alxdarksage/BridgePF.git","clone_url":"https://github.com/alxdarksage/BridgePF.git","svn_url":"https://github.com/alxdarksage/BridgePF","homepage":"","size":80148,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"Sage-Bionetworks:develop","ref":"develop","sha":"84bbc11ee661e32e35e7be4b23085ba29c46d7ff","user":{"login":"Sage-Bionetworks","id":1250897,"avatar_url":"https://avatars2.githubusercontent.com/u/1250897?v=4","gravatar_id":"","url":"https://api.github.com/users/Sage-Bionetworks","html_url":"https://github.com/Sage-Bionetworks","followers_url":"https://api.github.com/users/Sage-Bionetworks/followers","following_url":"https://api.github.com/users/Sage-Bionetworks/following{/other_user}","gists_url":"https://api.github.com/users/Sage-Bionetworks/gists{/gist_id}","starred_url":"https://api.github.com/users/Sage-Bionetworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sage-Bionetworks/subscriptions","organizations_url":"https://api.github.com/users/Sage-Bionetworks/orgs","repos_url":"https://api.github.com/users/Sage-Bionetworks/repos","events_url":"https://api.github.com/users/Sage-Bionetworks/events{/privacy}","received_events_url":"https://api.github.com/users/Sage-Bionetworks/received_events","type":"Organization","site_admin":false},"repo":{"id":18604783,"name":"BridgePF","full_name":"Sage-Bionetworks/BridgePF","owner":{"login":"Sage-Bionetworks","id":1250897,"avatar_url":"https://avatars2.githubusercontent.com/u/1250897?v=4","gravatar_id":"","url":"https://api.github.com/users/Sage-Bionetworks","html_url":"https://github.com/Sage-Bionetworks","followers_url":"https://api.github.com/users/Sage-Bionetworks/followers","following_url":"https://api.github.com/users/Sage-Bionetworks/following{/other_user}","gists_url":"https://api.github.com/users/Sage-Bionetworks/gists{/gist_id}","starred_url":"https://api.github.com/users/Sage-Bionetworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sage-Bionetworks/subscriptions","organizations_url":"https://api.github.com/users/Sage-Bionetworks/orgs","repos_url":"https://api.github.com/users/Sage-Bionetworks/repos","events_url":"https://api.github.com/users/Sage-Bionetworks/events{/privacy}","received_events_url":"https://api.github.com/users/Sage-Bionetworks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Sage-Bionetworks/BridgePF","description":"Server software for Bridge-based mobile applications","fork":false,"url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF","forks_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/forks","keys_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/teams","hooks_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/hooks","issue_events_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/issues/events{/number}","events_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/events","assignees_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/assignees{/user}","branches_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/branches{/branch}","tags_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/tags","blobs_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/git/refs{/sha}","trees_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/statuses/{sha}","languages_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/languages","stargazers_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/stargazers","contributors_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/contributors","subscribers_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/subscribers","subscription_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/subscription","commits_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/commits{/sha}","git_commits_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/git/commits{/sha}","comments_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/comments{/number}","issue_comment_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/issues/comments{/number}","contents_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/contents/{+path}","compare_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/merges","archive_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/downloads","issues_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/issues{/number}","pulls_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/pulls{/number}","milestones_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/milestones{/number}","notifications_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/labels{/name}","releases_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/releases{/id}","deployments_url":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/deployments","created_at":"2014-04-09T16:38:46Z","updated_at":"2018-05-07T23:52:57Z","pushed_at":"2018-05-08T23:23:42Z","git_url":"git://github.com/Sage-Bionetworks/BridgePF.git","ssh_url":"git@github.com:Sage-Bionetworks/BridgePF.git","clone_url":"https://github.com/Sage-Bionetworks/BridgePF.git","svn_url":"https://github.com/Sage-Bionetworks/BridgePF","homepage":"","size":79781,"stargazers_count":11,"watchers_count":11,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":23,"mirror_url":null,"archived":false,"open_issues_count":4,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":23,"open_issues":4,"watchers":11,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/pulls/1701"},"html":{"href":"https://github.com/Sage-Bionetworks/BridgePF/pull/1701"},"issue":{"href":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/issues/1701"},"comments":{"href":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/issues/1701/comments"},"review_comments":{"href":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/pulls/1701/comments"},"review_comment":{"href":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/pulls/1701/commits"},"statuses":{"href":"https://api.github.com/repos/Sage-Bionetworks/BridgePF/statuses/c62cc3356e96fc81c5f5c82c10c5a16d8ebf9d77"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"alxdarksage"}}