Skip to content

Commit 229e08b

Browse files
committed
fix legacy subscriptions
1 parent 6fc1923 commit 229e08b

32 files changed

Lines changed: 77 additions & 61 deletions

api/institutions/authentication.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ def authenticate(self, request):
341341
event_context={
342342
'domain': DOMAIN,
343343
'osf_support_email': OSF_SUPPORT_EMAIL,
344+
'user_fullname': user.fullname,
344345
'storage_flag_is_active': flag_is_active(request, features.STORAGE_I18N),
345346
},
346347
)

api_tests/identifiers/views/test_identifier_detail.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def test_identifier_preprint_detail_unpublished(
155155

156156
# test_unpublished_preprint_identifier_readcontrib_authenticated
157157
read_user = AuthUserFactory()
158-
preprint.add_contributor(read_user, READ, save=True)
158+
preprint.add_contributor(read_user, READ, save=True, notification_type=False)
159159
res = app.get(url, auth=read_user.auth, expect_errors=True)
160160
assert res.status_code == 200
161161

@@ -181,7 +181,7 @@ def test_identifier_preprint_detail_deleted(
181181

182182
# test_deleted_preprint_identifier_readcontrib_authenticated
183183
read_user = AuthUserFactory()
184-
preprint.add_contributor(read_user, READ, save=True)
184+
preprint.add_contributor(read_user, READ, save=True, notification_type=False)
185185
res = app.get(url, auth=read_user.auth, expect_errors=True)
186186
assert res.status_code == 404
187187

@@ -207,7 +207,7 @@ def test_identifier_preprint_detail_private(
207207

208208
# test_private_preprint_identifier_readcontrib_authenticated
209209
read_user = AuthUserFactory()
210-
preprint.add_contributor(read_user, READ, save=True)
210+
preprint.add_contributor(read_user, READ, save=True, notification_type=False)
211211
res = app.get(url, auth=read_user.auth, expect_errors=True)
212212
assert res.status_code == 200
213213

@@ -233,7 +233,7 @@ def test_identifier_preprint_detail_abandoned(
233233

234234
# test_abandoned_preprint_identifier_readcontrib_authenticated
235235
read_user = AuthUserFactory()
236-
preprint.add_contributor(read_user, READ, save=True)
236+
preprint.add_contributor(read_user, READ, save=True, notification_type=False)
237237
res = app.get(url, auth=read_user.auth, expect_errors=True)
238238
assert res.status_code == 403
239239

notifications/listeners.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ def queue_first_public_project_email(user, node):
7070
subscribed_object=user,
7171
user=user,
7272
event_context={
73+
'user_fullname': user.fullname,
7374
'domain': settings.DOMAIN,
7475
'nid': node._id,
75-
'fullname': user.fullname,
7676
'project_title': node.title,
7777
'osf_url': settings.DOMAIN,
7878
}

osf/models/collection_submission.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22

33
from django.db import models
4+
from django.utils import timezone
45
from django.utils.functional import cached_property
56
from framework import sentry
67
from framework.exceptions import PermissionsError
@@ -104,17 +105,26 @@ def _notify_contributors_pending(self, event_data):
104105
NotificationType.objects.get(
105106
name=NotificationType.Type.COLLECTION_SUBMISSION_SUBMITTED,
106107
).emit(
108+
is_digest=True,
107109
user=contributor,
108110
subscribed_object=self,
109111
event_context={
110-
'user': contributor.id,
111-
'submitter': user.id,
112+
'requester_contributor_names': ''.join(
113+
self.guid.referent.contributors.values_list('fullname', flat=True)),
114+
'localized_timestamp': str(timezone.now()),
115+
'user_fullname': contributor.fullname,
116+
'submitter_fullname': user.fullname,
117+
'requester_fullname': self.creator.fullname,
118+
'profile_image_url': user.profile_image_url(),
119+
'submitter_absolute_url': user.get_absolute_url(),
120+
'collections_link': settings.DOMAIN + 'collections/' + self.collection.provider._id,
121+
'collection_provider_name': self.collection.provider.name,
112122
'is_initiator': self.creator == contributor,
113123
'is_admin': self.guid.referent.has_permission(contributor, ADMIN),
114124
'is_registered_contrib': contributor.is_registered,
115-
'collection': self.collection.id,
116125
'claim_url': claim_url,
117-
'node': self.guid.referent.id,
126+
'node_title': self.guid.referent.title,
127+
'node_absolute_url': self.guid.referent.get_absolute_url(),
118128
'domain': settings.DOMAIN,
119129
'osf_contact_email': settings.OSF_CONTACT_EMAIL,
120130
},
@@ -128,7 +138,7 @@ def _notify_moderators_pending(self, event_data):
128138
user=user,
129139
subscribed_object=self.guid.referent,
130140
event_context={
131-
'submitter': self.creator.id,
141+
'submitter_fullname': self.creator.fullname,
132142
'requester_contributor_names': ''.join(self.guid.referent.contributors.values_list('fullname', flat=True))
133143
},
134144
is_digest=True,

osf/models/mixins.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ def add_affiliated_institution(self, inst, user, log=True, ignore_user_affiliati
321321
event_context={
322322
'user_fullname': user.fullname,
323323
'node_title': self.title,
324+
'node_id': self.machineable.target._id,
324325
'node_absolute_url': self.get_absolute_url(),
325326
}
326327
)
@@ -365,6 +366,7 @@ def remove_affiliated_institution(self, inst, user, save=False, log=True, notify
365366
event_context={
366367
'user_fullname': user.fullname,
367368
'node_title': self.title,
369+
'node_id': self.machineable.target._id,
368370
'node_absolute_url': self.get_absolute_url(),
369371
}
370372
)

osf/utils/machines.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def notify_edit_comment(self, ev):
304304
def get_context(self):
305305
return {
306306
'node_title': self.machineable.target.title,
307+
'node_id': self.machineable.target._id,
307308
'node_absolute_url': self.machineable.target.absolute_url,
308309
'requester_absolute_url': self.machineable.creator.absolute_url,
309310
}

website/notifications/views.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,13 @@ def get_configured_projects(user):
153153

154154

155155
def check_project_subscriptions_are_all_none(user, node):
156-
node_subscriptions = get_all_node_subscriptions(user, node)
156+
node_subscriptions = NotificationSubscription.objects.filter(
157+
user=user,
158+
object_id=node.id,
159+
content_type=ContentType.objects.get_for_model(node).id,
160+
)
157161
for s in node_subscriptions:
158-
if not s.none.filter(id=user.id).exists():
162+
if not s.message_frequecy == 'none':
159163
return False
160164
return True
161165

@@ -164,8 +168,8 @@ def get_all_user_subscriptions(user, extra=None):
164168
""" Get all Subscription objects that the user is subscribed to"""
165169
NotificationSubscription = apps.get_model('osf.NotificationSubscription')
166170
queryset = NotificationSubscription.objects.filter(
167-
Q(user=user)
168-
).distinct()
171+
user=user,
172+
)
169173
return queryset.filter(extra) if extra else queryset
170174

171175

website/project/views/contributor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ def notify_added_contributor(node, contributor, notification_type, auth=None, *a
639639
'is_initiator': getattr(getattr(auth, 'user', None), 'id', None) == contributor.id if auth else False,
640640
'branded_service': getattr(getattr(node, 'provider', None), 'id', None),
641641
'node_title': node.title,
642+
'node_id': node._id,
642643
'node_provider__id': getattr(node.provider, '_id', None),
643644
'node_absolute_url': node.absolute_url,
644645
'can_change_preferences': False,

website/search/elastic_search.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ def update_file(file_, index=None, delete=False):
715715
'category': 'file',
716716
'node_url': node_url,
717717
'node_title': getattr(target, 'title', None),
718+
'node__id': getattr(target, '_id', None),
718719
'parent_id': target.parent_node._id if getattr(target, 'parent_node', None) else None,
719720
'is_registration': getattr(target, 'is_registration', False),
720721
'is_retracted': getattr(target, 'is_retracted', False),

website/templates/emails/collection_submission_accepted.html.mako

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<p>
77
% if is_admin:
88
Your request to add <a href="${node.absolute_url}">${node.title}</a> to
9-
<a href="${domain + 'collections/' + collection.provider._id}">${collection.provider.name}</a> was approved.
9+
<a href="${domain + 'collections/' + collection.provider._id}">${collection_provider_name}</a> was approved.
1010
% else:
11-
<a href="${node.absolute_url}">${node.title}</a> was added to <a href="${domain + 'collections/' + collection.provider._id}">${collection.provider.name}</a>.
11+
<a href="${node.absolute_url}">${node.title}</a> was added to <a href="${domain + 'collections/' + collection.provider._id}">${collection_provider_name}</a>.
1212
% endif
1313
</p>
1414
<p>

0 commit comments

Comments
 (0)