diff options
-rw-r--r-- | app/models/incoming_message.rb | 2 | ||||
-rw-r--r-- | app/models/outgoing_message.rb | 3 | ||||
-rw-r--r-- | app/views/request/_incoming_correspondence.html.erb | 19 | ||||
-rw-r--r-- | app/views/request/_outgoing_correspondence.html.erb | 27 | ||||
-rw-r--r-- | app/views/request/_restricted_correspondence.html.erb | 18 | ||||
-rw-r--r-- | lib/message_prominence.rb | 4 | ||||
-rw-r--r-- | spec/integration/view_request_spec.rb | 38 |
7 files changed, 79 insertions, 32 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 96ecc7d53..85140398c 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -50,7 +50,7 @@ class IncomingMessage < ActiveRecord::Base belongs_to :raw_email - has_prominence(prominence_states = ['normal', 'hidden','requester_only']) + has_prominence # See binary_mask_stuff function below. It just test for inclusion # in this hash, not the value of the right hand side. diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb index 07bb2a8e4..e89c11141 100644 --- a/app/models/outgoing_message.rb +++ b/app/models/outgoing_message.rb @@ -22,6 +22,7 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class OutgoingMessage < ActiveRecord::Base + extend MessageProminence include Rails.application.routes.url_helpers include LinkToHelper self.default_url_options[:host] = AlaveteliConfiguration::domain @@ -32,6 +33,8 @@ class OutgoingMessage < ActiveRecord::Base strip_attributes! + has_prominence + belongs_to :info_request validates_presence_of :info_request diff --git a/app/views/request/_incoming_correspondence.html.erb b/app/views/request/_incoming_correspondence.html.erb index 1723f4d85..cd601a8ef 100644 --- a/app/views/request/_incoming_correspondence.html.erb +++ b/app/views/request/_incoming_correspondence.html.erb @@ -2,24 +2,7 @@ <%- if not incoming_message.user_can_view?(@user) %> <%= render :partial => 'request/hidden_correspondence', :locals => { :message => incoming_message }%> <%- else %> - <% if incoming_message.prominence == 'hidden' %> - <p id="hidden_message"> - <%- if !incoming_message.prominence_reason.blank? %> - <%= _('This message has prominence \'hidden\'. {{reason}} You can only see it because you are logged in as a super user.', :reason => incoming_message.prominence_reason) %> - <%- else %> - <%= _('This message has prominence \'hidden\'. You can only see it because you are logged in as a super user.') %> - <%- end %> - </p> - <% end %> - <% if incoming_message.prominence == 'requester_only' %> - <p id="hidden_message"> - <%- if !incoming_message.prominence_reason.blank? %> - <%= _('This message is hidden, so that only you, the requester, can see it. {{reason}}', :reason => incoming_message.prominence_reason) %> - <%- else %> - <%= _('This message is hidden, so that only you, the requester, can see it. Please <a href="{{url}}">contact us</a> if you are not sure why.', :url => help_requesting_path.html_safe) %> - <%- end %> - </p> - <% end %> + <%= render :partial => 'request/restricted_correspondence', :locals => {:message => incoming_message } %> <h2> <% if incoming_message.specific_from_name? %> <%= _("From:") %> <%= incoming_message.safe_mail_from %><br> diff --git a/app/views/request/_outgoing_correspondence.html.erb b/app/views/request/_outgoing_correspondence.html.erb index b43af0753..dced5c94c 100644 --- a/app/views/request/_outgoing_correspondence.html.erb +++ b/app/views/request/_outgoing_correspondence.html.erb @@ -1,13 +1,18 @@ <div class="outgoing correspondence" id="outgoing-<%=outgoing_message.id.to_s%>"> - <h2> - <%= _("From:") %> <%= @info_request.user_name %><br> - <br><%= simple_date(info_request_event.created_at) %> - </h2> - <%= render :partial => 'bubble', :locals => { :body => outgoing_message.get_body_for_html_display(), :attachments => nil } %> - <p class="event_actions"> - <% if outgoing_message.status == 'ready' && !@info_request.is_external? %> - <strong>Warning:</strong> This message has <strong>not yet been sent</strong> for an unknown reason. - <% end %> - <%= link_to _("Link to this"), outgoing_message_path(outgoing_message), :class => "link_to_this" %> - </p> + <%- if not outgoing_message.user_can_view?(@user) %> + <%= render :partial => 'request/hidden_correspondence', :locals => { :message => outgoing_message }%> + <%- else %> + <%= render :partial => 'request/restricted_correspondence', :locals => {:message => outgoing_message } %> + <h2> + <%= _("From:") %> <%= @info_request.user_name %><br> + <br><%= simple_date(info_request_event.created_at) %> + </h2> + <%= render :partial => 'bubble', :locals => { :body => outgoing_message.get_body_for_html_display(), :attachments => nil } %> + <p class="event_actions"> + <% if outgoing_message.status == 'ready' && !@info_request.is_external? %> + <strong>Warning:</strong> This message has <strong>not yet been sent</strong> for an unknown reason. + <% end %> + <%= link_to _("Link to this"), outgoing_message_path(outgoing_message), :class => "link_to_this" %> + </p> + <%- end %> </div> diff --git a/app/views/request/_restricted_correspondence.html.erb b/app/views/request/_restricted_correspondence.html.erb new file mode 100644 index 000000000..745c4ff0e --- /dev/null +++ b/app/views/request/_restricted_correspondence.html.erb @@ -0,0 +1,18 @@ +<% if message.prominence == 'hidden' %> + <p id="hidden_message"> + <%- if !message.prominence_reason.blank? %> + <%= _('This message has prominence \'hidden\'. {{reason}} You can only see it because you are logged in as a super user.', :reason => message.prominence_reason) %> + <%- else %> + <%= _('This message has prominence \'hidden\'. You can only see it because you are logged in as a super user.') %> + <%- end %> + </p> +<% end %> +<% if message.prominence == 'requester_only' %> + <p id="hidden_message"> + <%- if !message.prominence_reason.blank? %> + <%= _('This message is hidden, so that only you, the requester, can see it. {{reason}}', :reason => message.prominence_reason) %> + <%- else %> + <%= _('This message is hidden, so that only you, the requester, can see it. Please <a href="{{url}}">contact us</a> if you are not sure why.', :url => help_requesting_path.html_safe) %> + <%- end %> + </p> +<% end %> diff --git a/lib/message_prominence.rb b/lib/message_prominence.rb index 7bb8f3cf8..cc70be3b1 100644 --- a/lib/message_prominence.rb +++ b/lib/message_prominence.rb @@ -1,9 +1,9 @@ module MessageProminence - def has_prominence(prominence_states) + def has_prominence send :include, InstanceMethods cattr_accessor :prominence_states - self.prominence_states = prominence_states + self.prominence_states = ['normal', 'hidden','requester_only'] validates_inclusion_of :prominence, :in => self.prominence_states end diff --git a/spec/integration/view_request_spec.rb b/spec/integration/view_request_spec.rb index e79937bef..814e20fb3 100644 --- a/spec/integration/view_request_spec.rb +++ b/spec/integration/view_request_spec.rb @@ -128,5 +128,43 @@ describe "When viewing requests" do end + context 'when an outgoing message has prominence "requester_only"' do + + before do + @info_request = FactoryGirl.create(:info_request) + message = @info_request.outgoing_messages.first + message.prominence = 'requester_only' + message.prominence_reason = 'It is too irritating.' + message.save! + end + + it 'should show a hidden notice with login link to an unregistered user, and the message itself + with a hidden note to the requester or an admin' do + + # unregistered + unregistered = without_login + unregistered.browses_request(@info_request.url_title) + unregistered.response.body.should include("This message has been hidden.") + unregistered.response.body.should include("It is too irritating") + unregistered.response.body.should include("sign in</a> to view the message.") + unregistered.response.body.should_not include("Some information please") + + # requester + owner = login(@info_request.user) + owner.browses_request(@info_request.url_title) + owner.response.body.should include("Some information please") + owner.response.body.should include("This message is hidden, so that only you, the requester, can see it.") + owner.response.body.should include("It is too irritating.") + + # admin + admin_user = login(FactoryGirl.create(:admin_user)) + admin_user.browses_request(@info_request.url_title) + admin_user.response.body.should include('Some information please') + admin_user.response.body.should_not include("This message has been hidden.") + admin_user.response.body.should include("This message is hidden, so that only you, the requester, can see it.") + end + + end + end |