Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/institutional access #10884

Merged
merged 41 commits into from
Jan 21, 2025
Merged
Changes from 2 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
edb3118
Add new UserMessage feature for Institutional Access
Dec 3, 2024
cbcd763
Respond to CR by changing permissions logic and removing vestigial `u…
Dec 6, 2024
ec0d147
expand tests fix typos, align email templates and improve help text
Dec 6, 2024
cd45df2
clean-up serializer/permission code to validate better, 409s instead …
Dec 6, 2024
25d7857
add code to allow cc-ing fellow institutional admins and put their o…
Dec 10, 2024
f3ab16b
add new user message oauth scope and throttling classes
Dec 10, 2024
6b8c81c
add user message read/write permissions to full
Dec 10, 2024
9831d86
Merge pull request #10824 from Johnetordoff/institutional-access-user…
Johnetordoff Dec 11, 2024
cb64b51
Merge branch 'feature/institutional_access' of https://github.com/Cen…
Dec 11, 2024
dc2331e
revert typo
Dec 11, 2024
8de394a
change to bcc the sender instead of CC-ing them
Dec 11, 2024
7068791
Merge pull request #10841 from Johnetordoff/institutional-access-user…
Johnetordoff Dec 12, 2024
b7405af
add NodeRequest improvements for Institutional Access
Johnetordoff Dec 12, 2024
b2b73c5
Merge branch 'feature/institutional_access' of https://github.com/Cen…
Dec 12, 2024
7359973
fix up tests
Dec 12, 2024
4d16ab5
clean-up docstrings and typos
Dec 13, 2024
a024264
re-introduce in email template
Dec 13, 2024
e34b928
tweak permissions for 400 error code and add test cases
Dec 13, 2024
8b5c183
fix typo
Dec 16, 2024
efc5dd2
split off node request file again, added descriptive message when nod…
Dec 16, 2024
66df96c
Merge pull request #10826 from Johnetordoff/institutional-access-node…
Johnetordoff Dec 16, 2024
8c65e13
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
Dec 16, 2024
be8f711
allow BCC and reply emails to work with sendgrid
Dec 17, 2024
c99d066
Merge pull request #10859 from Johnetordoff/fix-sendgrid-email
Johnetordoff Dec 17, 2024
79135e4
try fixing sendgrid agian to not send 400 and fix to make 202 not go …
Dec 17, 2024
4fef0d0
Merge pull request #10860 from Johnetordoff/fix-sendgrid-email
Johnetordoff Dec 17, 2024
60eb88f
add fix to email mocking, test for catagories
Jan 6, 2025
4611112
Merge pull request #10890 from Johnetordoff/fix-mail-mocks
Johnetordoff Jan 6, 2025
d34ceb8
Merge pull request #10897 from bodintsov/develop
brianjgeiger Jan 7, 2025
06e7198
Make the requested permissions show up as defaults
bodintsov Jan 6, 2025
d5138e0
Merge pull request #10891 from bodintsov/feature/changed_to_legacy_co…
brianjgeiger Jan 8, 2025
d9540f3
Changes for "can_request_access" feature (#10877)
bodintsov Jan 9, 2025
78597c8
[ENG-6668] Add Contributor Page Improvements for Institutional Access…
Johnetordoff Jan 13, 2025
83a6049
[IAC][Bugs] Fix migrations and serializer (#10915)
Johnetordoff Jan 13, 2025
8f79cfd
fixed double mail sending
bodintsov Jan 14, 2025
d007d63
reverted changes to test_node_request_list
bodintsov Jan 14, 2025
b268003
added testcases to check email send once
bodintsov Jan 15, 2025
bb243a1
removed useless code
bodintsov Jan 15, 2025
979b157
refactored test
bodintsov Jan 15, 2025
e5cc7fe
Merge pull request #10919 from bodintsov/feature/double_email_fix
Johnetordoff Jan 15, 2025
d75b026
[IAC][Group CR][ENG-6751] (#10923)
Johnetordoff Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 40 additions & 15 deletions framework/email/tasks.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,21 @@
from io import BytesIO

from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail, Bcc, ReplyTo, Category, Attachment, FileContent
from sendgrid.helpers.mail import (
Mail,
Bcc,
ReplyTo,
Category,
Attachment,
FileContent,
Email,
To,
Personalization,
Cc,
FileName,
Disposition,
)


from framework import sentry
from framework.celery_tasks import app
@@ -135,6 +149,7 @@ def _send_with_sendgrid(
categories=None,
attachment_name: str = None,
attachment_content=None,
cc_addr=None,
bcc_addr=None,
reply_to=None,
client=None,
@@ -148,36 +163,46 @@ def _send_with_sendgrid(

client = client or SendGridAPIClient(settings.SENDGRID_API_KEY)
mail = Mail(
from_email=from_addr,
from_email=Email(from_addr),
html_content=message,
to_emails=to_addr,
subject=subject
subject=subject,
)

if reply_to:
mail.reply_to = ReplyTo(reply_to)
# Personalization to handle To, CC, and BCC sendgrid client concept
personalization = Personalization()

personalization.add_to(To(to_addr))

if cc_addr:
if isinstance(cc_addr, str):
cc_addr = [cc_addr]
for email in cc_addr:
personalization.add_cc(Cc(email))

if bcc_addr:
if isinstance(bcc_addr, str):
bcc_addr = [bcc_addr]
mail.bcc = [Bcc(email) for email in bcc_addr]
for email in bcc_addr:
personalization.add_bcc(Bcc(email))

if reply_to:
mail.reply_to = ReplyTo(reply_to)

mail.add_personalization(personalization)

if categories:
mail.category = [Category(x) for x in categories]
mail.add_category([Category(x) for x in categories])

if attachment_name and attachment_content:
attachment = Attachment(
file_content=_content_to_bytes(
FileContent(
b64encode(attachment_content).decode()
)
),
file_name=attachment_name
file_content=FileContent(b64encode(attachment_content).decode()),
file_name=FileName(attachment_name),
disposition=Disposition('attachment')
)
mail.add_attachment(attachment)

response = client.send(mail)
if response.status_code not in (200, 201):
if response.status_code not in (200, 201, 202):
sentry.log_message(
f'{response.status_code} error response from sendgrid.'
f'from_addr: {from_addr}\n'