]> source.dussan.org Git - redmine.git/commitdiff
Adds permissions to let users edit and/or delete their messages (#854, patch by Marku...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 11 Nov 2008 15:07:55 +0000 (15:07 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 11 Nov 2008 15:07:55 +0000 (15:07 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2019 e93f8b46-1217-0410-a6f0-8f06a7374b81

39 files changed:
app/controllers/messages_controller.rb
app/models/message.rb
app/views/messages/show.rhtml
lang/bg.yml
lang/ca.yml
lang/cs.yml
lang/da.yml
lang/de.yml
lang/en.yml
lang/es.yml
lang/fi.yml
lang/fr.yml
lang/he.yml
lang/hu.yml
lang/it.yml
lang/ja.yml
lang/ko.yml
lang/lt.yml
lang/nl.yml
lang/no.yml
lang/pl.yml
lang/pt-br.yml
lang/pt.yml
lang/ro.yml
lang/ru.yml
lang/sk.yml
lang/sr.yml
lang/sv.yml
lang/th.yml
lang/tr.yml
lang/uk.yml
lang/vn.yml
lang/zh-tw.yml
lang/zh.yml
lib/redmine.rb
lib/redmine/default_data/loader.rb
test/fixtures/messages.yml
test/fixtures/roles.yml
test/unit/message_test.rb

index 79b4b616a99cec34eedc7c1eecbafd37fd532c42..af39efb21890b9b9fcdad92ac62bf6373740eb3a 100644 (file)
@@ -19,7 +19,7 @@ class MessagesController < ApplicationController
   menu_item :boards
   before_filter :find_board, :only => [:new, :preview]
   before_filter :find_message, :except => [:new, :preview]
-  before_filter :authorize, :except => :preview
+  before_filter :authorize, :except => [:preview, :edit, :destroy]
 
   verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show }
   verify :xhr => true, :only => :quote
@@ -30,7 +30,7 @@ class MessagesController < ApplicationController
 
   # Show a topic and its replies
   def show
-    @replies = @topic.children
+    @replies = @topic.children.find(:all, :include => [:author, :attachments, {:board => :project}])
     @replies.reverse! if User.current.wants_comments_in_reverse_order?
     @reply = Message.new(:subject => "RE: #{@message.subject}")
     render :action => "show", :layout => false if request.xhr?
@@ -65,7 +65,8 @@ class MessagesController < ApplicationController
 
   # Edit a message
   def edit
-    if params[:message] && User.current.allowed_to?(:edit_messages, @project)
+    render_403 and return false unless @message.editable_by?(User.current)
+    if params[:message]
       @message.locked = params[:message]['locked']
       @message.sticky = params[:message]['sticky']
     end
@@ -78,6 +79,7 @@ class MessagesController < ApplicationController
   
   # Delete a messages
   def destroy
+    render_403 and return false unless @message.destroyable_by?(User.current)
     @message.destroy
     redirect_to @message.parent.nil? ?
       { :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } :
index f1cb2d0baa312a701acb203b4e637246d1eb5f32..9a313e822b5923df3ce3c3201188a74c79781d32 100644 (file)
@@ -71,6 +71,14 @@ class Message < ActiveRecord::Base
   def project
     board.project
   end
+
+  def editable_by?(usr)
+    usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project)))
+  end
+
+  def destroyable_by?(usr)
+    usr && usr.logged? && (usr.allowed_to?(:delete_messages, project) || (self.author == usr && usr.allowed_to?(:delete_own_messages, project)))
+  end
   
   private
   
index 31696d56dfde0a6123da884c6f1df86bb7ec3681..4143532b18d42d1f181cb7f878de8ce131b6070a 100644 (file)
@@ -4,8 +4,8 @@
 <div class="contextual">
     <%= watcher_tag(@topic, User.current) %>
     <%= link_to_remote_if_authorized l(:button_quote), { :url => {:action => 'quote', :id => @topic} }, :class => 'icon icon-comment' %>
-    <%= link_to_if_authorized l(:button_edit), {:action => 'edit', :id => @topic}, :class => 'icon icon-edit' %>
-    <%= link_to_if_authorized l(:button_delete), {:action => 'destroy', :id => @topic}, :method => :post, :confirm => l(:text_are_you_sure), :class => 'icon icon-del' %>
+    <%= link_to(l(:button_edit), {:action => 'edit', :id => @topic}, :class => 'icon icon-edit') if @message.editable_by?(User.current) %>
+    <%= 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) %>
 </div>
 
 <h2><%=h @topic.subject %></h2>
@@ -25,8 +25,8 @@
   <a name="<%= "message-#{message.id}" %>"></a>
   <div class="contextual">
     <%= link_to_remote_if_authorized image_tag('comment.png'), { :url => {:action => 'quote', :id => message} }, :title => l(:button_quote) %>
-    <%= link_to_if_authorized image_tag('edit.png'), {:action => 'edit', :id => message}, :title => l(:button_edit) %>
-    <%= link_to_if_authorized image_tag('delete.png'), {:action => 'destroy', :id => message}, :method => :post, :confirm => l(:text_are_you_sure), :title => l(:button_delete) %>
+    <%= link_to(image_tag('edit.png'), {:action => 'edit', :id => message}, :title => l(:button_edit)) if message.editable_by?(User.current) %>
+    <%= 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) %>
   </div>
   <div class="message reply">
   <h4><%=h message.subject %> - <%= authoring message.created_on, message.author %></h4>
index 000f0a97791cb00d92476c53f5bba3b9220bf024..ae345f9d33d8af8e4745a348ce289122b83aa810 100644 (file)
@@ -690,3 +690,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index 5db547ac596ce10f455bcebc6a8caf238d04213c..526495344c7b3edf87afc59dc1388dc7cd3fa364 100644 (file)
@@ -691,3 +691,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."\r
+permission_edit_own_messages: Edit own messages\r
+permission_delete_won_messages: Delete own messages\r
index 09ed76ea971f6309a5b1d33ca684b6fd70ca5e90..d195456cce78100d52648c7e421fea63c1e9140e 100644 (file)
@@ -695,3 +695,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index b5081e9eec70b78305882b4e832d618f3e72fb7c..b5dbe6b2198678c723c77c7ef8ecf7253bcadc5e 100644 (file)
@@ -691,3 +691,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index 3e59bcf9e9095c4ce11a0af422a1f32d0f7965c5..14f6e63a49dce7f1bcc88325dca30ec88a8799c3 100644 (file)
@@ -691,3 +691,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index 8a4a2577dee6987bfac40b5085abe64c9d503887..245663fd05e7362510de369be594dd3987622b31 100644 (file)
@@ -269,7 +269,9 @@ permission_manage_boards: Manage boards
 permission_view_messages: View messages
 permission_add_messages: Post messages
 permission_edit_messages: Edit messages
+permission_edit_own_messages: Edit own messages
 permission_delete_messages: Delete messages
+permission_delete_won_messages: Delete own messages
 
 project_module_issue_tracking: Issue tracking
 project_module_time_tracking: Time tracking
index c3b9de2b6aa69032810c2bd0c7ecde85a702409c..c0a624ba25b9bef9447b001aa1c34e1e50a91bbf 100644 (file)
@@ -693,3 +693,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index bdcefef9cd119c9a5a4e9c1a6947988b877d3bcc..5b2dc0e00d43591fa36eb5046c56604af266e6fb 100644 (file)
@@ -690,3 +690,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index ab34575b25909a6f669ecf5ebcd69373c65dcd73..8b2defbdc1366699916dd662d028475dc48c5e60 100644 (file)
@@ -270,7 +270,9 @@ permission_manage_boards: Gérer les forums
 permission_view_messages: Voir les messages
 permission_add_messages: Poster un message
 permission_edit_messages: Modifier les messages
+permission_edit_own_messages: Modifier ses propres messages
 permission_delete_messages: Supprimer les messages
+permission_delete_won_messages: Supprimer ses propres messages
 
 project_module_issue_tracking: Suivi des demandes
 project_module_time_tracking: Suivi du temps passé
index 13eab75c5bee8154ad51f3279c59da578ab46fde..e7f70e7edf09de1c58fbfc623f10090910a151e9 100644 (file)
@@ -690,3 +690,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index 1c4afdcd35d18db5827d4065e54c3978b031fb88..1d858a4b3c3295aa57c004bbfcf2eb47006585fc 100644 (file)
@@ -691,3 +691,5 @@ permission_edit_own_issue_notes: Saját jegyzetek szerkesztése
 setting_gravatar_enabled: Felhasználói fényképek engedélyezése
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index c6ae84a912ab539013c2f4e3e8202d002dc863c3..f4427104f81f6fed975e74710fa8ca9b7884cb1d 100644 (file)
@@ -690,3 +690,5 @@ permission_edit_own_issue_notes: Modifica proprie note
 setting_gravatar_enabled: Usa icone utente Gravatar
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index 4092584d7009ddcff33b318f474aef4a76207874..347454b506fe3ec37102c7ff3b2a32e2eee1a7a4 100644 (file)
@@ -691,3 +691,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index 595acfa9ef2a60ad59869303c3b355bef84a9cae..498572f928ef8d3e3ee42ccda4187ea3cd6b50b9 100644 (file)
@@ -690,3 +690,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index 544cb14f972567ea5c1e1d63fe37c728ffc323bb..bcec2b3476901588d2e3963a4ee46f4dc5ecbe6c 100644 (file)
@@ -692,3 +692,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index 3434b14817a4429dcf395b6ff4a1ce59d3b9f874..0353419694205077d975b700d8a456da3234a451 100644 (file)
@@ -692,3 +692,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index ca056f809016e093f6cb1d316f13d23172e47976..d6779234a9376fa605b02b358edb0d6a30d710a7 100644 (file)
@@ -691,3 +691,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index df7d525dc714a4ff2d277df51bee9aedd37b1631..2a2df834122491e0ee36f6aee66a6a21f526dcf7 100644 (file)
@@ -725,3 +725,5 @@ setting_gravatar_enabled: Używaj ikon użytkowników Gravatar
 
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index 13660baa96cecca28ac4e1cac156ac30ae66035a..e1fa05892ac27e8536a2921c3d4eb766c5cd1b72 100644 (file)
@@ -691,3 +691,5 @@ permission_edit_own_issue_notes: Editar próprias notas
 setting_gravatar_enabled: Usar ícones do Gravatar
 label_example: Exemplo
 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."
+permission_edit_own_messages: Edit own messages\r
+permission_delete_won_messages: Delete own messages\r
index ce1e27a364969b688610c637f7ddc3a1afe401a5..310d2c3920e21c997f17c9b57b04ff564da6f938 100644 (file)
@@ -692,3 +692,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index 8890f6e2db4bf449eb1bbfeb8f619ef8745aa5cb..cc1d9bc57fd9d304f0807547facb45318684da30 100644 (file)
@@ -690,3 +690,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index 363386dc9788e90ed405b72ca8e2734201b76017..87c3a13cec8b91f87134a916c0ffbb7eb9c2fbd9 100644 (file)
@@ -723,3 +723,5 @@ text_user_wrote: '%s написал(а):'
 text_wiki_destroy_confirmation: Вы уверены, что хотите удалить данную Wiki и все ее содержимое?
 text_workflow_edit: Выберите роль и трекер для редактирования последовательности состояний
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index 5c53eda2fdabd3967b72ef8334ad3e0ff42679eb..65a9920ea4707f2c4c9be8fa8a3a42a40adb717a 100644 (file)
@@ -695,3 +695,5 @@ permission_edit_own_issue_notes: Editácia vlastných poznámok úlohy
 setting_gravatar_enabled: Použitie uživateľských Gravatar ikon
 label_example: Example
 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."\r
+permission_edit_own_messages: Edit own messages\r
+permission_delete_won_messages: Delete own messages\r
index 54b1e70c6a3a6ba4421aa20b689e5ab7d7672777..1f555c41b2f9a6a33ae8752892a17ecddef6eda2 100644 (file)
@@ -691,3 +691,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index 76b6e6c3869e0a67f6bd94a60d6a1f2cf53a2f1f..e5547892c31114e22e6ebfccf411a21ff0f1bd36 100644 (file)
@@ -691,3 +691,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index fa471101f68aa6e3fd2fc6f3adb3c32c27a07025..1d2f4e6a531a0fa75f9468fe61d3bbedcc088649 100644 (file)
@@ -693,3 +693,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index 90d4d5f651546ff8722b54b03ac201b0790527bf..3646baa441ada738c979fdeda6687c73d0d268ad 100644 (file)
@@ -691,3 +691,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index a7f3f7347ee86c90e826fe9e95051533291e3554..55acd3a4be714905cd678f0a3695728984fc29b1 100644 (file)
@@ -692,3 +692,5 @@ permission_edit_own_issue_notes: Edit own notes
 setting_gravatar_enabled: Use Gravatar user icons
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index 81957a53cc802a690bb2c1a5e4cf124ee0617028..a0506c39cf7d7ca5273d86bf3a975750aa90c1bc 100644 (file)
@@ -691,3 +691,5 @@ permission_edit_time_entries: Edit time logs
 permission_edit_own_time_entries: Edit own time logs
 label_example: Example
 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."\r
+permission_edit_own_messages: Edit own messages\r
+permission_delete_won_messages: Delete own messages\r
index c99e10de3ea008f1cdeaa33966094f479948d585..e0a6ee9e883591b184fc356b4ab46123286fa115 100644 (file)
@@ -692,3 +692,5 @@ enumeration_issue_priorities: 項目優先權
 enumeration_doc_categories: 文件分類
 enumeration_activities: 活動 (時間追蹤)
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index 10fd1ac01d9c15237ad2c1ca3fefd70300e96d25..6da16683abc5f83126676c5758eec52dfcbcf0cf 100644 (file)
@@ -692,3 +692,5 @@ enumeration_doc_categories: 文档类别
 enumeration_activities: 活动(时间跟踪)
 label_example: Example
 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."
+permission_edit_own_messages: Edit own messages
+permission_delete_won_messages: Delete own messages
index b07d8e90cc87ee0bcb483ffd2c7ddd8eb4af3c88..19f0854e2826f81d6c2b7fcaf42c62ea62b0b368 100644 (file)
@@ -99,7 +99,9 @@ Redmine::AccessControl.map do |map|
     map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true
     map.permission :add_messages, {:messages => [:new, :reply, :quote]}
     map.permission :edit_messages, {:messages => :edit}, :require => :member
+    map.permission :edit_own_messages, {:messages => :edit}, :require => :loggedin
     map.permission :delete_messages, {:messages => :destroy}, :require => :member
+    map.permission :delete_own_messages, {:messages => :destroy}, :require => :loggedin
   end
 end
 
index 1c3b1f939d3d21705765f3f759ce4d52839baf93..b7cab56ca30b5923e5bae2ea343ef4a7dea7c66f 100644 (file)
@@ -65,6 +65,7 @@ module Redmine
                                                       :edit_wiki_pages,
                                                       :delete_wiki_pages,
                                                       :add_messages,
+                                                      :edit_own_messages,
                                                       :view_files,
                                                       :manage_files,
                                                       :browse_repository,
@@ -85,6 +86,7 @@ module Redmine
                                                     :view_wiki_pages,
                                                     :view_wiki_edits,
                                                     :add_messages,
+                                                    :edit_own_messages,
                                                     :view_files,
                                                     :browse_repository,
                                                     :view_changesets]
index f82f376c14323de3d9e3077e78f64f6fcc56549c..e578853d48e38f6ee3232cba3eee607a4e544a3a 100644 (file)
@@ -38,8 +38,8 @@ messages_004:
   updated_on: 2007-08-12 17:15:32 +02:00\r
   subject: Post 2\r
   id: 4\r
-  replies_count: 1\r
-  last_reply_id: 5\r
+  replies_count: 2\r
+  last_reply_id: 6\r
   content: "This is an other post"\r
   author_id: \r
   parent_id: \r
@@ -55,3 +55,14 @@ messages_005:
   author_id: 1\r
   parent_id: 4\r
   board_id: 1\r
+messages_006: \r
+  created_on: <%= 2.days.ago.to_date.to_s(:db) %>\r
+  updated_on: <%= 2.days.ago.to_date.to_s(:db) %>\r
+  subject: 'RE: post 2'\r
+  id: 6\r
+  replies_count: 0\r
+  last_reply_id: \r
+  content: "Another reply to the second post"\r
+  author_id: 3\r
+  parent_id: 4\r
+  board_id: 1\r
index 5bc6809d72f84f2d683f4c4144d8da1eae75f1bc..d8ae2c8197773b45863fb17b3a6ae3f8fe00bd3a 100644 (file)
@@ -80,6 +80,8 @@ roles_002:
     - :protect_wiki_pages\r
     - :delete_wiki_pages\r
     - :add_messages\r
+    - :edit_own_messages\r
+    - :delete_own_messages\r
     - :manage_boards\r
     - :view_files\r
     - :manage_files\r
index 6e8e8fb26ab6a5143196ad3be4d085c93e7cfd67..b907cfef327bb33fbac353e1fc840a9b8f18d419 100644 (file)
@@ -1,7 +1,7 @@
 require File.dirname(__FILE__) + '/../test_helper'
 
 class MessageTest < Test::Unit::TestCase
-  fixtures :projects, :boards, :messages, :users, :watchers
+  fixtures :projects, :roles, :members, :boards, :messages, :users, :watchers
 
   def setup
     @board = Board.find(1)
@@ -76,4 +76,22 @@ class MessageTest < Test::Unit::TestCase
     assert_equal topics_count, board.topics_count
     assert_equal messages_count - 1, board.messages_count
   end
+  
+  def test_editable_by
+    message = Message.find(6)
+    author = message.author
+    assert message.editable_by?(author)
+    
+    author.role_for_project(message.project).remove_permission!(:edit_own_messages)
+    assert !message.reload.editable_by?(author.reload)
+  end
+  
+  def test_destroyable_by
+    message = Message.find(6)
+    author = message.author
+    assert message.destroyable_by?(author)
+    
+    author.role_for_project(message.project).remove_permission!(:delete_own_messages)
+    assert !message.reload.destroyable_by?(author.reload)
+  end
 end