0002-Ability-of-assign-watchers-to-Wiki-pages.patch

Go MAEDA, 2021-05-27 09:55

Download (9.46 KB)

View differences:

app/views/wiki/show.html.erb
100 100

  
101 101
<% content_for :sidebar do %>
102 102
  <%= render :partial => 'sidebar' %>
103
  <% if User.current.allowed_to?(:add_wiki_page_watchers, @project) ||
104
    (@page.watchers.present? && User.current.allowed_to?(:view_wiki_page_watchers, @project)) %>
105
    <div id="watchers">
106
      <%= render :partial => 'watchers/watchers', :locals => {:watched => @page} %>
107
    </div>
108
  <% end %>
103 109
<% end %>
104 110

  
105 111
<% content_for :header_tags do %>
config/locales/en.yml
559 559
  permission_view_wiki_edits: View wiki history
560 560
  permission_edit_wiki_pages: Edit wiki pages
561 561
  permission_delete_wiki_pages_attachments: Delete attachments
562
  permission_view_wiki_page_watchers: View wiki page watchers list
563
  permission_add_wiki_page_watchers: Add wiki page watchers
564
  permission_delete_wiki_page_watchers: Delete wiki page watchers
562 565
  permission_protect_wiki_pages: Protect wiki pages
563 566
  permission_manage_repository: Manage repository
564 567
  permission_browse_repository: Browse repository
......
958 961
  label_generate_key: Generate a key
959 962
  label_issue_watchers: Watchers
960 963
  label_message_watchers: Watchers
964
  label_wiki_page_watchers: Watchers
961 965
  label_example: Example
962 966
  label_display: Display
963 967
  label_sort: Sort
lib/redmine.rb
169 169
    map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member
170 170
    map.permission :delete_wiki_pages, {:wiki => [:destroy, :destroy_version]}, :require => :member
171 171
    map.permission :delete_wiki_pages_attachments, {}
172
    map.permission :view_wiki_page_watchers, {}, :read => true
173
    map.permission :add_wiki_page_watchers, {:watchers => [:new, :create, :autocomplete_for_user]}
174
    map.permission :delete_wiki_page_watchers, {:watchers => :destroy}
172 175
    map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member
173 176
    map.permission :manage_wiki, {:wikis => [:edit, :destroy], :wiki => :rename}, :require => :member
174 177
  end
test/fixtures/roles.yml
53 53
    - :protect_wiki_pages
54 54
    - :delete_wiki_pages
55 55
    - :rename_wiki_pages
56
    - :view_wiki_page_watchers
57
    - :add_wiki_page_watchers
58
    - :delete_wiki_page_watchers
56 59
    - :manage_wiki
57 60
    - :view_messages
58 61
    - :add_messages
......
112 115
    - :edit_wiki_pages
113 116
    - :protect_wiki_pages
114 117
    - :delete_wiki_pages
118
    - :view_wiki_page_watchers
115 119
    - :view_messages
116 120
    - :add_messages
117 121
    - :edit_own_messages
......
158 162
    - :view_wiki_edits
159 163
    - :edit_wiki_pages
160 164
    - :delete_wiki_pages
165
    - :view_wiki_page_watchers
161 166
    - :view_messages
162 167
    - :add_messages
163 168
    - :view_message_watchers
test/fixtures/watchers.yml
11 11
  watchable_type: Issue
12 12
  watchable_id: 2
13 13
  user_id: 1
14
watchers_004:
15
  watchable_type: WikiPage
16
  watchable_id: 1
17
  user_id: 1
test/functional/watchers_controller_test.rb
22 22
class WatchersControllerTest < Redmine::ControllerTest
23 23
  fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
24 24
           :issues, :trackers, :projects_trackers, :issue_statuses, :enumerations, :watchers,
25
           :boards, :messages
25
           :boards, :messages, :wikis, :wiki_pages
26 26

  
27 27
  def setup
28 28
    User.current = nil
......
163 163
    assert_match /ajax-modal/, response.body
164 164
  end
165 165

  
166
  def test_new_for_wiki_page
167
    @request.session[:user_id] = 2
168
    get :new, :params => {:object_type => 'wiki_page', :object_id => '1'}, :xhr => true
169
    assert_response :success
170
    assert_match /ajax-modal/, response.body
171
  end
172

  
166 173
  def test_new_with_multiple_objects
167 174
    @request.session[:user_id] = 2
168 175
    get :new, :params => {:object_type => 'issue', :object_id => ['1', '2']}, :xhr => true
......
238 245
    assert Message.find(1).watched_by?(User.find(4))
239 246
  end
240 247

  
248
  def test_create_for_wiki_page
249
    @request.session[:user_id] = 2
250
    assert_difference('Watcher.count') do
251
      post :create, :params => {
252
        :object_type => 'wiki_page', :object_id => '1',
253
        :watcher => {:user_id => '4'}
254
      }, :xhr => true
255
      assert_response :success
256
      assert_match /watchers/, response.body
257
      assert_match /ajax-modal/, response.body
258
    end
259
    assert WikiPage.find(1).watched_by?(User.find(4))
260
  end
261

  
241 262
  def test_create_with_mutiple_users
242 263
    @request.session[:user_id] = 2
243 264
    assert_difference('Watcher.count', 3) do
......
272 293
    assert message.watched_by?(Group.find(10))
273 294
  end
274 295

  
296
  def test_create_for_wiki_page_with_mutiple_users
297
    @request.session[:user_id] = 2
298
    assert_difference('Watcher.count', 3) do
299
      post :create, :params => {
300
        :object_type => 'wiki_page', :object_id => '1',
301
        :watcher => {:user_ids => ['4', '7', '10']}
302
      }, :xhr => true
303
      assert_response :success
304
      assert_match /watchers/, response.body
305
      assert_match /ajax-modal/, response.body
306
    end
307
    wiki_page = WikiPage.find(1)
308
    assert wiki_page.watched_by?(User.find(4))
309
    assert wiki_page.watched_by?(User.find(7))
310
    assert wiki_page.watched_by?(Group.find(10))
311
  end
312

  
275 313
  def test_create_with_mutiple_objects
276 314
    @request.session[:user_id] = 2
277 315
    assert_difference('Watcher.count', 6) do
......
464 502
    assert !message.watched_by?(user)
465 503
  end
466 504

  
505
  def test_destroy_for_wiki_page
506
    @request.session[:user_id] = 2
507
    wiki_page = WikiPage.find(1)
508
    user = User.find(1)
509
    assert wiki_page.watched_by?(user)
510
    assert_difference('Watcher.count', -1) do
511
      delete :destroy, :params => {
512
        :object_type => 'wiki_page', :object_id => '1', :user_id => '1'
513
      }, :xhr => true
514
      assert_response :success
515
      assert_match /watchers/, response.body
516
    end
517
    wiki_page.reload
518
    assert !wiki_page.watched_by?(user)
519
  end
520

  
467 521
  def test_destroy_locked_user
468 522
    user = User.find(3)
469 523
    user.lock!
test/functional/wiki_controller_test.rb
23 23
  fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
24 24
           :enabled_modules, :wikis, :wiki_pages, :wiki_contents,
25 25
           :wiki_content_versions, :attachments,
26
           :issues, :issue_statuses, :trackers
26
           :issues, :issue_statuses, :trackers, :watchers
27 27

  
28 28
  def setup
29 29
    User.current = nil
......
121 121
    assert_select 'div#sidebar', :text => /Side bar content for test_show_with_sidebar/
122 122
  end
123 123

  
124
  def test_show_should_display_watchers
125
    @request.session[:user_id] = 2
126
    page = Project.find(1).wiki.find_page('Another_page')
127
    page.add_watcher User.find(2)
128
    page.add_watcher Group.find(10)
129
    [['1', true], ['0', false]].each do |(gravatar_enabled, is_display_gravatar)|
130
      with_settings :gravatar_enabled => gravatar_enabled do
131
        get :show, :params => {:project_id => 1, :id => 'Another_page'}
132
      end
133

  
134
      assert_select 'div#watchers ul' do
135
        assert_select 'li.user-2' do
136
          assert_select 'img.gravatar[title=?]', 'John Smith', is_display_gravatar
137
          assert_select 'a[href="/users/2"]'
138
          assert_select 'a[class*=delete]'
139
        end
140
        assert_select 'li.user-10' do
141
          assert_select 'img.gravatar[title=?]', 'A Team', is_display_gravatar
142
          assert_select 'a[href="/users/10"]', false
143
          assert_select 'a[class*=delete]'
144
        end
145
      end
146
    end
147
  end
148

  
124 149
  def test_show_should_display_section_edit_links
125 150
    @request.session[:user_id] = 2
126 151
    get :show, :params => {:project_id => 1, :id => 'Page with sections'}
127
-