Add reply_to and group_id to messages schema

This commit is contained in:
Patrick Gansterer 2015-02-26 00:11:39 +01:00 committed by wvengen
parent 3a3119f274
commit 55e8ff481c
7 changed files with 41 additions and 18 deletions

View file

@ -1120,16 +1120,20 @@ de:
subscribe: Erklärungen zum Verteiler findest Du im %{link}.
subscribe_msg: Eventuell musst Du Dich dem Verteiler erst bekannt machen.
wiki: Wiki (Abschnitt Mailing-Liste)
message: Nachricht
no_user_found: Kein/e Benutzer/in gefunden
reply_to: Diese Nachricht ist eine Antwort auf eine andere %{link}.
search: Suche ...
search_user: Nach Bernutzer/in suchen
title: Neue Nachricht
show:
all_messages: Nachrichten im Überblick
from: 'Von:'
group: 'Gruppe:'
reply: Antworten
sent_on: 'Gesendet:'
subject: 'Betreff:'
reply_to: 'Antwort auf:'
title: Nachricht anzeigen
to: 'An:'
messages_mailer:

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20141211210719) do
ActiveRecord::Schema.define(version: 20150227161931) do
create_table "article_categories", force: :cascade do |t|
t.string "name", limit: 255, default: "", null: false
@ -186,6 +186,8 @@ ActiveRecord::Schema.define(version: 20141211210719) do
t.integer "email_state", limit: 4, default: 0, null: false
t.boolean "private", limit: 1, default: false
t.datetime "created_at"
t.integer "reply_to", limit: 4
t.integer "group_id", limit: 4
end
create_table "order_articles", force: :cascade do |t|

View file

@ -10,8 +10,18 @@ class MessagesController < ApplicationController
# Creates a new message object.
def new
@message = Message.new(params[:message])
if @message.reply_to && !@message.reply_to.is_readable_for?(current_user)
redirect_to new_message_url, alert: 'Nachricht ist privat!'
if @message.reply_to
original_message = Message.find(@message.reply_to)
if original_message.is_readable_for?(current_user)
@message.add_recipients [original_message.sender]
@message.group_id = original_message.group_id
@message.subject = I18n.t('messages.model.reply_subject', :subject => original_message.subject)
@message.body = I18n.t('messages.model.reply_header', :user => original_message.sender.display, :when => I18n.l(original_message.created_at, :format => :short)) + "\n"
original_message.body.each_line{ |l| @message.body += I18n.t('messages.model.reply_indent', :line => l) }
else
redirect_to new_message_url, alert: 'Nachricht ist privat!'
end
end
end

View file

@ -1,8 +1,10 @@
class Message < ActiveRecord::Base
belongs_to :sender, :class_name => "User", :foreign_key => "sender_id"
belongs_to :group, :class_name => "Group", :foreign_key => "group_id"
belongs_to :reply_to_message, :class_name => "Message", :foreign_key => "reply_to"
serialize :recipients_ids, Array
attr_accessor :sent_to_all, :group_id, :recipient_tokens, :reply_to
attr_accessor :sent_to_all, :recipient_tokens
scope :pending, -> { where(:email_state => 0) }
scope :sent, -> { where(:email_state => 1) }
@ -26,6 +28,7 @@ class Message < ActiveRecord::Base
end
def clean_up_recipient_ids
add_recipients Group.find(group_id).users unless group_id.blank?
self.recipients_ids = recipients_ids.uniq.reject { |id| id.blank? } unless recipients_ids.nil?
self.recipients_ids = User.all.collect(&:id) if sent_to_all == "1"
end
@ -35,24 +38,11 @@ class Message < ActiveRecord::Base
self.recipients_ids += users.collect(&:id) unless users.blank?
end
def group_id=(group_id)
@group_id = group_id
add_recipients Group.find(group_id).users unless group_id.blank?
end
def recipient_tokens=(ids)
@recipient_tokens = ids
add_recipients ids.split(",").collect { |id| User.find(id) }
end
def reply_to=(message_id)
@reply_to = Message.find(message_id)
add_recipients([@reply_to.sender])
self.subject = I18n.t('messages.model.reply_subject', :subject => @reply_to.subject)
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) }
end
def mail_to=(user_id)
user = User.find(user_id)
add_recipients([user])

View file

@ -22,6 +22,11 @@
- title t('.title')
= simple_form_for @message do |f|
= f.hidden_field :reply_to
- if @message.reply_to
%p= t('.reply_to', link: link_to(t('.message'), message_path(@message.reply_to))).html_safe
- if FoodsoftConfig[:mailing_list].blank?
= f.input :sent_to_all, :as => :boolean
- else

View file

@ -8,6 +8,14 @@
%tr
%td= t '.to'
%td= @message.recipients.map {|e| e.name}.join(', ')
- if @message.group
%tr
%td= t '.group'
%td= @message.group.name
- if @message.reply_to
%tr
%td= t '.reply_to'
%td= link_to @message.reply_to_message.subject, message_path(@message.reply_to)
%tr
%td= t '.subject'
%td

View file

@ -58,14 +58,18 @@ en:
subscribe: You can find more about the mailing-list at %{link}.
subscribe_msg: You may have to subscribe to the mailing-list first.
wiki: Wiki (page Mailing-List)
message: message
no_user_found: No user found
reply_to: This message is an reply to an other %{link}.
search: Search ...
search_user: Search user
title: New message
show:
all_messages: All messages
from: ! 'From:'
group: 'Group:'
reply: Reply
reply_to: 'Reply to:'
sent_on: ! 'Sent:'
subject: ! 'Subject:'
title: Show message