Show private messages in foodsofts index pages (fixes #106)
This commit is contained in:
parent
f8148e7d30
commit
722bb474d1
7 changed files with 10 additions and 8 deletions
|
@ -8,6 +8,6 @@ class MessageThreadsController < ApplicationController
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@group = Group.find_by_id(params[:id])
|
@group = Group.find_by_id(params[:id])
|
||||||
@message_threads = Message.pub.threads.where(group: @group).page(params[:page]).per(@per_page).order(created_at: :desc)
|
@message_threads = Message.readable_for(current_user).threads.where(group: @group).page(params[:page]).per(@per_page).order(created_at: :desc)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@ class MessagesController < ApplicationController
|
||||||
|
|
||||||
# Renders the "inbox" action.
|
# Renders the "inbox" action.
|
||||||
def index
|
def index
|
||||||
@messages = Message.pub.page(params[:page]).per(@per_page).order('created_at DESC').includes(:sender)
|
@messages = Message.readable_for(current_user).page(params[:page]).per(@per_page).order('created_at DESC').includes(:sender)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates a new message object.
|
# Creates a new message object.
|
||||||
|
|
|
@ -9,9 +9,11 @@ class Message < ApplicationRecord
|
||||||
|
|
||||||
attr_accessor :send_method, :recipient_tokens, :order_id
|
attr_accessor :send_method, :recipient_tokens, :order_id
|
||||||
|
|
||||||
scope :pub, -> { where(:private => false) }
|
|
||||||
scope :threads, -> { where(:reply_to => nil) }
|
scope :threads, -> { where(:reply_to => nil) }
|
||||||
scope :thread, -> (id) { where("id = ? OR reply_to = ?", id, id) }
|
scope :thread, -> (id) { where("id = ? OR reply_to = ?", id, id) }
|
||||||
|
scope :readable_for, -> (user) {
|
||||||
|
joins(:message_recipients).where('private = ? OR message_recipients.user_id = ?', false, user.try(&:id)).distinct
|
||||||
|
}
|
||||||
|
|
||||||
validates_presence_of :message_recipients, :subject, :body
|
validates_presence_of :message_recipients, :subject, :body
|
||||||
validates_length_of :subject, :in => 1..255
|
validates_length_of :subject, :in => 1..255
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/ insert_after 'erb[silent]:contains("<dashboard_middle_mark>")'
|
/ insert_after 'erb[silent]:contains("<dashboard_middle_mark>")'
|
||||||
- if FoodsoftMessages.enabled?
|
- if FoodsoftMessages.enabled?
|
||||||
- unless Message.pub.empty?
|
- unless Message.readable_for(current_user).empty?
|
||||||
%section#messages
|
%section#messages
|
||||||
%h2= t '.messages.title'
|
%h2= t '.messages.title'
|
||||||
= render 'messages/messages', messages: Message.pub.order('created_at DESC').limit(5), pagination: false
|
= render 'messages/messages', messages: Message.readable_for(current_user).order('created_at DESC').limit(5), pagination: false
|
||||||
%p= raw t '.messages.view_all.text', messages: link_to(t('.messages.view_all.messages'), messages_path), threads: link_to(t('.messages.view_all.threads'), message_threads_path)
|
%p= raw t '.messages.view_all.text', messages: link_to(t('.messages.view_all.messages'), messages_path), threads: link_to(t('.messages.view_all.threads'), message_threads_path)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
- message_threads = Message.pub.threads.where(group: group).order(created_at: :desc).limit(5)
|
- message_threads = Message.readable_for(current_user).threads.where(group: group).order(created_at: :desc).limit(5)
|
||||||
- unless message_threads.empty?
|
- unless message_threads.empty?
|
||||||
%section
|
%section
|
||||||
%h3
|
%h3
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
- if pagination
|
- if pagination
|
||||||
- if Message.pub.count > 20
|
- if Message.readable_for(current_user).count > 20
|
||||||
= items_per_page
|
= items_per_page
|
||||||
= pagination_links_remote message_threads
|
= pagination_links_remote message_threads
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
- if pagination
|
- if pagination
|
||||||
- if Message.pub.count > 20
|
- if Message.readable_for(current_user).count > 20
|
||||||
= items_per_page
|
= items_per_page
|
||||||
= pagination_links_remote messages
|
= pagination_links_remote messages
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue