Add reply_to and group_id to messages schema
This commit is contained in:
parent
3a3119f274
commit
55e8ff481c
7 changed files with 41 additions and 18 deletions
|
@ -1120,16 +1120,20 @@ de:
|
||||||
subscribe: Erklärungen zum Verteiler findest Du im %{link}.
|
subscribe: Erklärungen zum Verteiler findest Du im %{link}.
|
||||||
subscribe_msg: Eventuell musst Du Dich dem Verteiler erst bekannt machen.
|
subscribe_msg: Eventuell musst Du Dich dem Verteiler erst bekannt machen.
|
||||||
wiki: Wiki (Abschnitt Mailing-Liste)
|
wiki: Wiki (Abschnitt Mailing-Liste)
|
||||||
|
message: Nachricht
|
||||||
no_user_found: Kein/e Benutzer/in gefunden
|
no_user_found: Kein/e Benutzer/in gefunden
|
||||||
|
reply_to: Diese Nachricht ist eine Antwort auf eine andere %{link}.
|
||||||
search: Suche ...
|
search: Suche ...
|
||||||
search_user: Nach Bernutzer/in suchen
|
search_user: Nach Bernutzer/in suchen
|
||||||
title: Neue Nachricht
|
title: Neue Nachricht
|
||||||
show:
|
show:
|
||||||
all_messages: Nachrichten im Überblick
|
all_messages: Nachrichten im Überblick
|
||||||
from: 'Von:'
|
from: 'Von:'
|
||||||
|
group: 'Gruppe:'
|
||||||
reply: Antworten
|
reply: Antworten
|
||||||
sent_on: 'Gesendet:'
|
sent_on: 'Gesendet:'
|
||||||
subject: 'Betreff:'
|
subject: 'Betreff:'
|
||||||
|
reply_to: 'Antwort auf:'
|
||||||
title: Nachricht anzeigen
|
title: Nachricht anzeigen
|
||||||
to: 'An:'
|
to: 'An:'
|
||||||
messages_mailer:
|
messages_mailer:
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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|
|
create_table "article_categories", force: :cascade do |t|
|
||||||
t.string "name", limit: 255, default: "", null: false
|
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.integer "email_state", limit: 4, default: 0, null: false
|
||||||
t.boolean "private", limit: 1, default: false
|
t.boolean "private", limit: 1, default: false
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
|
t.integer "reply_to", limit: 4
|
||||||
|
t.integer "group_id", limit: 4
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "order_articles", force: :cascade do |t|
|
create_table "order_articles", force: :cascade do |t|
|
||||||
|
|
|
@ -10,8 +10,18 @@ class MessagesController < ApplicationController
|
||||||
# Creates a new message object.
|
# Creates a new message object.
|
||||||
def new
|
def new
|
||||||
@message = Message.new(params[:message])
|
@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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
class Message < ActiveRecord::Base
|
class Message < ActiveRecord::Base
|
||||||
belongs_to :sender, :class_name => "User", :foreign_key => "sender_id"
|
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
|
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 :pending, -> { where(:email_state => 0) }
|
||||||
scope :sent, -> { where(:email_state => 1) }
|
scope :sent, -> { where(:email_state => 1) }
|
||||||
scope :pub, -> { where(:private => false) }
|
scope :pub, -> { where(:private => false) }
|
||||||
|
@ -26,6 +28,7 @@ class Message < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean_up_recipient_ids
|
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 = recipients_ids.uniq.reject { |id| id.blank? } unless recipients_ids.nil?
|
||||||
self.recipients_ids = User.all.collect(&:id) if sent_to_all == "1"
|
self.recipients_ids = User.all.collect(&:id) if sent_to_all == "1"
|
||||||
end
|
end
|
||||||
|
@ -35,24 +38,11 @@ class Message < ActiveRecord::Base
|
||||||
self.recipients_ids += users.collect(&:id) unless users.blank?
|
self.recipients_ids += users.collect(&:id) unless users.blank?
|
||||||
end
|
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)
|
def recipient_tokens=(ids)
|
||||||
@recipient_tokens = ids
|
@recipient_tokens = ids
|
||||||
add_recipients ids.split(",").collect { |id| User.find(id) }
|
add_recipients ids.split(",").collect { |id| User.find(id) }
|
||||||
end
|
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)
|
def mail_to=(user_id)
|
||||||
user = User.find(user_id)
|
user = User.find(user_id)
|
||||||
add_recipients([user])
|
add_recipients([user])
|
||||||
|
|
|
@ -22,6 +22,11 @@
|
||||||
- title t('.title')
|
- title t('.title')
|
||||||
|
|
||||||
= simple_form_for @message do |f|
|
= 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?
|
- if FoodsoftConfig[:mailing_list].blank?
|
||||||
= f.input :sent_to_all, :as => :boolean
|
= f.input :sent_to_all, :as => :boolean
|
||||||
- else
|
- else
|
||||||
|
|
|
@ -8,6 +8,14 @@
|
||||||
%tr
|
%tr
|
||||||
%td= t '.to'
|
%td= t '.to'
|
||||||
%td= @message.recipients.map {|e| e.name}.join(', ')
|
%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
|
%tr
|
||||||
%td= t '.subject'
|
%td= t '.subject'
|
||||||
%td
|
%td
|
||||||
|
|
|
@ -58,14 +58,18 @@ en:
|
||||||
subscribe: You can find more about the mailing-list at %{link}.
|
subscribe: You can find more about the mailing-list at %{link}.
|
||||||
subscribe_msg: You may have to subscribe to the mailing-list first.
|
subscribe_msg: You may have to subscribe to the mailing-list first.
|
||||||
wiki: Wiki (page Mailing-List)
|
wiki: Wiki (page Mailing-List)
|
||||||
|
message: message
|
||||||
no_user_found: No user found
|
no_user_found: No user found
|
||||||
|
reply_to: This message is an reply to an other %{link}.
|
||||||
search: Search ...
|
search: Search ...
|
||||||
search_user: Search user
|
search_user: Search user
|
||||||
title: New message
|
title: New message
|
||||||
show:
|
show:
|
||||||
all_messages: All messages
|
all_messages: All messages
|
||||||
from: ! 'From:'
|
from: ! 'From:'
|
||||||
|
group: 'Group:'
|
||||||
reply: Reply
|
reply: Reply
|
||||||
|
reply_to: 'Reply to:'
|
||||||
sent_on: ! 'Sent:'
|
sent_on: ! 'Sent:'
|
||||||
subject: ! 'Subject:'
|
subject: ! 'Subject:'
|
||||||
title: Show message
|
title: Show message
|
||||||
|
|
Loading…
Reference in a new issue