-
Notifications
You must be signed in to change notification settings - Fork 348
[ENG-8064] Add New Notifications Data Model (Refactor Notifications Phase 2) #11151
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
base: develop
Are you sure you want to change the base?
Changes from all commits
8e9126a
61a072f
5a8f453
df19159
ddd1cbb
c1c12bd
7c79222
e04d901
b0d0521
d77eed2
74f42bf
6eacd4d
59c5c2f
3c6dfa8
24c503b
94734fd
51df115
5ec04a0
f281e99
dbf4815
ebffbe4
795a7e6
a90a234
8421403
f9d4249
4c2d145
8d9a26f
7ccc8fb
c418021
57ba198
8745da4
c635beb
681a960
9aed0ad
bb1d1f5
519b710
4c50c6c
e228bd4
8bbe32f
40db424
496fc23
a73fb3a
466685a
a4e1fab
96db17a
5993dad
e7319cd
e2d70b1
5c6c61e
5ef1089
a6cc270
9686ae4
7fef010
21a54f4
f624258
263b952
93f9544
725d79d
fd85623
0f793a9
e7a8e3c
eae2207
fcce6d4
d2dd171
c92ca40
04a91be
6fc1923
229e08b
839af9a
efee288
bcb085d
7c8c7dd
c8c73f0
a1fb86d
5e817c8
51c416b
d2e4925
68b68ac
9658544
f9043b6
a2dd86a
46e8726
18e6e89
5a0d535
944692a
13d22f7
d9d0d0b
95bea2d
b87fa3f
aecc2ed
0776c2a
2939b71
1901d84
baea6eb
208d0ba
8bb9287
873f28d
9cac232
3fed9a4
dbe1f2f
980a986
0f43255
57d7a1a
7c41d2b
877cccb
9ffac6f
95e749d
f512919
cc0689e
679ee8d
f1d560d
de372a2
6dda64c
0e5d22a
0304ab5
05e692c
6178df1
c4c2649
07af650
ce48563
f8245d3
547aaad
a0f238b
6038ce2
eb4452b
72b7280
7f2066f
bc54d93
1f237f5
6fb6e7f
aeba2aa
14e26f3
c836a71
62918d2
0e73a2a
5591ea2
ea2503a
64ff3b0
a243f12
244b54f
abf316d
04268ba
c977eaa
b9caab4
a0f1aa5
0cd2fab
872bafe
1983847
5089376
01690b1
54f0999
b981312
1d55350
7a8e401
1c43a13
b643b79
30351cd
6b90076
e460497
7ba77c1
7ff55b2
cceab95
36db21e
68cf978
6799824
c0aa54d
dc24645
a98d958
b241b26
05aad5e
282defc
499d823
c646a43
d3c238c
8937680
5109912
de56134
7981aaf
bf9a444
f985d70
0a46af1
698ce5d
6816040
6733701
b8fdc80
89dc4ed
1f5adb4
c88a2da
80ab307
b7102b0
ab02fa7
114c130
6244b56
9124543
860430b
02d0b13
335eafd
da3d15a
9b9a9de
f9bd245
eb33db2
7d082a4
c274041
c0b1314
ff7010d
b24de31
1ae1a92
9e898a0
bd15318
f46eb8a
d03d5fa
02b7adf
200fcf8
e8f7e1f
efc3a81
bc0ec38
287ae30
f9003e8
566ca6a
a28feef
33d6fda
e2dcfe5
ee98f7f
4f988c9
27d4ec4
76ae430
ea5839c
9e638ef
13fc874
2f2d281
26a8c28
d9ca75f
aad4585
bb98fe1
1d40702
d682552
baba239
026ddc1
f43d401
25e5b18
afa4c5b
26594e8
c7b6cf3
32a14dd
4b81676
59c4051
76bbfe7
054fe23
9fa5e5a
4e12ff3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,6 @@ | |
from framework.flask import redirect | ||
from framework.sentry import log_exception | ||
from framework.transactions.handlers import no_auto_transaction | ||
from website import mails | ||
from website import settings | ||
from addons.base import signals as file_signals | ||
from addons.base.utils import format_last_known_metadata, get_mfr_url | ||
|
@@ -52,7 +51,7 @@ | |
DraftRegistration, | ||
Guid, | ||
FileVersionUserMetadata, | ||
FileVersion | ||
FileVersion, NotificationType | ||
) | ||
from osf.metrics import PreprintView, PreprintDownload | ||
from osf.utils import permissions | ||
|
@@ -64,7 +63,7 @@ | |
from website.util import rubeus | ||
|
||
# import so that associated listener is instantiated and gets emails | ||
from website.notifications.events.files import FileEvent # noqa | ||
from notifications.file_event_notifications import FileEvent # noqa | ||
|
||
ERROR_MESSAGES = {'FILE_GONE': """ | ||
<style> | ||
|
@@ -226,8 +225,6 @@ def get_auth(auth, **kwargs): | |
_check_resource_permissions(resource, auth, action) | ||
|
||
provider_name = waterbutler_data['provider'] | ||
waterbutler_settings = None | ||
waterbutler_credentials = None | ||
file_version = file_node = None | ||
if provider_name == 'osfstorage' or (not flag_is_active(request, features.ENABLE_GV)): | ||
file_version, file_node = _get_osfstorage_file_version_and_node( | ||
|
@@ -576,20 +573,25 @@ def create_waterbutler_log(payload, **kwargs): | |
params=payload | ||
) | ||
|
||
if payload.get('email') is True or payload.get('errors'): | ||
mails.send_mail( | ||
user.username, | ||
mails.FILE_OPERATION_FAILED if payload.get('errors') | ||
else mails.FILE_OPERATION_SUCCESS, | ||
action=payload['action'], | ||
source_node=source_node, | ||
destination_node=destination_node, | ||
source_path=payload['source']['materialized'], | ||
source_addon=payload['source']['addon'], | ||
destination_addon=payload['destination']['addon'], | ||
osf_support_email=settings.OSF_SUPPORT_EMAIL | ||
if payload.get('email') or payload.get('errors'): | ||
if payload.get('email'): | ||
notification_type = NotificationType.Type.USER_FILE_OPERATION_SUCCESS.instance | ||
if payload.get('errors'): | ||
notification_type = NotificationType.Type.USER_FILE_OPERATION_FAILED.instance | ||
notification_type.emit( | ||
user=user, | ||
subscribed_object=node, | ||
event_context={ | ||
'user_fullname': user.fullname, | ||
'action': payload['action'], | ||
'source_node': source_node, | ||
'destination_node': destination_node, | ||
'source_path': payload['source']['materialized'], | ||
'source_addon': payload['source']['addon'], | ||
'destination_addon': payload['destination']['addon'], | ||
'osf_support_email': settings.OSF_SUPPORT_EMAIL | ||
} | ||
) | ||
|
||
if payload.get('errors'): | ||
# Action failed but our function succeeded | ||
# Bail out to avoid file_signals | ||
|
@@ -605,18 +607,46 @@ def create_waterbutler_log(payload, **kwargs): | |
update_storage_usage_with_size(payload) | ||
|
||
with transaction.atomic(): | ||
file_signals.file_updated.send(target=node, user=user, event_type=action, payload=payload) | ||
|
||
file_signals.file_updated.send(target=node, user=user, payload=payload) | ||
return {'status': 'success'} | ||
|
||
|
||
@file_signals.file_updated.connect | ||
def addon_delete_file_node(self, target, user, event_type, payload): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notice |
||
def emit_notification(self, target, user, payload, *args, **kwargs): | ||
notification_types = { | ||
'rename': NotificationType.Type.ADDON_FILE_RENAMED.instance, | ||
'copy': NotificationType.Type.ADDON_FILE_COPIED.instance, | ||
'create': NotificationType.Type.FILE_UPDATED.instance, | ||
'move': NotificationType.Type.ADDON_FILE_MOVED.instance, | ||
'delete': NotificationType.Type.FILE_REMOVED.instance, | ||
'update': NotificationType.Type.FILE_UPDATED.instance, | ||
'create_folder': NotificationType.Type.FOLDER_CREATED.instance, | ||
} | ||
notification_type = notification_types[payload.get('action')] | ||
if notification_type not in notification_types.values(): | ||
raise NotImplementedError(f'Notification type {notification_type} is not supported') | ||
notification_type.emit( | ||
user=user, | ||
subscribed_object=target, | ||
event_context={ | ||
'profile_image_url': user.profile_image_url(), | ||
'localized_timestamp': str(timezone.now()), | ||
'message': payload.get('message'), | ||
'user_fullname': user.fullname, | ||
'osf_logo': settings.OSF_LOGO, | ||
'url': target.absolute_url, | ||
}, | ||
is_digest=True | ||
) | ||
|
||
@file_signals.file_updated.connect | ||
def addon_delete_file_node(self, target, user, payload): | ||
""" Get addon BaseFileNode(s), move it into the TrashedFileNode collection | ||
and remove it from StoredFileNode. | ||
Required so that the guids of deleted addon files are not re-pointed when an | ||
addon file or folder is moved or renamed. | ||
""" | ||
event_type = payload['action'] | ||
if event_type == 'file_removed' and payload.get('provider', None) != 'osfstorage': | ||
provider = payload['provider'] | ||
path = payload['metadata']['path'] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,9 @@ | |
from addons.boa.boa_error_code import BoaErrorCode | ||
from framework import sentry | ||
from framework.celery_tasks import app as celery_app | ||
from osf.models import OSFUser | ||
from osf.models import OSFUser, NotificationType | ||
from osf.utils.fields import ensure_str, ensure_bytes | ||
from website import settings as osf_settings | ||
from website.mails import send_mail, ADDONS_BOA_JOB_COMPLETE, ADDONS_BOA_JOB_FAILURE | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -184,18 +183,19 @@ async def submit_to_boa_async(host, username, password, user_guid, project_guid, | |
|
||
logger.info('Successfully uploaded query output to OSF.') | ||
logger.debug('Task ends <<<<<<<<') | ||
await sync_to_async(send_mail)( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it was necessary for this to be async, there's nothing being it's already being processed that way. |
||
to_addr=user.username, | ||
mail=ADDONS_BOA_JOB_COMPLETE, | ||
fullname=user.fullname, | ||
query_file_name=query_file_name, | ||
query_file_full_path=file_full_path, | ||
output_file_name=output_file_name, | ||
job_id=boa_job.id, | ||
project_url=project_url, | ||
boa_job_list_url=boa_settings.BOA_JOB_LIST_URL, | ||
boa_support_email=boa_settings.BOA_SUPPORT_EMAIL, | ||
osf_support_email=osf_settings.OSF_SUPPORT_EMAIL, | ||
NotificationType.Type.ADDONS_BOA_JOB_COMPLETE.instance.emit( | ||
user=user, | ||
event_context={ | ||
'fullname': user.fullname, | ||
'query_file_name': query_file_name, | ||
'query_file_full_path': file_full_path, | ||
'output_file_name': output_file_name, | ||
'job_id': boa_job.id, | ||
'project_url': project_url, | ||
'boa_job_list_url': boa_settings.BOA_JOB_LIST_URL, | ||
'boa_support_email': boa_settings.BOA_SUPPORT_EMAIL, | ||
'osf_support_email': osf_settings.OSF_SUPPORT_EMAIL, | ||
} | ||
) | ||
return BoaErrorCode.NO_ERROR | ||
|
||
|
@@ -209,22 +209,24 @@ def handle_boa_error(message, code, username, fullname, project_url, query_file_ | |
sentry.log_message(message, skip_session=True) | ||
except Exception: | ||
pass | ||
send_mail( | ||
to_addr=username, | ||
mail=ADDONS_BOA_JOB_FAILURE, | ||
fullname=fullname, | ||
code=code, | ||
message=message, | ||
query_file_name=query_file_name, | ||
file_size=file_size, | ||
max_file_size=boa_settings.MAX_SUBMISSION_SIZE, | ||
query_file_full_path=query_file_full_path, | ||
output_file_name=output_file_name, | ||
job_id=job_id, | ||
max_job_wait_hours=boa_settings.MAX_JOB_WAITING_TIME / 3600, | ||
project_url=project_url, | ||
boa_job_list_url=boa_settings.BOA_JOB_LIST_URL, | ||
boa_support_email=boa_settings.BOA_SUPPORT_EMAIL, | ||
osf_support_email=osf_settings.OSF_SUPPORT_EMAIL, | ||
NotificationType.Type.ADDONS_BOA_JOB_FAILURE.instance.emit( | ||
destination_address=username, | ||
event_context={ | ||
'user_fullname': fullname, | ||
'code': code, | ||
'query_file_name': query_file_name, | ||
'file_size': file_size, | ||
'message': message, | ||
'max_file_size': boa_settings.MAX_SUBMISSION_SIZE, | ||
'query_file_full_path': query_file_full_path, | ||
'output_file_name': output_file_name, | ||
'job_id': job_id, | ||
'max_job_wait_hours': boa_settings.MAX_JOB_WAITING_TIME / 3600, | ||
'project_url': project_url, | ||
'boa_job_list_url': boa_settings.BOA_JOB_LIST_URL, | ||
'boa_support_email': boa_settings.BOA_SUPPORT_EMAIL, | ||
'osf_support_email': osf_settings.OSF_SUPPORT_EMAIL, | ||
|
||
} | ||
) | ||
return code |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
from django.contrib.auth import login, REDIRECT_FIELD_NAME, authenticate, logout | ||
|
||
from osf.models.user import OSFUser | ||
from osf.models import AdminProfile, AbstractProvider | ||
from osf.models import AdminProfile | ||
from admin.common_auth.forms import LoginForm, UserRegistrationForm, DeskUserForm | ||
|
||
|
||
|
@@ -69,16 +69,6 @@ def form_valid(self, form): | |
|
||
# create AdminProfile for this new user | ||
profile, created = AdminProfile.objects.get_or_create(user=osf_user) | ||
|
||
for group in form.cleaned_data.get('group_perms'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Johnetordoff Should get done on demand now |
||
osf_user.groups.add(group) | ||
split = group.name.split('_') | ||
group_type = split[0] | ||
if group_type == 'reviews': | ||
provider_id = split[2] | ||
provider = AbstractProvider.objects.get(id=provider_id) | ||
provider.notification_subscriptions.get(event_name='new_pending_submissions').add_user_to_subscription(osf_user, 'email_transactional') | ||
|
||
osf_user.save() | ||
|
||
if created: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not used