summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2021-05-29 07:30:54 +0000
committerGo MAEDA <maeda@farend.jp>2021-05-29 07:30:54 +0000
commit0b8c23f021834f0f03f799b789dcc690f59c84d4 (patch)
tree46f0dd712e398bc3fb09717585a3abeed70083de
parentf217037771b2ca84f695fbd02f14098933c4f3e1 (diff)
downloadredmine-0b8c23f021834f0f03f799b789dcc690f59c84d4.tar.gz
redmine-0b8c23f021834f0f03f799b789dcc690f59c84d4.zip
Ability to add watchers to Wiki pages (#7652).
Patch by Yuichi HARADA. git-svn-id: http://svn.redmine.org/redmine/trunk@21016 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/views/wiki/show.html.erb6
-rw-r--r--config/locales/en.yml4
-rw-r--r--lib/redmine.rb3
-rw-r--r--test/fixtures/roles.yml5
-rw-r--r--test/fixtures/watchers.yml4
-rw-r--r--test/functional/watchers_controller_test.rb56
-rw-r--r--test/functional/wiki_controller_test.rb27
7 files changed, 103 insertions, 2 deletions
diff --git a/app/views/wiki/show.html.erb b/app/views/wiki/show.html.erb
index a7104967d..6a0245809 100644
--- a/app/views/wiki/show.html.erb
+++ b/app/views/wiki/show.html.erb
@@ -100,6 +100,12 @@
<% content_for :sidebar do %>
<%= render :partial => 'sidebar' %>
+ <% if User.current.allowed_to?(:add_wiki_page_watchers, @project) ||
+ (@page.watchers.present? && User.current.allowed_to?(:view_wiki_page_watchers, @project)) %>
+ <div id="watchers">
+ <%= render :partial => 'watchers/watchers', :locals => {:watched => @page} %>
+ </div>
+ <% end %>
<% end %>
<% content_for :header_tags do %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 9d779a2fe..2ac0affb8 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -559,6 +559,9 @@ en:
permission_view_wiki_edits: View wiki history
permission_edit_wiki_pages: Edit wiki pages
permission_delete_wiki_pages_attachments: Delete attachments
+ permission_view_wiki_page_watchers: View wiki page watchers list
+ permission_add_wiki_page_watchers: Add wiki page watchers
+ permission_delete_wiki_page_watchers: Delete wiki page watchers
permission_protect_wiki_pages: Protect wiki pages
permission_manage_repository: Manage repository
permission_browse_repository: Browse repository
@@ -958,6 +961,7 @@ en:
label_generate_key: Generate a key
label_issue_watchers: Watchers
label_message_watchers: Watchers
+ label_wiki_page_watchers: Watchers
label_example: Example
label_display: Display
label_sort: Sort
diff --git a/lib/redmine.rb b/lib/redmine.rb
index cabbffe29..f6d83acd9 100644
--- a/lib/redmine.rb
+++ b/lib/redmine.rb
@@ -169,6 +169,9 @@ Redmine::AccessControl.map do |map|
map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member
map.permission :delete_wiki_pages, {:wiki => [:destroy, :destroy_version]}, :require => :member
map.permission :delete_wiki_pages_attachments, {}
+ map.permission :view_wiki_page_watchers, {}, :read => true
+ map.permission :add_wiki_page_watchers, {:watchers => [:new, :create, :autocomplete_for_user]}
+ map.permission :delete_wiki_page_watchers, {:watchers => :destroy}
map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member
map.permission :manage_wiki, {:wikis => [:edit, :destroy], :wiki => :rename}, :require => :member
end
diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml
index 61c324b1e..076d347ff 100644
--- a/test/fixtures/roles.yml
+++ b/test/fixtures/roles.yml
@@ -53,6 +53,9 @@ roles_001:
- :protect_wiki_pages
- :delete_wiki_pages
- :rename_wiki_pages
+ - :view_wiki_page_watchers
+ - :add_wiki_page_watchers
+ - :delete_wiki_page_watchers
- :manage_wiki
- :view_messages
- :add_messages
@@ -112,6 +115,7 @@ roles_002:
- :edit_wiki_pages
- :protect_wiki_pages
- :delete_wiki_pages
+ - :view_wiki_page_watchers
- :view_messages
- :add_messages
- :edit_own_messages
@@ -158,6 +162,7 @@ roles_003:
- :view_wiki_edits
- :edit_wiki_pages
- :delete_wiki_pages
+ - :view_wiki_page_watchers
- :view_messages
- :add_messages
- :view_message_watchers
diff --git a/test/fixtures/watchers.yml b/test/fixtures/watchers.yml
index fdcf5b382..038318ccc 100644
--- a/test/fixtures/watchers.yml
+++ b/test/fixtures/watchers.yml
@@ -11,3 +11,7 @@ watchers_003:
watchable_type: Issue
watchable_id: 2
user_id: 1
+watchers_004:
+ watchable_type: WikiPage
+ watchable_id: 1
+ user_id: 1
diff --git a/test/functional/watchers_controller_test.rb b/test/functional/watchers_controller_test.rb
index 21f31278d..0eac38012 100644
--- a/test/functional/watchers_controller_test.rb
+++ b/test/functional/watchers_controller_test.rb
@@ -22,7 +22,7 @@ require File.expand_path('../../test_helper', __FILE__)
class WatchersControllerTest < Redmine::ControllerTest
fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
:issues, :trackers, :projects_trackers, :issue_statuses, :enumerations, :watchers,
- :boards, :messages
+ :boards, :messages, :wikis, :wiki_pages
def setup
User.current = nil
@@ -163,6 +163,13 @@ class WatchersControllerTest < Redmine::ControllerTest
assert_match /ajax-modal/, response.body
end
+ def test_new_for_wiki_page
+ @request.session[:user_id] = 2
+ get :new, :params => {:object_type => 'wiki_page', :object_id => '1'}, :xhr => true
+ assert_response :success
+ assert_match /ajax-modal/, response.body
+ end
+
def test_new_with_multiple_objects
@request.session[:user_id] = 2
get :new, :params => {:object_type => 'issue', :object_id => ['1', '2']}, :xhr => true
@@ -238,6 +245,20 @@ class WatchersControllerTest < Redmine::ControllerTest
assert Message.find(1).watched_by?(User.find(4))
end
+ def test_create_for_wiki_page
+ @request.session[:user_id] = 2
+ assert_difference('Watcher.count') do
+ post :create, :params => {
+ :object_type => 'wiki_page', :object_id => '1',
+ :watcher => {:user_id => '4'}
+ }, :xhr => true
+ assert_response :success
+ assert_match /watchers/, response.body
+ assert_match /ajax-modal/, response.body
+ end
+ assert WikiPage.find(1).watched_by?(User.find(4))
+ end
+
def test_create_with_mutiple_users
@request.session[:user_id] = 2
assert_difference('Watcher.count', 3) do
@@ -272,6 +293,23 @@ class WatchersControllerTest < Redmine::ControllerTest
assert message.watched_by?(Group.find(10))
end
+ def test_create_for_wiki_page_with_mutiple_users
+ @request.session[:user_id] = 2
+ assert_difference('Watcher.count', 3) do
+ post :create, :params => {
+ :object_type => 'wiki_page', :object_id => '1',
+ :watcher => {:user_ids => ['4', '7', '10']}
+ }, :xhr => true
+ assert_response :success
+ assert_match /watchers/, response.body
+ assert_match /ajax-modal/, response.body
+ end
+ wiki_page = WikiPage.find(1)
+ assert wiki_page.watched_by?(User.find(4))
+ assert wiki_page.watched_by?(User.find(7))
+ assert wiki_page.watched_by?(Group.find(10))
+ end
+
def test_create_with_mutiple_objects
@request.session[:user_id] = 2
assert_difference('Watcher.count', 6) do
@@ -464,6 +502,22 @@ class WatchersControllerTest < Redmine::ControllerTest
assert !message.watched_by?(user)
end
+ def test_destroy_for_wiki_page
+ @request.session[:user_id] = 2
+ wiki_page = WikiPage.find(1)
+ user = User.find(1)
+ assert wiki_page.watched_by?(user)
+ assert_difference('Watcher.count', -1) do
+ delete :destroy, :params => {
+ :object_type => 'wiki_page', :object_id => '1', :user_id => '1'
+ }, :xhr => true
+ assert_response :success
+ assert_match /watchers/, response.body
+ end
+ wiki_page.reload
+ assert !wiki_page.watched_by?(user)
+ end
+
def test_destroy_locked_user
user = User.find(3)
user.lock!
diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb
index 032d3f30e..0ac5ff248 100644
--- a/test/functional/wiki_controller_test.rb
+++ b/test/functional/wiki_controller_test.rb
@@ -23,7 +23,7 @@ class WikiControllerTest < Redmine::ControllerTest
fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
:enabled_modules, :wikis, :wiki_pages, :wiki_contents,
:wiki_content_versions, :attachments,
- :issues, :issue_statuses, :trackers
+ :issues, :issue_statuses, :trackers, :watchers
def setup
User.current = nil
@@ -121,6 +121,31 @@ class WikiControllerTest < Redmine::ControllerTest
assert_select 'div#sidebar', :text => /Side bar content for test_show_with_sidebar/
end
+ def test_show_should_display_watchers
+ @request.session[:user_id] = 2
+ page = Project.find(1).wiki.find_page('Another_page')
+ page.add_watcher User.find(2)
+ page.add_watcher Group.find(10)
+ [['1', true], ['0', false]].each do |(gravatar_enabled, is_display_gravatar)|
+ with_settings :gravatar_enabled => gravatar_enabled do
+ get :show, :params => {:project_id => 1, :id => 'Another_page'}
+ end
+
+ assert_select 'div#watchers ul' do
+ assert_select 'li.user-2' do
+ assert_select 'img.gravatar[title=?]', 'John Smith', is_display_gravatar
+ assert_select 'a[href="/users/2"]'
+ assert_select 'a[class*=delete]'
+ end
+ assert_select 'li.user-10' do
+ assert_select 'img.gravatar[title=?]', 'A Team', is_display_gravatar
+ assert_select 'a[href="/users/10"]', false
+ assert_select 'a[class*=delete]'
+ end
+ end
+ end
+ end
+
def test_show_should_display_section_edit_links
@request.session[:user_id] = 2
get :show, :params => {:project_id => 1, :id => 'Page with sections'}