Skip to content

Commit

Permalink
expand tests fix typos, align email templates and improve help text
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tordoff committed Dec 6, 2024
1 parent cbcd763 commit ec0d147
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion api/users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def create(self, validated_data: Dict[str, Any]) -> UserMessage:
)

if not sender.is_institutional_admin(institution):
raise exceptions.ValidationError({'sender': 'Only institutional adminstraters can create messages.'})
raise exceptions.ValidationError({'sender': 'Only institutional administrators can create messages.'})

if not recipient.is_affiliated_with_institution(institution):
raise exceptions.ValidationError(
Expand Down
20 changes: 19 additions & 1 deletion api_tests/users/views/test_user_message_institutional_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_non_institutional_admin_cannot_create_message(self, app, noncontrib, us
Ensure a non-institutional admin cannot create a `UserMessage`, even with valid data.
"""
res = app.post_json_api(url_with_affiliation, payload, auth=noncontrib.auth, expect_errors=True)
assert res.status_code == 401
assert res.status_code == 403

def test_request_without_institution(self, app, institutional_admin, user, url_with_affiliation, payload):
"""
Expand All @@ -110,6 +110,15 @@ def test_request_without_institution(self, app, institutional_admin, user, url_w

res = app.post_json_api(url_with_affiliation, payload, auth=institutional_admin.auth, expect_errors=True)
assert res.status_code == 400
error = res.json['errors']
assert error == [
{
'source': {
'pointer': '/data/relationships/institution'
},
'detail': 'Institution ID is required.'
}
]

def test_missing_message_fails(self, app, institutional_admin, user, url_with_affiliation, payload):
"""
Expand All @@ -119,6 +128,15 @@ def test_missing_message_fails(self, app, institutional_admin, user, url_with_af

res = app.post_json_api(url_with_affiliation, payload, auth=institutional_admin.auth, expect_errors=True)
assert res.status_code == 400
error = res.json['errors']
assert error == [
{
'source': {
'pointer': '/data/attributes/message_text'
},
'detail': 'This field is required.',
}
]

def test_admin_cannot_message_user_outside_institution(
self,
Expand Down
4 changes: 2 additions & 2 deletions osf/migrations/0025_usermessage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.13 on 2024-12-04 14:45
# Generated by Django 4.2.13 on 2024-12-06 21:31

from django.conf import settings
from django.db import migrations, models
Expand All @@ -24,7 +24,7 @@ class Migration(migrations.Migration):
('message_text', models.TextField(help_text='The content of the message. The custom text of a formatted email.')),
('message_type', models.CharField(choices=[('institutional_request', 'INSTITUTIONAL_REQUEST')], help_text='The type of message being sent, as defined in MessageTypes.', max_length=50)),
('institution', models.ForeignKey(help_text='The institution associated with this message.', on_delete=django.db.models.deletion.CASCADE, to='osf.institution')),
('recipient', models.ForeignKey(help_text='The user who received this message.', on_delete=django.db.models.deletion.CASCADE, related_name='received_user_messages', to=settings.AUTH_USER_MODEL)),
('recipient', models.ForeignKey(help_text='The recipient of this message.', on_delete=django.db.models.deletion.CASCADE, related_name='received_user_messages', to=settings.AUTH_USER_MODEL)),
('sender', models.ForeignKey(help_text='The user who sent this message.', on_delete=django.db.models.deletion.CASCADE, related_name='sent_user_messages', to=settings.AUTH_USER_MODEL)),
],
options={
Expand Down
2 changes: 1 addition & 1 deletion osf/models/user_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class UserMessage(BaseModel, ObjectIDMixin):
'OSFUser',
on_delete=models.CASCADE,
related_name='received_user_messages',
help_text='The user who received this message.'
help_text='The recipient of this message.'
)
message_text = models.TextField(
help_text='The content of the message. The custom text of a formatted email.'
Expand Down
2 changes: 1 addition & 1 deletion website/mails/mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,5 +598,5 @@ def get_english_article(word):

USER_MESSAGE_INSTITUTIONAL_ACCESS_REQUEST = Mail(
'user_message_institutional_access_request',
subject='Institutional Access Request'
subject='Message from Institutional Admin'
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,13 @@
<%!from website import settings%>
Hello ${recipient.fullname},
<p>
${sender.fullname} from your <b>${institution.name}</b>, has sent you a request regarding your project.
This message is coming from an Institutional administrator within your Institution.
</p>
% if message_text:
<p>
Message from ${sender.fullname}:<br>
${message_text}
</p>
% endif
<p>
To review this request, please visit your project dashboard or contact your institution administrator for further details.
</p>
<p>
Sincerely,<br>
The OSF Team
</p>
<p>
Want more information? Visit <a href="${settings.DOMAIN}">${settings.DOMAIN}</a> to learn about OSF, or
<a href="https://cos.io/">https://cos.io/</a> for information about its supporting organization, the Center
Expand Down

0 comments on commit ec0d147

Please sign in to comment.