Skip to content

Commit

Permalink
Show tag-based notes on new request preview
Browse files Browse the repository at this point in the history
Use TaggableTerms to check OutgoingMessage#body for terms that we have a
tag-based Note for.

We can use this to warn users that they’re about to make a mistake.

For example, we could configure OutgoingMessage like so:

    OutgoingMessage.taggable_terms = {
      body: {
        /my 999 call/i => ‘preview_warning_sar’
      }
    }

Then, if a user includes “my 999 call” in their request content, we’d
detect this and render a Note applied via the ‘preview_warning_sar’ tag.
  • Loading branch information
garethrees committed Oct 18, 2023
1 parent ea144d4 commit e219f9e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/request_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ def new
return
end

@outgoing_message.update_taggable_terms

# Show preview page, if it is a preview
return render_new_preview if params[:preview].to_i == 1

Expand Down
2 changes: 2 additions & 0 deletions app/models/outgoing_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class OutgoingMessage < ApplicationRecord
include MessageProminence
include Rails.application.routes.url_helpers
include LinkToHelper
include Notable
include Taggable
include TaggableTerms

STATUS_TYPES = %w(ready sent failed).freeze
MESSAGE_TYPES = %w(initial_request followup).freeze
Expand Down
2 changes: 2 additions & 0 deletions app/views/request/preview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

<div class="message-preview">
<div class="preview-advice">
<%= render_notes(@outgoing_message.all_notes) %>

<div class="advice-panel">
<ul>
<li><%= _('Check you haven\'t included any <strong>personal information</strong>.') %></li>
Expand Down
4 changes: 4 additions & 0 deletions spec/models/outgoing_message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@
require 'spec_helper'
require 'models/concerns/message_prominence'
require 'models/concerns/taggable'
require 'models/concerns/taggable_terms'

RSpec.describe OutgoingMessage do
it_behaves_like 'concerns/message_prominence', :initial_request
it_behaves_like 'concerns/taggable', :initial_request
it_behaves_like 'concerns/taggable_terms',
:initial_request, { body: 'Some trains and a bus.' },
:body

describe '.is_searchable' do
subject { described_class.is_searchable }
Expand Down

0 comments on commit e219f9e

Please sign in to comment.