##// END OF EJS Templates
Adds permissions to let users edit and/or delete their messages (#854, patch by Markus Knittig with slight changes)....
Jean-Philippe Lang -
r2017:7a05f8ed6691
parent child
Show More
@@ -19,7 +19,7 class MessagesController < ApplicationController
19 19 menu_item :boards
20 20 before_filter :find_board, :only => [:new, :preview]
21 21 before_filter :find_message, :except => [:new, :preview]
22 before_filter :authorize, :except => :preview
22 before_filter :authorize, :except => [:preview, :edit, :destroy]
23 23
24 24 verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show }
25 25 verify :xhr => true, :only => :quote
@@ -30,7 +30,7 class MessagesController < ApplicationController
30 30
31 31 # Show a topic and its replies
32 32 def show
33 @replies = @topic.children
33 @replies = @topic.children.find(:all, :include => [:author, :attachments, {:board => :project}])
34 34 @replies.reverse! if User.current.wants_comments_in_reverse_order?
35 35 @reply = Message.new(:subject => "RE: #{@message.subject}")
36 36 render :action => "show", :layout => false if request.xhr?
@@ -65,7 +65,8 class MessagesController < ApplicationController
65 65
66 66 # Edit a message
67 67 def edit
68 if params[:message] && User.current.allowed_to?(:edit_messages, @project)
68 render_403 and return false unless @message.editable_by?(User.current)
69 if params[:message]
69 70 @message.locked = params[:message]['locked']
70 71 @message.sticky = params[:message]['sticky']
71 72 end
@@ -78,6 +79,7 class MessagesController < ApplicationController
78 79
79 80 # Delete a messages
80 81 def destroy
82 render_403 and return false unless @message.destroyable_by?(User.current)
81 83 @message.destroy
82 84 redirect_to @message.parent.nil? ?
83 85 { :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } :
@@ -71,6 +71,14 class Message < ActiveRecord::Base
71 71 def project
72 72 board.project
73 73 end
74
75 def editable_by?(usr)
76 usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project)))
77 end
78
79 def destroyable_by?(usr)
80 usr && usr.logged? && (usr.allowed_to?(:delete_messages, project) || (self.author == usr && usr.allowed_to?(:delete_own_messages, project)))
81 end
74 82
75 83 private
76 84
@@ -4,8 +4,8
4 4 <div class="contextual">
5 5 <%= watcher_tag(@topic, User.current) %>
6 6 <%= link_to_remote_if_authorized l(:button_quote), { :url => {:action => 'quote', :id => @topic} }, :class => 'icon icon-comment' %>
7 <%= link_to_if_authorized l(:button_edit), {:action => 'edit', :id => @topic}, :class => 'icon icon-edit' %>
8 <%= link_to_if_authorized l(:button_delete), {:action => 'destroy', :id => @topic}, :method => :post, :confirm => l(:text_are_you_sure), :class => 'icon icon-del' %>
7 <%= link_to(l(:button_edit), {:action => 'edit', :id => @topic}, :class => 'icon icon-edit') if @message.editable_by?(User.current) %>
8 <%= link_to(l(:button_delete), {:action => 'destroy', :id => @topic}, :method => :post, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') if @message.destroyable_by?(User.current) %>
9 9 </div>
10 10
11 11 <h2><%=h @topic.subject %></h2>
@@ -25,8 +25,8
25 25 <a name="<%= "message-#{message.id}" %>"></a>
26 26 <div class="contextual">
27 27 <%= link_to_remote_if_authorized image_tag('comment.png'), { :url => {:action => 'quote', :id => message} }, :title => l(:button_quote) %>
28 <%= link_to_if_authorized image_tag('edit.png'), {:action => 'edit', :id => message}, :title => l(:button_edit) %>
29 <%= link_to_if_authorized image_tag('delete.png'), {:action => 'destroy', :id => message}, :method => :post, :confirm => l(:text_are_you_sure), :title => l(:button_delete) %>
28 <%= link_to(image_tag('edit.png'), {:action => 'edit', :id => message}, :title => l(:button_edit)) if message.editable_by?(User.current) %>
29 <%= link_to(image_tag('delete.png'), {:action => 'destroy', :id => message}, :method => :post, :confirm => l(:text_are_you_sure), :title => l(:button_delete)) if message.destroyable_by?(User.current) %>
30 30 </div>
31 31 <div class="message reply">
32 32 <h4><%=h message.subject %> - <%= authoring message.created_on, message.author %></h4>
@@ -690,3 +690,5 permission_edit_own_issue_notes: Edit own notes
690 690 setting_gravatar_enabled: Use Gravatar user icons
691 691 label_example: Example
692 692 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
693 permission_edit_own_messages: Edit own messages
694 permission_delete_won_messages: Delete own messages
@@ -691,3 +691,5 permission_edit_own_issue_notes: Edit own notes
691 691 setting_gravatar_enabled: Use Gravatar user icons
692 692 label_example: Example
693 693 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
694 permission_edit_own_messages: Edit own messages
695 permission_delete_won_messages: Delete own messages
@@ -695,3 +695,5 permission_edit_own_issue_notes: Edit own notes
695 695 setting_gravatar_enabled: Use Gravatar user icons
696 696 label_example: Example
697 697 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
698 permission_edit_own_messages: Edit own messages
699 permission_delete_won_messages: Delete own messages
@@ -691,3 +691,5 permission_edit_own_issue_notes: Edit own notes
691 691 setting_gravatar_enabled: Use Gravatar user icons
692 692 label_example: Example
693 693 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
694 permission_edit_own_messages: Edit own messages
695 permission_delete_won_messages: Delete own messages
@@ -691,3 +691,5 permission_edit_own_issue_notes: Edit own notes
691 691 setting_gravatar_enabled: Use Gravatar user icons
692 692 label_example: Example
693 693 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
694 permission_edit_own_messages: Edit own messages
695 permission_delete_won_messages: Delete own messages
@@ -269,7 +269,9 permission_manage_boards: Manage boards
269 269 permission_view_messages: View messages
270 270 permission_add_messages: Post messages
271 271 permission_edit_messages: Edit messages
272 permission_edit_own_messages: Edit own messages
272 273 permission_delete_messages: Delete messages
274 permission_delete_won_messages: Delete own messages
273 275
274 276 project_module_issue_tracking: Issue tracking
275 277 project_module_time_tracking: Time tracking
@@ -693,3 +693,5 permission_edit_own_issue_notes: Edit own notes
693 693 setting_gravatar_enabled: Use Gravatar user icons
694 694 label_example: Example
695 695 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
696 permission_edit_own_messages: Edit own messages
697 permission_delete_won_messages: Delete own messages
@@ -690,3 +690,5 permission_edit_own_issue_notes: Edit own notes
690 690 setting_gravatar_enabled: Use Gravatar user icons
691 691 label_example: Example
692 692 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
693 permission_edit_own_messages: Edit own messages
694 permission_delete_won_messages: Delete own messages
@@ -270,7 +270,9 permission_manage_boards: Gérer les forums
270 270 permission_view_messages: Voir les messages
271 271 permission_add_messages: Poster un message
272 272 permission_edit_messages: Modifier les messages
273 permission_edit_own_messages: Modifier ses propres messages
273 274 permission_delete_messages: Supprimer les messages
275 permission_delete_won_messages: Supprimer ses propres messages
274 276
275 277 project_module_issue_tracking: Suivi des demandes
276 278 project_module_time_tracking: Suivi du temps passé
@@ -690,3 +690,5 permission_edit_own_issue_notes: Edit own notes
690 690 setting_gravatar_enabled: Use Gravatar user icons
691 691 label_example: Example
692 692 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
693 permission_edit_own_messages: Edit own messages
694 permission_delete_won_messages: Delete own messages
@@ -691,3 +691,5 permission_edit_own_issue_notes: Saját jegyzetek szerkesztése
691 691 setting_gravatar_enabled: Felhasználói fényképek engedélyezése
692 692 label_example: Example
693 693 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
694 permission_edit_own_messages: Edit own messages
695 permission_delete_won_messages: Delete own messages
@@ -690,3 +690,5 permission_edit_own_issue_notes: Modifica proprie note
690 690 setting_gravatar_enabled: Usa icone utente Gravatar
691 691 label_example: Example
692 692 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
693 permission_edit_own_messages: Edit own messages
694 permission_delete_won_messages: Delete own messages
@@ -691,3 +691,5 permission_edit_own_issue_notes: Edit own notes
691 691 setting_gravatar_enabled: Use Gravatar user icons
692 692 label_example: Example
693 693 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
694 permission_edit_own_messages: Edit own messages
695 permission_delete_won_messages: Delete own messages
@@ -690,3 +690,5 permission_edit_own_issue_notes: Edit own notes
690 690 setting_gravatar_enabled: Use Gravatar user icons
691 691 label_example: Example
692 692 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
693 permission_edit_own_messages: Edit own messages
694 permission_delete_won_messages: Delete own messages
@@ -692,3 +692,5 permission_edit_own_issue_notes: Edit own notes
692 692 setting_gravatar_enabled: Use Gravatar user icons
693 693 label_example: Example
694 694 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
695 permission_edit_own_messages: Edit own messages
696 permission_delete_won_messages: Delete own messages
@@ -692,3 +692,5 permission_edit_own_issue_notes: Edit own notes
692 692 setting_gravatar_enabled: Use Gravatar user icons
693 693 label_example: Example
694 694 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
695 permission_edit_own_messages: Edit own messages
696 permission_delete_won_messages: Delete own messages
@@ -691,3 +691,5 permission_edit_own_issue_notes: Edit own notes
691 691 setting_gravatar_enabled: Use Gravatar user icons
692 692 label_example: Example
693 693 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
694 permission_edit_own_messages: Edit own messages
695 permission_delete_won_messages: Delete own messages
@@ -725,3 +725,5 setting_gravatar_enabled: Używaj ikon użytkowników Gravatar
725 725
726 726 label_example: Example
727 727 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
728 permission_edit_own_messages: Edit own messages
729 permission_delete_won_messages: Delete own messages
@@ -691,3 +691,5 permission_edit_own_issue_notes: Editar próprias notas
691 691 setting_gravatar_enabled: Usar ícones do Gravatar
692 692 label_example: Exemplo
693 693 text_repository_usernames_mapping: "Seleciona ou atualiza os usuários do Redmine mapeando para cada usuário encontrado no log do repositório.\nUsuários com o mesmo login ou email no Redmine e no repositório serão mapeados automaticamente."
694 permission_edit_own_messages: Edit own messages
695 permission_delete_won_messages: Delete own messages
@@ -692,3 +692,5 permission_edit_own_issue_notes: Edit own notes
692 692 setting_gravatar_enabled: Use Gravatar user icons
693 693 label_example: Example
694 694 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
695 permission_edit_own_messages: Edit own messages
696 permission_delete_won_messages: Delete own messages
@@ -690,3 +690,5 permission_edit_own_issue_notes: Edit own notes
690 690 setting_gravatar_enabled: Use Gravatar user icons
691 691 label_example: Example
692 692 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
693 permission_edit_own_messages: Edit own messages
694 permission_delete_won_messages: Delete own messages
@@ -723,3 +723,5 text_user_wrote: '%s написал(а):'
723 723 text_wiki_destroy_confirmation: Вы уверены, что хотите удалить данную Wiki и все ее содержимое?
724 724 text_workflow_edit: Выберите роль и трекер для редактирования последовательности состояний
725 725 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
726 permission_edit_own_messages: Edit own messages
727 permission_delete_won_messages: Delete own messages
@@ -695,3 +695,5 permission_edit_own_issue_notes: Editácia vlastných poznámok úlohy
695 695 setting_gravatar_enabled: Použitie uživateľských Gravatar ikon
696 696 label_example: Example
697 697 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
698 permission_edit_own_messages: Edit own messages
699 permission_delete_won_messages: Delete own messages
@@ -691,3 +691,5 permission_edit_own_issue_notes: Edit own notes
691 691 setting_gravatar_enabled: Use Gravatar user icons
692 692 label_example: Example
693 693 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
694 permission_edit_own_messages: Edit own messages
695 permission_delete_won_messages: Delete own messages
@@ -691,3 +691,5 permission_edit_own_issue_notes: Edit own notes
691 691 setting_gravatar_enabled: Use Gravatar user icons
692 692 label_example: Example
693 693 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
694 permission_edit_own_messages: Edit own messages
695 permission_delete_won_messages: Delete own messages
@@ -693,3 +693,5 permission_edit_own_issue_notes: Edit own notes
693 693 setting_gravatar_enabled: Use Gravatar user icons
694 694 label_example: Example
695 695 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
696 permission_edit_own_messages: Edit own messages
697 permission_delete_won_messages: Delete own messages
@@ -691,3 +691,5 permission_edit_own_issue_notes: Edit own notes
691 691 setting_gravatar_enabled: Use Gravatar user icons
692 692 label_example: Example
693 693 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
694 permission_edit_own_messages: Edit own messages
695 permission_delete_won_messages: Delete own messages
@@ -692,3 +692,5 permission_edit_own_issue_notes: Edit own notes
692 692 setting_gravatar_enabled: Use Gravatar user icons
693 693 label_example: Example
694 694 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
695 permission_edit_own_messages: Edit own messages
696 permission_delete_won_messages: Delete own messages
@@ -691,3 +691,5 permission_edit_time_entries: Edit time logs
691 691 permission_edit_own_time_entries: Edit own time logs
692 692 label_example: Example
693 693 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
694 permission_edit_own_messages: Edit own messages
695 permission_delete_won_messages: Delete own messages
@@ -692,3 +692,5 enumeration_issue_priorities: 項目優先權
692 692 enumeration_doc_categories: 文件分類
693 693 enumeration_activities: 活動 (時間追蹤)
694 694 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
695 permission_edit_own_messages: Edit own messages
696 permission_delete_won_messages: Delete own messages
@@ -692,3 +692,5 enumeration_doc_categories: 文档类别
692 692 enumeration_activities: 活动(时间跟踪)
693 693 label_example: Example
694 694 text_repository_usernames_mapping: "Select ou update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
695 permission_edit_own_messages: Edit own messages
696 permission_delete_won_messages: Delete own messages
@@ -99,7 +99,9 Redmine::AccessControl.map do |map|
99 99 map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true
100 100 map.permission :add_messages, {:messages => [:new, :reply, :quote]}
101 101 map.permission :edit_messages, {:messages => :edit}, :require => :member
102 map.permission :edit_own_messages, {:messages => :edit}, :require => :loggedin
102 103 map.permission :delete_messages, {:messages => :destroy}, :require => :member
104 map.permission :delete_own_messages, {:messages => :destroy}, :require => :loggedin
103 105 end
104 106 end
105 107
@@ -65,6 +65,7 module Redmine
65 65 :edit_wiki_pages,
66 66 :delete_wiki_pages,
67 67 :add_messages,
68 :edit_own_messages,
68 69 :view_files,
69 70 :manage_files,
70 71 :browse_repository,
@@ -85,6 +86,7 module Redmine
85 86 :view_wiki_pages,
86 87 :view_wiki_edits,
87 88 :add_messages,
89 :edit_own_messages,
88 90 :view_files,
89 91 :browse_repository,
90 92 :view_changesets]
@@ -38,8 +38,8 messages_004:
38 38 updated_on: 2007-08-12 17:15:32 +02:00
39 39 subject: Post 2
40 40 id: 4
41 replies_count: 1
42 last_reply_id: 5
41 replies_count: 2
42 last_reply_id: 6
43 43 content: "This is an other post"
44 44 author_id:
45 45 parent_id:
@@ -55,3 +55,14 messages_005:
55 55 author_id: 1
56 56 parent_id: 4
57 57 board_id: 1
58 messages_006:
59 created_on: <%= 2.days.ago.to_date.to_s(:db) %>
60 updated_on: <%= 2.days.ago.to_date.to_s(:db) %>
61 subject: 'RE: post 2'
62 id: 6
63 replies_count: 0
64 last_reply_id:
65 content: "Another reply to the second post"
66 author_id: 3
67 parent_id: 4
68 board_id: 1
@@ -80,6 +80,8 roles_002:
80 80 - :protect_wiki_pages
81 81 - :delete_wiki_pages
82 82 - :add_messages
83 - :edit_own_messages
84 - :delete_own_messages
83 85 - :manage_boards
84 86 - :view_files
85 87 - :manage_files
@@ -1,7 +1,7
1 1 require File.dirname(__FILE__) + '/../test_helper'
2 2
3 3 class MessageTest < Test::Unit::TestCase
4 fixtures :projects, :boards, :messages, :users, :watchers
4 fixtures :projects, :roles, :members, :boards, :messages, :users, :watchers
5 5
6 6 def setup
7 7 @board = Board.find(1)
@@ -76,4 +76,22 class MessageTest < Test::Unit::TestCase
76 76 assert_equal topics_count, board.topics_count
77 77 assert_equal messages_count - 1, board.messages_count
78 78 end
79
80 def test_editable_by
81 message = Message.find(6)
82 author = message.author
83 assert message.editable_by?(author)
84
85 author.role_for_project(message.project).remove_permission!(:edit_own_messages)
86 assert !message.reload.editable_by?(author.reload)
87 end
88
89 def test_destroyable_by
90 message = Message.find(6)
91 author = message.author
92 assert message.destroyable_by?(author)
93
94 author.role_for_project(message.project).remove_permission!(:delete_own_messages)
95 assert !message.reload.destroyable_by?(author.reload)
96 end
79 97 end
General Comments 0
You need to be logged in to leave comments. Login now