Skip to content

Commit 20271f1

Browse files
committed
Fix code style issues and the sender map logic to handle the empty pref case correctly.
Also fixed the rails script to use the correct directory always.
1 parent aedc9f5 commit 20271f1

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

app/models/message_gateway.rb

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class MessageGateway < ActionMailer::Base
22
def receive(email)
33
user = get_receiving_user_from_email_address(email)
44
return false if user.nil?
5-
return false unless check_sender_is_in_mailmap(user, email)
5+
return false unless check_sender_is_in_mailmap(user, email.from[0])
66

77
context = user.prefs.sms_context
88
todo_params = get_todo_params(email)
@@ -90,29 +90,24 @@ def get_receiving_user_from_sms_email(address)
9090
return user
9191
end
9292

93-
def check_sender_is_in_mailmap(user, email)
94-
if user.present? && !sender_is_in_mailmap?(user, email)
95-
Rails.logger.warn "#{email.from[0]} not found in mailmap for #{user.login}"
93+
def check_sender_is_in_mailmap(user, from)
94+
if user.present? && SITE_CONFIG['email_dispatch'] == 'to' && !sender_is_in_mailmap?(user, from)
95+
Rails.logger.warn "#{from} not found in mailmap for #{user.login}"
9696
return false
9797
end
9898
return true
9999
end
100100

101-
def sender_is_in_mailmap?(user, email)
102-
if SITE_CONFIG['email_dispatch'] == 'to'
103-
if SITE_CONFIG['mailmap'].is_a? Hash
104-
# Look for the sender in the map of allowed senders
105-
SITE_CONFIG['mailmap'][user.preference.sms_email].include? email.from[0]
106-
else
107-
# If the config mailmap isn't defined, use the values provided by the users.
108-
pref_senders = user.prefs.sms_permitted_senders.split(',').collect(&:strip)
109-
pref_senders.include? email.from[0]
110-
end
111-
else
112-
# We can't check the map if it's not defined, or if the lookup is the
113-
# wrong way round, so just allow it
114-
true
101+
def sender_is_in_mailmap?(user, from)
102+
if SITE_CONFIG['mailmap'].is_a? Hash
103+
# Look for the sender in the map of allowed senders
104+
SITE_CONFIG['mailmap'][user.preference.sms_email].include? from
105+
elif !(pref_senders = user.prefs.sms_permitted_senders).empty?
106+
# If the config mailmap isn't defined, use the values provided by the users.
107+
pref_senders.split(',').collect(&:strip).include? from
115108
end
109+
# We can't check the map if it's not defined so just allow it
110+
true
116111
end
117112

118113
def get_text_or_nil(text)

app/models/preference.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Preference < ApplicationRecord
22
belongs_to :user
33
belongs_to :sms_context, :class_name => 'Context'
44

5-
validates_uniqueness_of :sms_email, :case_sensitive => false
5+
validates :sms_email, uniqueness: { case_sensitive: false }
66

77
def self.themes
88
{ :black => 'black', :light_blue => 'light_blue' }

bin/rails

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ SCRIPT=$(readlink -f "$0")
55
# Absolute path this script is in, thus /home/user/bin
66
SCRIPTPATH=$(dirname "$SCRIPT")
77

8-
if [ -e ../.use-docker -a ! -e /etc/app-env ];
8+
if [ -e $SCRIPTPATH/../.use-docker -a ! -e /etc/app-env ];
99
then
1010
$SCRIPTPATH/../script/docker-environment $0 "$@"
1111
else

0 commit comments

Comments
 (0)