Allow changing the visibitly (public/privat) of messages (fixes #625)
This commit is contained in:
parent
c955a6ee40
commit
226192f7cb
6 changed files with 38 additions and 0 deletions
|
@ -1400,6 +1400,7 @@ de:
|
||||||
title: Neue Nachricht
|
title: Neue Nachricht
|
||||||
show:
|
show:
|
||||||
all_messages: Nachrichten im Überblick
|
all_messages: Nachrichten im Überblick
|
||||||
|
change_visibility: 'Ändern'
|
||||||
from: 'Von:'
|
from: 'Von:'
|
||||||
group: Gruppe
|
group: Gruppe
|
||||||
reply: Antworten
|
reply: Antworten
|
||||||
|
@ -1408,9 +1409,14 @@ de:
|
||||||
subject: 'Betreff:'
|
subject: 'Betreff:'
|
||||||
title: Nachricht anzeigen
|
title: Nachricht anzeigen
|
||||||
to: 'An:'
|
to: 'An:'
|
||||||
|
visibility: 'Sichtbarkeit:'
|
||||||
|
visibility_private: 'Privat'
|
||||||
|
visibility_public: 'Öffentlich'
|
||||||
thread:
|
thread:
|
||||||
all_message_threads: Alle Nachrichtenverläufe
|
all_message_threads: Alle Nachrichtenverläufe
|
||||||
reply: Antworten
|
reply: Antworten
|
||||||
|
toggle_private:
|
||||||
|
not_allowed: Du kannst die Sichtbarkeit dieser Nachricht nicht ändern.
|
||||||
messages_mailer:
|
messages_mailer:
|
||||||
foodsoft_message:
|
foodsoft_message:
|
||||||
footer: |
|
footer: |
|
||||||
|
|
|
@ -1425,6 +1425,7 @@ en:
|
||||||
title: New message
|
title: New message
|
||||||
show:
|
show:
|
||||||
all_messages: All messages
|
all_messages: All messages
|
||||||
|
change_visibility: 'Change'
|
||||||
from: 'From:'
|
from: 'From:'
|
||||||
group: 'Group:'
|
group: 'Group:'
|
||||||
reply: Reply
|
reply: Reply
|
||||||
|
@ -1433,9 +1434,14 @@ en:
|
||||||
subject: 'Subject:'
|
subject: 'Subject:'
|
||||||
title: Show message
|
title: Show message
|
||||||
to: 'To:'
|
to: 'To:'
|
||||||
|
visibility: 'Visibility:'
|
||||||
|
visibility_private: 'Private'
|
||||||
|
visibility_public: 'Public'
|
||||||
thread:
|
thread:
|
||||||
all_message_threads: All message threads
|
all_message_threads: All message threads
|
||||||
reply: Reply
|
reply: Reply
|
||||||
|
toggle_private:
|
||||||
|
not_allowed: You can not change the visibility of the message.
|
||||||
messages_mailer:
|
messages_mailer:
|
||||||
foodsoft_message:
|
foodsoft_message:
|
||||||
footer: |
|
footer: |
|
||||||
|
|
|
@ -48,6 +48,16 @@ class MessagesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def toggle_private
|
||||||
|
message = Message.find(params[:id])
|
||||||
|
if message.can_toggle_private?(current_user)
|
||||||
|
message.update_attribute :private, !message.private
|
||||||
|
redirect_to message
|
||||||
|
else
|
||||||
|
redirect_to message, alert: I18n.t('messages.toggle_private.not_allowed')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def thread
|
def thread
|
||||||
@messages = Message.thread(params[:id]).order(:created_at)
|
@messages = Message.thread(params[:id]).order(:created_at)
|
||||||
end
|
end
|
||||||
|
|
|
@ -124,6 +124,12 @@ class Message < ApplicationRecord
|
||||||
!private || sender == user || recipients_ids.include?(user.id)
|
!private || sender == user || recipients_ids.include?(user.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_toggle_private?(user)
|
||||||
|
return true if sender == user
|
||||||
|
return false if private?
|
||||||
|
user.role_admin?
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def create_salt
|
def create_salt
|
||||||
|
|
|
@ -23,6 +23,15 @@
|
||||||
%tr
|
%tr
|
||||||
%td= t '.sent_on'
|
%td= t '.sent_on'
|
||||||
%td= format_time(@message.created_at)
|
%td= format_time(@message.created_at)
|
||||||
|
%tr
|
||||||
|
%td= t '.visibility'
|
||||||
|
%td
|
||||||
|
- if @message.private
|
||||||
|
= t '.visibility_private'
|
||||||
|
- else
|
||||||
|
= t '.visibility_public'
|
||||||
|
- if @message.can_toggle_private?(current_user)
|
||||||
|
= link_to t('.change_visibility'), toggle_private_message_path(@message), method: :post, class: 'btn btn-mini'
|
||||||
%hr/
|
%hr/
|
||||||
%p= simple_format(h(@message.body))
|
%p= simple_format(h(@message.body))
|
||||||
%hr/
|
%hr/
|
||||||
|
|
|
@ -3,6 +3,7 @@ Rails.application.routes.draw do
|
||||||
resources :messages, :only => [:index, :show, :new, :create] do
|
resources :messages, :only => [:index, :show, :new, :create] do
|
||||||
member do
|
member do
|
||||||
get :thread
|
get :thread
|
||||||
|
post :toggle_private
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue