#254 Add privacy options for sender and recipient in web interface
Merged 5 years ago by jflory7. Opened 5 years ago by shraddhaag.
fedora-commops/ shraddhaag/fedora-happiness-packets add-permissions  into  master

@@ -149,3 +149,32 @@ 

                                                                "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("<br>"),

+             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'")

@@ -3,7 +3,7 @@ 

  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 @@ 

      re_path(r'^send/confirmation/(?P<identifier>[\w-]+)/(?P<token>[\w-]+)/$', MessageSenderConfirmationView.as_view(), name='sender_confirm'),

      re_path(r'^send/confirmed/$', MessageSenderConfirmedView.as_view(), name='sender_confirmed'),

      re_path(r'^recipient/(?P<identifier>[\w-]+)/(?P<token>[\w-]+)/$', MessageRecipientMessageUpdate.as_view(), name='recipient_message_update'),

+     re_path(r'^sender/(?P<identifier>[\w-]+)/(?P<token>[\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'),

  ]

@@ -19,7 +19,7 @@ 

  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 @@ 

          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

@@ -0,0 +1,18 @@ 

+ {% extends 'base.html' %}

+ {% load crispy_forms_tags %}

+ 

+ {% block content %}

+ 

+     <div class="page-header">

+         <h2>Change permission settings on the following Happiness Packet:</h2>

+     </div>

+     <h4>

+         Sent to {{ message.recipient_name }}

+     </h4>

+     <blockquote>

+         {{ message.message|safe }}

+     </blockquote>

+     

+     {% crispy form %}

+ 

+ {% endblock content %} 

\ No newline at end of file

@@ -22,6 +22,7 @@ 

      <blockquote>

        {{ message.message|safe }}

      </blockquote>

+     <p><a href="{% url 'messaging:recipient_message_update' identifier=message.identifier token=message.recipient_email_token %}">Update Permissions</a></p>

      {% endfor %}

  

      {% block pagination %}

@@ -19,6 +19,7 @@ 

      <blockquote>

        {{ message.message|safe }}

      </blockquote>

+     <p><a href="{% url 'messaging:sender_message_update' identifier=message.identifier token=message.sender_email_token %}">Update Permissions</a></p>

      {% endfor %}

  

      {% block pagination %}

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.

Metadata Update from @jflory7:
- Pull-request tagged with: PASSED, needs testing, new change, type - backend, type - frontend, type - summer coding

5 years ago

Metadata Update from @jflory7:
- Pull-request untagged with: needs testing
- Request assigned

5 years ago

Nice work @shraddhaag! This is awesome. :raised_hands: I like your idea for adding links to this in the Sent/Received Packets pages. I hadn't thought of that.

I tested this as a sender and I was able to change permissions on a packet and see it reflected in the Happiness Archive immediately. This is really cool!

Merging! :ocean: I also updated the requirements list and Taiga board.

Pull-Request has been merged by jflory7

5 years ago