From 732fd4f9c3afaf441e768ecde552395438c3ac23 Mon Sep 17 00:00:00 2001 From: Shraddha Agrawal Date: Jul 11 2019 08:24:19 +0000 Subject: Add privacy options for sender and recipient in web interface This commit adds the following: 1. A form, view, URL mapping and template for changing sender permissions on a sent packet. 2. Including link for changing recipient permission. --- diff --git a/happinesspackets/messaging/forms.py b/happinesspackets/messaging/forms.py index 0b632b5..799b891 100644 --- a/happinesspackets/messaging/forms.py +++ b/happinesspackets/messaging/forms.py @@ -149,3 +149,32 @@ class MessageRecipientForm(forms.ModelForm): "names, you must also check 'I agree to publish this " "message and display it publicly in the Happiness " "Archive.'") +class MessageSenderPermissionForm(forms.ModelForm): + class Meta: + model = Message + fields = ['sender_named', 'sender_approved_public', 'sender_approved_public_named'] + + def __init__(self, *args, **kwargs): + super(MessageSenderPermissionForm, self).__init__(*args, **kwargs) + self.helper = FormHelper() + self.helper.form_class = 'form-horizontal' + self.helper.label_class = 'col-md-3' + self.helper.field_class = 'col-md-8' + + self.fields['sender_named'].label = 'I agree to share my name and email address with the recipient.' + self.fields['sender_approved_public'].label = "I agree to publish this message and display it publicly in the Happiness Archive." + self.fields['sender_approved_public_named'].label = "... and I agree to display our names publicly too." + self.fields['sender_approved_public_named'].help_text = "Note: We only publish information if both the sender and the recipients agree." + + self.helper.layout = Layout( + Fieldset("Privacy and permissions", 'sender_named', 'sender_approved_public', 'sender_approved_public_named'), + HTML("
"), + Submit('submit', 'Send some happiness', css_class='btn-lg centered'), + ) + + def clean(self): + super(MessageSenderPermissionForm, self).clean() + if self.cleaned_data.get('sender_approved_public_named') and not self.cleaned_data.get('sender_approved_public'): + self.add_error('sender_approved_public_named', "If you want us to publish the message including your names, " + "you must also check 'I agree to publish this message and" + "display it publicly in the Happiness Archive'") diff --git a/happinesspackets/messaging/urls.py b/happinesspackets/messaging/urls.py index ec2a51a..1c63566 100644 --- a/happinesspackets/messaging/urls.py +++ b/happinesspackets/messaging/urls.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals from django.urls import re_path from .views import (StartView, MessageSearchView, MessageSendView, MessageSenderConfirmationSentView, MessageSenderConfirmationView, - MessageSenderConfirmedView, MessageRecipientMessageUpdate, FaqView, ArchiveView, InspirationView, + MessageSenderConfirmedView, MessageRecipientMessageUpdate, MessageSenderPermissionsUpdate,FaqView, ArchiveView, InspirationView, BlacklistEmailView, ReceivedMessagesView, SentMessagesView, FasidSearchView) app_name = 'messaging' @@ -21,6 +21,7 @@ urlpatterns = [ re_path(r'^send/confirmation/(?P[\w-]+)/(?P[\w-]+)/$', MessageSenderConfirmationView.as_view(), name='sender_confirm'), re_path(r'^send/confirmed/$', MessageSenderConfirmedView.as_view(), name='sender_confirmed'), re_path(r'^recipient/(?P[\w-]+)/(?P[\w-]+)/$', MessageRecipientMessageUpdate.as_view(), name='recipient_message_update'), + re_path(r'^sender/(?P[\w-]+)/(?P[\w-]+)/$', MessageSenderPermissionsUpdate.as_view(), name='sender_message_update'), re_path(r'^send/search/$', FasidSearchView.fasidCheck, name='fasid_check'), re_path(r'^search/?$', MessageSearchView.as_view(), name='search'), ] diff --git a/happinesspackets/messaging/views.py b/happinesspackets/messaging/views.py index 4cdd63f..75ecba1 100644 --- a/happinesspackets/messaging/views.py +++ b/happinesspackets/messaging/views.py @@ -19,7 +19,7 @@ from django.conf import settings from haystack.generic_views import SearchView from haystack.forms import SearchForm -from .forms import MessageSendForm, MessageRecipientForm +from .forms import MessageSendForm, MessageRecipientForm, MessageSenderPermissionForm from .models import Message, BLACKLIST_HMAC_SALT, BlacklistedEmail, strip_email from fedora_messaging.api import publish @@ -201,6 +201,24 @@ class MessageRecipientMessageUpdate(UpdateView): return HttpResponseRedirect(self.request.path) +class MessageSenderPermissionsUpdate(UpdateView): + model = Message + form_class = MessageSenderPermissionForm + template_name = 'messaging/message_sender_permissions_form.html' + slug_field = 'identifier' + slug_url_kwarg = 'identifier' + + def get_queryset(self): + message = super(MessageSenderPermissionsUpdate, self).get_queryset() + valid_status = [Message.STATUS.sent, Message.STATUS.read] + return message.filter(sender_email_token=self.kwargs['token'], status__in=valid_status) + + def form_valid(self, form): + form.save() + messages.success(self.request, "Your choices have been saved.") + return HttpResponseRedirect(self.request.path) + + class UserMessageView(LoginRequiredMixin, ListView): model = Message paginate_by = 5 diff --git a/templates/messaging/message_sender_permissions_form.html b/templates/messaging/message_sender_permissions_form.html new file mode 100644 index 0000000..87577cc --- /dev/null +++ b/templates/messaging/message_sender_permissions_form.html @@ -0,0 +1,18 @@ +{% extends 'base.html' %} +{% load crispy_forms_tags %} + +{% block content %} + + +

+ Sent to {{ message.recipient_name }} +

+
+ {{ message.message|safe }} +
+ + {% crispy form %} + +{% endblock content %} \ No newline at end of file diff --git a/templates/messaging/received_messages.html b/templates/messaging/received_messages.html index 0b5726b..fdb3014 100644 --- a/templates/messaging/received_messages.html +++ b/templates/messaging/received_messages.html @@ -22,6 +22,7 @@
{{ message.message|safe }}
+

Update Permissions

{% endfor %} {% block pagination %} diff --git a/templates/messaging/sent_messages.html b/templates/messaging/sent_messages.html index 153f35d..64c587e 100644 --- a/templates/messaging/sent_messages.html +++ b/templates/messaging/sent_messages.html @@ -19,6 +19,7 @@
{{ message.message|safe }}
+

Update Permissions

{% endfor %} {% block pagination %}