diff --git a/app/views/news/show.html.erb b/app/views/news/show.html.erb index 95d6fe265..b884c3095 100644 --- a/app/views/news/show.html.erb +++ b/app/views/news/show.html.erb @@ -69,3 +69,10 @@ <% content_for :header_tags do %> <%= stylesheet_link_tag 'scm' %> <% end %> + +<% if User.current.allowed_to?(:add_news_watchers, @project) || + (@news.watchers.present? && User.current.allowed_to?(:view_news_watchers, @project)) %> +<% content_for :sidebar do %> +
<%= render :partial => 'watchers/watchers', :locals => {:watched => @news} %>
+<% end %> +<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 9d779a2fe..f00335071 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -546,6 +546,9 @@ en: permission_view_news: View news permission_manage_news: Manage news permission_comment_news: Comment news + permission_view_news_watchers: View news watchers list + permission_add_news_watchers: Add news watchers + permission_delete_news_watchers: Delete news watchers permission_view_documents: View documents permission_add_documents: Add documents permission_edit_documents: Edit documents @@ -958,6 +961,7 @@ en: label_generate_key: Generate a key label_issue_watchers: Watchers label_message_watchers: Watchers + label_news_watchers: Watchers label_example: Example label_display: Display label_sort: Sort diff --git a/lib/redmine.rb b/lib/redmine.rb index ee9aece1a..bb36a6f81 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -147,6 +147,9 @@ Redmine::AccessControl.map do |map| map.permission :view_news, {:news => [:index, :show]}, :read => true map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy], :comments => [:destroy], :attachments => :upload}, :require => :member map.permission :comment_news, {:comments => :create} + map.permission :view_news_watchers, {}, :read => true + map.permission :add_news_watchers, {:watchers => [:new, :create, :autocomplete_for_user]} + map.permission :delete_news_watchers, {:watchers => :destroy} end map.project_module :documents do |map| diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml index 61c324b1e..ea348d3ed 100644 --- a/test/fixtures/roles.yml +++ b/test/fixtures/roles.yml @@ -41,6 +41,9 @@ roles_001: - :view_news - :manage_news - :comment_news + - :view_news_watchers + - :add_news_watchers + - :delete_news_watchers - :view_documents - :add_documents - :edit_documents @@ -103,6 +106,7 @@ roles_002: - :view_news - :manage_news - :comment_news + - :view_news_watchers - :view_documents - :add_documents - :edit_documents @@ -150,6 +154,7 @@ roles_003: - :view_news - :manage_news - :comment_news + - :view_news_watchers - :view_documents - :add_documents - :edit_documents diff --git a/test/fixtures/watchers.yml b/test/fixtures/watchers.yml index 759ab51cc..05ea8aa84 100644 --- a/test/fixtures/watchers.yml +++ b/test/fixtures/watchers.yml @@ -1,13 +1,17 @@ ---- -watchers_001: +--- +watchers_001: watchable_type: Issue watchable_id: 2 user_id: 3 -watchers_002: +watchers_002: watchable_type: Message watchable_id: 1 user_id: 1 -watchers_003: +watchers_003: watchable_type: Issue watchable_id: 2 user_id: 1 +watchers_004: + watchable_type: News + watchable_id: 1 + user_id: 1 diff --git a/test/functional/news_controller_test.rb b/test/functional/news_controller_test.rb index 4dd46c8a7..31134cd71 100644 --- a/test/functional/news_controller_test.rb +++ b/test/functional/news_controller_test.rb @@ -22,7 +22,7 @@ require File.expand_path('../../test_helper', __FILE__) class NewsControllerTest < Redmine::ControllerTest fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :enabled_modules, :news, :comments, - :attachments, :user_preferences + :attachments, :user_preferences, :watchers def setup User.current = nil @@ -82,6 +82,31 @@ class NewsControllerTest < Redmine::ControllerTest assert_equal ["This is an other comment", "my first comment"], comments end + def test_show_should_display_watchers + @request.session[:user_id] = 2 + news = News.find(1) + news.add_watcher User.find(2) + news.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 => {:id => 1}) + 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_not_found get(:show, :params => {:id => 999}) assert_response 404 diff --git a/test/functional/watchers_controller_test.rb b/test/functional/watchers_controller_test.rb index 21f31278d..d42807be9 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, :news def setup User.current = nil @@ -163,6 +163,13 @@ class WatchersControllerTest < Redmine::ControllerTest assert_match /ajax-modal/, response.body end + def test_new_for_news + @request.session[:user_id] = 2 + get :new, :params => {:object_type => 'news', :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_news + @request.session[:user_id] = 2 + assert_difference('Watcher.count') do + post :create, :params => { + :object_type => 'news', :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 News.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_news_with_mutiple_users + @request.session[:user_id] = 2 + assert_difference('Watcher.count', 3) do + post :create, :params => { + :object_type => 'news', :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 + news = News.find(1) + assert news.watched_by?(User.find(4)) + assert news.watched_by?(User.find(7)) + assert news.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_news + @request.session[:user_id] = 2 + news = News.find(1) + user = User.find(1) + assert news.watched_by?(user) + assert_difference('Watcher.count', -1) do + delete :destroy, :params => { + :object_type => 'news', :object_id => '1', :user_id => '1' + }, :xhr => true + assert_response :success + assert_match /watchers/, response.body + end + news.reload + assert !news.watched_by?(user) + end + def test_destroy_locked_user user = User.find(3) user.lock!