user display changes in model and mailer
This commit is contained in:
parent
f6c2fd9a9d
commit
ea3db22306
4 changed files with 23 additions and 9 deletions
|
@ -1,6 +1,11 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
# ActionMailer class that handles all emails for the FoodSoft.
|
# ActionMailer class that handles all emails for the FoodSoft.
|
||||||
class Mailer < ActionMailer::Base
|
class Mailer < ActionMailer::Base
|
||||||
|
# XXX Quick fix to allow the use of show_user. Proper take would be one of
|
||||||
|
# (1) Use draper, decorate user
|
||||||
|
# (2) Create a helper with this method, include here and in ApplicationHelper
|
||||||
|
helper :application
|
||||||
|
include ApplicationHelper
|
||||||
|
|
||||||
layout 'email' # Use views/layouts/email.txt.erb
|
layout 'email' # Use views/layouts/email.txt.erb
|
||||||
|
|
||||||
|
@ -15,7 +20,7 @@ class Mailer < ActionMailer::Base
|
||||||
|
|
||||||
mail subject: "[#{FoodsoftConfig[:name]}] " + message.subject,
|
mail subject: "[#{FoodsoftConfig[:name]}] " + message.subject,
|
||||||
to: recipient.email,
|
to: recipient.email,
|
||||||
from: "#{message.sender.nick} <#{message.sender.email}>"
|
from: "#{show_user(message.sender)} <#{message.sender.email}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sends an email with instructions on how to reset the password.
|
# Sends an email with instructions on how to reset the password.
|
||||||
|
@ -26,7 +31,7 @@ class Mailer < ActionMailer::Base
|
||||||
@link = new_password_url(id: @user.id, token: @user.reset_password_token)
|
@link = new_password_url(id: @user.id, token: @user.reset_password_token)
|
||||||
|
|
||||||
mail :to => @user.email,
|
mail :to => @user.email,
|
||||||
:subject => "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.reset_password.subject', :username => @user.nick)
|
:subject => "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.reset_password.subject', :username => show_user(@user))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sends an invite email.
|
# Sends an invite email.
|
||||||
|
@ -75,7 +80,7 @@ class Mailer < ActionMailer::Base
|
||||||
@feedback = feedback
|
@feedback = feedback
|
||||||
|
|
||||||
mail :to => FoodsoftConfig[:notification]["error_recipients"],
|
mail :to => FoodsoftConfig[:notification]["error_recipients"],
|
||||||
:from => "#{user.nick} <#{user.email}>",
|
:from => "#{show_user user} <#{user.email}>",
|
||||||
:sender => FoodsoftConfig[:notification]["sender_address"],
|
:sender => FoodsoftConfig[:notification]["sender_address"],
|
||||||
:errors_to => FoodsoftConfig[:notification]["sender_address"],
|
:errors_to => FoodsoftConfig[:notification]["sender_address"],
|
||||||
:subject => "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.feedback.subject', :email => user.email)
|
:subject => "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.feedback.subject', :email => user.email)
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Message < ActiveRecord::Base
|
||||||
@reply_to = Message.find(message_id)
|
@reply_to = Message.find(message_id)
|
||||||
add_recipients([@reply_to.sender])
|
add_recipients([@reply_to.sender])
|
||||||
self.subject = I18n.t('messages.model.reply_subject', :subject => @reply_to.subject)
|
self.subject = I18n.t('messages.model.reply_subject', :subject => @reply_to.subject)
|
||||||
self.body = I18n.t('messages.model.reply_header', :user => @reply_to.sender.nick, :when => I18n.l(@reply_to.created_at, :format => :short)) + "\n"
|
self.body = I18n.t('messages.model.reply_header', :user => @reply_to.sender.display, :when => I18n.l(@reply_to.created_at, :format => :short)) + "\n"
|
||||||
@reply_to.body.each_line{ |l| self.body += I18n.t('messages.model.reply_indent', :line => l) }
|
@reply_to.body.each_line{ |l| self.body += I18n.t('messages.model.reply_indent', :line => l) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ class Message < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def sender_name
|
def sender_name
|
||||||
system_message? ? I18n.t('layouts.foodsoft') : sender.nick rescue "??"
|
system_message? ? I18n.t('layouts.foodsoft') : sender.display rescue "?"
|
||||||
end
|
end
|
||||||
|
|
||||||
def recipients
|
def recipients
|
||||||
|
@ -77,7 +77,7 @@ class Message < ActiveRecord::Base
|
||||||
begin
|
begin
|
||||||
Mailer.foodsoft_message(self, user).deliver
|
Mailer.foodsoft_message(self, user).deliver
|
||||||
rescue
|
rescue
|
||||||
Rails.logger.warn "Deliver failed for #{user.nick}: #{user.email}"
|
Rails.logger.warn "Deliver failed for user \##{user.id}: #{user.email}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Ordergroup < Group
|
||||||
"#{contact_phone} (#{contact_person})"
|
"#{contact_phone} (#{contact_person})"
|
||||||
end
|
end
|
||||||
def non_members
|
def non_members
|
||||||
User.all(:order => 'nick').reject { |u| (users.include?(u) || u.ordergroup) }
|
User.natural_order.all.reject { |u| (users.include?(u) || u.ordergroup) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def value_of_open_orders(exclude = nil)
|
def value_of_open_orders(exclude = nil)
|
||||||
|
@ -102,7 +102,7 @@ class Ordergroup < Group
|
||||||
# Make sure, that a user can only be in one ordergroup
|
# Make sure, that a user can only be in one ordergroup
|
||||||
def uniqueness_of_members
|
def uniqueness_of_members
|
||||||
users.each do |user|
|
users.each do |user|
|
||||||
errors.add :user_tokens, I18n.t('ordergroups.model.error_single_group', :user => user.nick) if user.groups.where(:type => 'Ordergroup').size > 1
|
errors.add :user_tokens, I18n.t('ordergroups.model.error_single_group', :user => user.display) if user.groups.where(:type => 'Ordergroup').size > 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -158,8 +158,17 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# XXX this is view-related; need to move out things like token_attributes
|
||||||
|
# then this can be removed
|
||||||
|
def display
|
||||||
|
# would be sensible to match ApplicationController#show_user
|
||||||
|
FoodsoftConfig[:use_nick] ? nick : "#{first_name} #{last_name}"
|
||||||
|
end
|
||||||
|
|
||||||
def token_attributes
|
def token_attributes
|
||||||
{:id => id, :name => "#{nick} (#{ordergroup.try(:name)})"}
|
# would be sensible to match ApplicationController#show_user
|
||||||
|
# this should not be part of the model anyway
|
||||||
|
{:id => id, :name => "#{display} (#{ordergroup.try(:name)})"}
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue