Skip to content

Commit 1e32636

Browse files
authored
Feature/conversation encryption (#1001)
- adds a slider to edit_person to toggle showing of conversation title and message sender - adds key-value pair for show_conversation_details to person model's notification_preferences - updates the conversation_mailer to reflect these preference changes - adds encryption to conversation model title attribute - host_dashboard resource_cards can now be altered to determine what attribute they show publicly - adds migrations to update un-encrypted values to be encrypted
2 parents bab8aab + c1efdd8 commit 1e32636

File tree

17 files changed

+80
-24
lines changed

17 files changed

+80
-24
lines changed

app/controllers/better_together/people_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ def set_resource_instance
9494
def person_params
9595
params.require(:person).permit(
9696
:name, :description, :profile_image, :slug, :locale, :notify_by_email,
97-
:profile_image, :cover_image, :remove_profile_image, :remove_cover_image,
97+
:show_conversation_details, :profile_image, :cover_image, :remove_profile_image,
98+
:remove_cover_image,
9899
*resource_class.permitted_attributes
99100
)
100101
end

app/mailers/better_together/conversation_mailer.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,25 @@ def new_message_notification # rubocop:todo Metrics/MethodLength, Metrics/AbcSiz
1111
@recipient = params[:recipient]
1212
@sender = @message.sender
1313

14+
from = t('better_together.conversation_mailer.new_message_notification.from_address',
15+
from_address: default_params[:from])
1416
subject = t('better_together.conversation_mailer.new_message_notification.subject')
15-
if @conversation.title.present?
16-
subject = t('better_together.conversation_mailer.new_message_notification.subject_with_title',
17-
conversation: @conversation.title)
17+
if @recipient.show_conversation_details
18+
if @conversation.title.present?
19+
subject = t('better_together.conversation_mailer.new_message_notification.subject_with_title',
20+
conversation: @conversation.title)
21+
end
22+
from = t('better_together.conversation_mailer.new_message_notification.from_address_with_sender',
23+
sender_name: @sender.name,
24+
from_address: default_params[:from])
1825
end
1926

2027
# Override time zone and locale if necessary
2128
self.locale = @recipient.locale
2229
self.time_zone = @recipient.time_zone
2330

2431
mail(to: @recipient.email,
25-
from: t('better_together.conversation_mailer.new_message_notification.from_address',
26-
sender_name: @sender.name,
27-
from_address: default_params[:from]),
28-
subject:)
32+
from:, subject:)
2933
end
3034
# rubocop:enable Metrics/AbcSize
3135
end

app/models/better_together/conversation.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module BetterTogether
44
# groups messages for participants
55
class Conversation < ApplicationRecord
6+
encrypts :title, deterministic: true
67
belongs_to :creator, class_name: 'BetterTogether::Person'
78
has_many :messages, dependent: :destroy
89
has_many :conversation_participants, dependent: :destroy

app/models/better_together/person.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def self.primary_community_delegation_attrs
6868

6969
store_attributes :notification_preferences do
7070
notify_by_email Boolean, default: true
71+
show_conversation_details Boolean, default: false
7172
end
7273

7374
validates :name,

app/notifiers/better_together/new_message_notifier.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def sender
3333
delegate :url, to: :event
3434

3535
def send_email_notification?
36-
recipient.email.present? && recipient.notification_preferences['notify_by_email'] && should_send_email?
36+
recipient.email.present? && recipient.notify_by_email && should_send_email?
3737
end
3838

3939
def should_send_email?

app/views/better_together/conversation_mailer/new_message_notification.html.erb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
<p><%= t('.greeting', recipient_name: @recipient.name) %></p>
44

5-
<p><%= t('.message_intro', sender_name: @sender.name) %></p>
5+
6+
<% if(@recipient.show_conversation_details) %>
7+
<p><%= t('.message_intro_with_sender', sender_name: @sender.name) %></p>
8+
<% else %>
9+
<p><%= t('.message_intro') %></p>
10+
<% end %>
611

712
<p><%= t('.view_conversation') %></p>
813

app/views/better_together/host_dashboard/_resource_card.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- app/views/better_together/host_dashboard/_resource_card.html.erb -->
22

3-
<%# locals: (collection:, model_class: collection.model, model_name: model_class.model_name, count:, url_helper: :url_for) -%>
3+
<%# locals: (collection:, model_class: collection.model, model_name: model_class.model_name, count:, url_helper: :url_for, show_attr: :to_s) -%>
44

55
<div class="col mb-4">
66
<div class="card hover-effect shadow-sm h-100">
@@ -19,12 +19,12 @@
1919
<div class="card-body" style="min-height: 100px;">
2020
<% if collection.any? %>
2121
<% collection.each do |resource| %>
22-
<div class="d-flex justify-content-between mb-2">
22+
<div class="d-flex justify-content-between mb-2">
2323
<span class="text-truncate" style="max-width: 70%;" data-bs-toggle="tooltip" title="<%= resource.to_s %>">
24-
<% if policy(resource).show? %>
24+
<% if policy(resource).show? %>
2525
<%= link_to resource, public_send(url_helper, resource), class: "text-decoration-none" %>
2626
<% else %>
27-
<%= resource %>
27+
<%= resource.public_send(show_attr) %>
2828
<% end %>
2929
</span>
3030
<span class="text-muted small" data-bs-toggle="tooltip" title="<%= l(resource.created_at, format: :long) %>">

app/views/better_together/host_dashboard/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
<!-- Users -->
3737
<%= render partial: 'resource_card', locals: { collection: @users, count: @user_count, url_helper: :user_path } %>
38-
<%= render partial: 'resource_card', locals: { collection: @conversations, count: @conversation_count, url_helper: :conversation_path } %>
38+
<%= render partial: 'resource_card', locals: { collection: @conversations, count: @conversation_count, url_helper: :conversation_path, show_attr: :id } %>
3939
<%= render partial: 'resource_card', locals: { collection: @messages, count: @message_count, url_helper: :message_path } %>
4040
<%= render partial: 'resource_card', locals: { collection: @categories, count: @category_count, url_helper: :category_path } %>
4141
</div>

app/views/better_together/people/_form.html.erb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
</div>
114114
</div>
115115

116-
<!-- Device Permissions Tab -->
116+
<!-- Preferences Tab -->
117117
<div class="nav-tab-pane tab-pane fade"
118118
id="person-preferences"
119119
role="tabpanel"
@@ -128,6 +128,10 @@
128128
<%= render partial: 'better_together/shared/fields/toggle_switch', locals: {form:, attr: :notify_by_email} %>
129129
<small class="form-text text-muted"><%= t('helpers.hint.person.notify_by_email') %></small>
130130
</div>
131+
<div class="mb-3">
132+
<%= render partial: 'better_together/shared/fields/toggle_switch', locals: {form:, attr: :show_conversation_details} %>
133+
<small class="form-text text-muted"><%= t('helpers.hint.person.show_conversation_details') %></small>
134+
</div>
131135
</div>
132136

133137
<!-- Device Permissions Tab -->

config/locales/en.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ en:
303303
person_platform_memberships: Person platform memberships
304304
platform_roles: Platform roles
305305
preferences: Preferences
306+
show_conversation_details: Show conversation details
306307
slug: Username
307308
slugs: Slugs
308309
string_translations: String translations
@@ -628,9 +629,11 @@ en:
628629
add: Add Contact
629630
conversation_mailer:
630631
new_message_notification:
631-
from_address: '%{sender_name} via %{from_address}'
632+
from_address: 'New message via %{from_address}'
633+
from_address_with_sender: '%{sender_name} via %{from_address}'
632634
greeting: Hello %{recipient_name},
633-
message_intro: 'You have an unread message from %{sender_name}:'
635+
message_intro: You have an unread message
636+
message_intro_with_sender: 'You have an unread message from %{sender_name}'
634637
signature: Signature
635638
signature_html: |-
636639
Best regards,<br />
@@ -1315,6 +1318,7 @@ en:
13151318
name: Enter the full name of the person.
13161319
notify_by_email: Send an email when a conversation has an unread message.
13171320
profile_image: Upload a profile image for the person.
1321+
show_conversation_details: Show conversation title and sender name in notifications.
13181322
slug: A URL-friendly identifier, typically auto-generated.
13191323
label:
13201324
person:

0 commit comments

Comments
 (0)