Feature #33016 » 33016.patch
app/views/news/show.html.erb | ||
---|---|---|
69 | 69 |
<% content_for :header_tags do %> |
70 | 70 |
<%= stylesheet_link_tag 'scm' %> |
71 | 71 |
<% end %> |
72 | ||
73 |
<% if User.current.allowed_to?(:add_news_watchers, @project) || |
|
74 |
(@news.watchers.present? && User.current.allowed_to?(:view_news_watchers, @project)) %> |
|
75 |
<% content_for :sidebar do %> |
|
76 |
<div id="watchers"><%= render :partial => 'watchers/watchers', :locals => {:watched => @news} %></div> |
|
77 |
<% end %> |
|
78 |
<% end %> |
config/locales/en.yml | ||
---|---|---|
546 | 546 |
permission_view_news: View news |
547 | 547 |
permission_manage_news: Manage news |
548 | 548 |
permission_comment_news: Comment news |
549 |
permission_view_news_watchers: View news watchers list |
|
550 |
permission_add_news_watchers: Add news watchers |
|
551 |
permission_delete_news_watchers: Delete news watchers |
|
549 | 552 |
permission_view_documents: View documents |
550 | 553 |
permission_add_documents: Add documents |
551 | 554 |
permission_edit_documents: Edit documents |
... | ... | |
958 | 961 |
label_generate_key: Generate a key |
959 | 962 |
label_issue_watchers: Watchers |
960 | 963 |
label_message_watchers: Watchers |
964 |
label_news_watchers: Watchers |
|
961 | 965 |
label_example: Example |
962 | 966 |
label_display: Display |
963 | 967 |
label_sort: Sort |
lib/redmine.rb | ||
---|---|---|
147 | 147 |
map.permission :view_news, {:news => [:index, :show]}, :read => true |
148 | 148 |
map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy], :comments => [:destroy], :attachments => :upload}, :require => :member |
149 | 149 |
map.permission :comment_news, {:comments => :create} |
150 |
map.permission :view_news_watchers, {}, :read => true |
|
151 |
map.permission :add_news_watchers, {:watchers => [:new, :create, :autocomplete_for_user]} |
|
152 |
map.permission :delete_news_watchers, {:watchers => :destroy} |
|
150 | 153 |
end |
151 | 154 | |
152 | 155 |
map.project_module :documents do |map| |
test/fixtures/roles.yml | ||
---|---|---|
41 | 41 |
- :view_news |
42 | 42 |
- :manage_news |
43 | 43 |
- :comment_news |
44 |
- :view_news_watchers |
|
45 |
- :add_news_watchers |
|
46 |
- :delete_news_watchers |
|
44 | 47 |
- :view_documents |
45 | 48 |
- :add_documents |
46 | 49 |
- :edit_documents |
... | ... | |
103 | 106 |
- :view_news |
104 | 107 |
- :manage_news |
105 | 108 |
- :comment_news |
109 |
- :view_news_watchers |
|
106 | 110 |
- :view_documents |
107 | 111 |
- :add_documents |
108 | 112 |
- :edit_documents |
... | ... | |
150 | 154 |
- :view_news |
151 | 155 |
- :manage_news |
152 | 156 |
- :comment_news |
157 |
- :view_news_watchers |
|
153 | 158 |
- :view_documents |
154 | 159 |
- :add_documents |
155 | 160 |
- :edit_documents |
test/fixtures/watchers.yml | ||
---|---|---|
1 |
---
|
|
2 |
watchers_001:
|
|
1 |
--- |
|
2 |
watchers_001: |
|
3 | 3 |
watchable_type: Issue |
4 | 4 |
watchable_id: 2 |
5 | 5 |
user_id: 3 |
6 |
watchers_002:
|
|
6 |
watchers_002: |
|
7 | 7 |
watchable_type: Message |
8 | 8 |
watchable_id: 1 |
9 | 9 |
user_id: 1 |
10 |
watchers_003:
|
|
10 |
watchers_003: |
|
11 | 11 |
watchable_type: Issue |
12 | 12 |
watchable_id: 2 |
13 | 13 |
user_id: 1 |
14 |
watchers_004: |
|
15 |
watchable_type: News |
|
16 |
watchable_id: 1 |
|
17 |
user_id: 1 |
test/functional/news_controller_test.rb | ||
---|---|---|
22 | 22 |
class NewsControllerTest < Redmine::ControllerTest |
23 | 23 |
fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, |
24 | 24 |
:enabled_modules, :news, :comments, |
25 |
:attachments, :user_preferences |
|
25 |
:attachments, :user_preferences, :watchers
|
|
26 | 26 | |
27 | 27 |
def setup |
28 | 28 |
User.current = nil |
... | ... | |
82 | 82 |
assert_equal ["This is an other comment", "my first comment"], comments |
83 | 83 |
end |
84 | 84 | |
85 |
def test_show_should_display_watchers |
|
86 |
@request.session[:user_id] = 2 |
|
87 |
news = News.find(1) |
|
88 |
news.add_watcher User.find(2) |
|
89 |
news.add_watcher Group.find(10) |
|
90 |
[['1', true], ['0', false]].each do |(gravatar_enabled, is_display_gravatar)| |
|
91 |
with_settings :gravatar_enabled => gravatar_enabled do |
|
92 |
get(:show, :params => {:id => 1}) |
|
93 |
end |
|
94 | ||
95 |
assert_select 'div#watchers ul' do |
|
96 |
assert_select 'li.user-2' do |
|
97 |
assert_select 'img.gravatar[title=?]', 'John Smith', is_display_gravatar |
|
98 |
assert_select 'a[href="/users/2"]' |
|
99 |
assert_select 'a[class*=delete]' |
|
100 |
end |
|
101 |
assert_select 'li.user-10' do |
|
102 |
assert_select 'img.gravatar[title=?]', 'A Team', is_display_gravatar |
|
103 |
assert_select 'a[href="/users/10"]', false |
|
104 |
assert_select 'a[class*=delete]' |
|
105 |
end |
|
106 |
end |
|
107 |
end |
|
108 |
end |
|
109 | ||
85 | 110 |
def test_show_not_found |
86 | 111 |
get(:show, :params => {:id => 999}) |
87 | 112 |
assert_response 404 |
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, :news
|
|
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_news |
|
167 |
@request.session[:user_id] = 2 |
|
168 |
get :new, :params => {:object_type => 'news', :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_news |
|
249 |
@request.session[:user_id] = 2 |
|
250 |
assert_difference('Watcher.count') do |
|
251 |
post :create, :params => { |
|
252 |
:object_type => 'news', :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 News.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_news_with_mutiple_users |
|
297 |
@request.session[:user_id] = 2 |
|
298 |
assert_difference('Watcher.count', 3) do |
|
299 |
post :create, :params => { |
|
300 |
:object_type => 'news', :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 |
news = News.find(1) |
|
308 |
assert news.watched_by?(User.find(4)) |
|
309 |
assert news.watched_by?(User.find(7)) |
|
310 |
assert news.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_news |
|
506 |
@request.session[:user_id] = 2 |
|
507 |
news = News.find(1) |
|
508 |
user = User.find(1) |
|
509 |
assert news.watched_by?(user) |
|
510 |
assert_difference('Watcher.count', -1) do |
|
511 |
delete :destroy, :params => { |
|
512 |
:object_type => 'news', :object_id => '1', :user_id => '1' |
|
513 |
}, :xhr => true |
|
514 |
assert_response :success |
|
515 |
assert_match /watchers/, response.body |
|
516 |
end |
|
517 |
news.reload |
|
518 |
assert !news.watched_by?(user) |
|
519 |
end |
|
520 | ||
467 | 521 |
def test_destroy_locked_user |
468 | 522 |
user = User.find(3) |
469 | 523 |
user.lock! |
- « Previous
- 1
- 2
- 3
- Next »