2009-01-06 11:49:19 +01:00
|
|
|
class MessagesController < ApplicationController
|
2011-05-18 14:47:17 +02:00
|
|
|
|
2014-04-05 18:47:16 +02:00
|
|
|
before_filter -> { require_plugin_enabled FoodsoftMessages }
|
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
# Renders the "inbox" action.
|
|
|
|
def index
|
2014-11-21 14:37:56 +01:00
|
|
|
@messages = Message.pub.page(params[:page]).per(@per_page).order('created_at DESC').includes(:sender)
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
2011-05-18 14:47:17 +02:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
# Creates a new message object.
|
|
|
|
def new
|
2011-05-18 14:47:17 +02:00
|
|
|
@message = Message.new(params[:message])
|
2013-03-24 01:36:50 +01:00
|
|
|
if @message.reply_to and not @message.reply_to.is_readable_for?(current_user)
|
|
|
|
redirect_to new_message_url, alert: 'Nachricht ist privat!'
|
|
|
|
end
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
2011-05-18 14:47:17 +02:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
# Creates a new message.
|
|
|
|
def create
|
2009-01-15 18:26:37 +01:00
|
|
|
@message = @current_user.send_messages.new(params[:message])
|
|
|
|
if @message.save
|
2014-03-07 09:51:24 +01:00
|
|
|
Resque.enqueue(MessageNotifier, FoodsoftConfig.scope, 'message_deliver', @message.id)
|
2013-02-09 10:13:56 +01:00
|
|
|
redirect_to messages_url, :notice => I18n.t('messages.create.notice')
|
2009-01-06 11:49:19 +01:00
|
|
|
else
|
|
|
|
render :action => 'new'
|
|
|
|
end
|
|
|
|
end
|
2011-05-18 14:47:17 +02:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
# Shows a single message.
|
|
|
|
def show
|
2009-01-15 18:26:37 +01:00
|
|
|
@message = Message.find(params[:id])
|
2013-03-24 01:36:50 +01:00
|
|
|
unless @message.is_readable_for?(current_user)
|
|
|
|
redirect_to messages_url, alert: 'Nachricht ist privat!'
|
|
|
|
end
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
end
|