Add a user preference that can be used as a fallback for the sender authentication.

This commit is contained in:
Jyri-Petteri Paloposki 2022-02-22 18:46:14 +02:00
parent f40e3c0788
commit ddcd468070
7 changed files with 21 additions and 4 deletions

View file

@ -39,7 +39,7 @@ class PreferencesController < ApplicationController
:staleness_starts, :due_style, :locale, :title_date_format, :time_zone,
:show_hidden_projects_in_sidebar, :show_project_on_todo_done,
:review_period, :refresh, :verbose_action_descriptors,
:mobile_todos_per_page, :sms_email, :sms_context_id, :theme)
:mobile_todos_per_page, :sms_email, :sms_context_id, :sms_permitted_senders, :theme)
end
def user_params

View file

@ -99,9 +99,15 @@ class MessageGateway < ActionMailer::Base
end
def sender_is_in_mailmap?(user, email)
if (SITE_CONFIG['mailmap'].is_a? Hash) && SITE_CONFIG['email_dispatch'] == 'to'
if SITE_CONFIG['email_dispatch'] == 'to'
if SITE_CONFIG['mailmap'].is_a? Hash
# Look for the sender in the map of allowed senders
SITE_CONFIG['mailmap'][user.preference.sms_email].include? email.from[0]
else
# If the config mailmap isn't defined, use the values provided by the users.
pref_senders = user.prefs.sms_permitted_senders.split(',').collect(&:strip)
pref_senders.include? email.from[0]
end
else
# We can't check the map if it's not defined, or if the lookup is the
# wrong way round, so just allow it

View file

@ -37,6 +37,9 @@
<div class="form-group">
<%= pref('prefs', "sms_context") { select('prefs', 'sms_context_id', current_user.contexts.map{|c| [c.name, c.id]}, {}, class: "form-control") } %>
</div>
<div class="form-group">
<%= pref_with_text_field('prefs', "sms_permitted_senders") %>
</div>
<div class="form-group">
<%= pref_with_select_field('prefs', 'theme', [[t('models.preference.themes.black'), Preference.themes[:black]], [t('models.preference.themes.light_blue'), Preference.themes[:light_blue]]]) %>
</div>

View file

@ -21,6 +21,7 @@ en:
show_project_on_todo_done: Go to project page on completing todo
sms_context: Default email context
sms_email: From email
sms_permitted_senders: Permitted email senders (use comma as separator)
staleness_starts: Start of staleness
theme: Theme
time_zone: Time zone

View file

@ -21,6 +21,7 @@ fi:
show_project_on_todo_done: Siirry projektinäkymään toimenpiteen valmistuessa
sms_context: Sähköpostin oletusasiayhteys
sms_email: Lähettäjän sähköpostiosoite
sms_permitted_senders: Sallitut lähettäjät (käytä pilkkua erottimena)
staleness_starts: Vanhentumisen alkaminen
time_zone: Aikavyöhyke
title_date_format: Otsakkeen päivämäärämuoto

View file

@ -0,0 +1,5 @@
class AddSmspermittedsendersToPreference < ActiveRecord::Migration[5.2]
def change
add_column :preferences, :sms_permitted_senders, :string
end
end

View file

@ -88,6 +88,7 @@ ActiveRecord::Schema.define(version: 2020_08_20_000743) do
t.string "locale"
t.integer "review_period", default: 14, null: false
t.string "theme"
t.string "sms_permitted_senders"
t.index ["user_id"], name: "index_preferences_on_user_id"
end