@@ -17,8 +17,22 | |||||
17 |
|
17 | |||
18 | class NewsController < ApplicationController |
|
18 | class NewsController < ApplicationController | |
19 | layout 'base' |
|
19 | layout 'base' | |
20 | before_filter :find_project, :authorize |
|
20 | before_filter :find_project, :authorize, :except => :index | |
21 |
|
21 | before_filter :find_optional_project, :only => :index | ||
|
22 | accept_key_auth :index | |||
|
23 | ||||
|
24 | def index | |||
|
25 | @news_pages, @newss = paginate :news, | |||
|
26 | :per_page => 10, | |||
|
27 | :conditions => (@project ? {:project_id => @project.id} : Project.visible_by(User.current)), | |||
|
28 | :include => [:author, :project], | |||
|
29 | :order => "#{News.table_name}.created_on DESC" | |||
|
30 | respond_to do |format| | |||
|
31 | format.html { render :layout => false if request.xhr? } | |||
|
32 | format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") } | |||
|
33 | end | |||
|
34 | end | |||
|
35 | ||||
22 | def show |
|
36 | def show | |
23 | end |
|
37 | end | |
24 |
|
38 | |||
@@ -47,7 +61,7 class NewsController < ApplicationController | |||||
47 |
|
61 | |||
48 | def destroy |
|
62 | def destroy | |
49 | @news.destroy |
|
63 | @news.destroy | |
50 |
redirect_to |
|
64 | redirect_to :action => 'index', :project_id => @project | |
51 | end |
|
65 | end | |
52 |
|
66 | |||
53 | private |
|
67 | private | |
@@ -56,5 +70,13 private | |||||
56 | @project = @news.project |
|
70 | @project = @news.project | |
57 | rescue ActiveRecord::RecordNotFound |
|
71 | rescue ActiveRecord::RecordNotFound | |
58 | render_404 |
|
72 | render_404 | |
59 |
end |
|
73 | end | |
|
74 | ||||
|
75 | def find_optional_project | |||
|
76 | return true unless params[:project_id] | |||
|
77 | @project = Project.find(params[:project_id]) | |||
|
78 | authorize | |||
|
79 | rescue ActiveRecord::RecordNotFound | |||
|
80 | render_404 | |||
|
81 | end | |||
60 | end |
|
82 | end |
@@ -330,21 +330,11 class ProjectsController < ApplicationController | |||||
330 | if @news.save |
|
330 | if @news.save | |
331 | flash[:notice] = l(:notice_successful_create) |
|
331 | flash[:notice] = l(:notice_successful_create) | |
332 | Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added') |
|
332 | Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added') | |
333 |
redirect_to :action => ' |
|
333 | redirect_to :controller => 'news', :action => 'index', :project_id => @project | |
334 | end |
|
334 | end | |
335 | end |
|
335 | end | |
336 | end |
|
336 | end | |
337 |
|
337 | |||
338 | # Show news list of @project |
|
|||
339 | def list_news |
|
|||
340 | @news_pages, @newss = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC" |
|
|||
341 |
|
||||
342 | respond_to do |format| |
|
|||
343 | format.html { render :layout => false if request.xhr? } |
|
|||
344 | format.atom { render_feed(@newss, :title => "#{@project.name}: #{l(:label_news_plural)}") } |
|
|||
345 | end |
|
|||
346 | end |
|
|||
347 |
|
||||
348 | def add_file |
|
338 | def add_file | |
349 | if request.post? |
|
339 | if request.post? | |
350 | @version = @project.versions.find_by_id(params[:version_id]) |
|
340 | @version = @project.versions.find_by_id(params[:version_id]) |
@@ -1,17 +1,17 | |||||
1 | <div class="contextual"> |
|
1 | <div class="contextual"> | |
2 |
<%= link_to_if_authorized |
|
2 | <%= link_to_if_authorized(l(:label_news_new), | |
3 | {:controller => 'projects', :action => 'add_news', :id => @project}, |
|
3 | {:controller => 'projects', :action => 'add_news', :id => @project}, | |
4 | :class => 'icon icon-add', |
|
4 | :class => 'icon icon-add', | |
5 | :onclick => 'Element.show("add-news"); return false;' %> |
|
5 | :onclick => 'Element.show("add-news"); return false;') if @project %> | |
6 | </div> |
|
6 | </div> | |
7 |
|
7 | |||
8 | <div id="add-news" style="display:none;"> |
|
8 | <div id="add-news" style="display:none;"> | |
9 | <h2><%=l(:label_news_new)%></h2> |
|
9 | <h2><%=l(:label_news_new)%></h2> | |
10 | <% labelled_tabular_form_for :news, @news, :url => { :action => "add_news", :id => @project } do |f| %> |
|
10 | <% labelled_tabular_form_for :news, @news, :url => { :controller => 'projects', :action => "add_news", :id => @project } do |f| %> | |
11 | <%= render :partial => 'news/form', :locals => { :f => f } %> |
|
11 | <%= render :partial => 'news/form', :locals => { :f => f } %> | |
12 | <%= submit_tag l(:button_create) %> |
|
12 | <%= submit_tag l(:button_create) %> | |
13 | <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-news")' %> |
|
13 | <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-news")' %> | |
14 | <% end %> |
|
14 | <% end if @project %> | |
15 | </div> |
|
15 | </div> | |
16 |
|
16 | |||
17 | <h2><%=l(:label_news_plural)%></h2> |
|
17 | <h2><%=l(:label_news_plural)%></h2> | |
@@ -20,7 +20,8 | |||||
20 | <p class="nodata"><%= l(:label_no_data) %></p> |
|
20 | <p class="nodata"><%= l(:label_no_data) %></p> | |
21 | <% else %> |
|
21 | <% else %> | |
22 | <% @newss.each do |news| %> |
|
22 | <% @newss.each do |news| %> | |
23 |
<h3><%= link_to |
|
23 | <h3><%= link_to(h(news.project.name), :controller => 'projects', :action => 'show', :id => news.project) + ': ' unless news.project == @project %> | |
|
24 | <%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %> | |||
24 | <%= "(#{news.comments_count} #{lwr(:label_comment, news.comments_count).downcase})" if news.comments_count > 0 %></h3> |
|
25 | <%= "(#{news.comments_count} #{lwr(:label_comment, news.comments_count).downcase})" if news.comments_count > 0 %></h3> | |
25 | <p class="author"><%= authoring news.created_on, news.author %></p> |
|
26 | <p class="author"><%= authoring news.created_on, news.author %></p> | |
26 | <%= textilizable(news.description) %> |
|
27 | <%= textilizable(news.description) %> |
@@ -46,11 +46,11 | |||||
46 | </div> |
|
46 | </div> | |
47 | <% end %> |
|
47 | <% end %> | |
48 |
|
48 | |||
49 |
<% if @news.any? && authorize_for(' |
|
49 | <% if @news.any? && authorize_for('news', 'index') %> | |
50 | <div class="box"> |
|
50 | <div class="box"> | |
51 | <h3><%=l(:label_news_latest)%></h3> |
|
51 | <h3><%=l(:label_news_latest)%></h3> | |
52 | <%= render :partial => 'news/news', :collection => @news %> |
|
52 | <%= render :partial => 'news/news', :collection => @news %> | |
53 |
<p><%= link_to l(:label_news_view_all), :controller => ' |
|
53 | <p><%= link_to l(:label_news_view_all), :controller => 'news', :action => 'index', :project_id => @project %></p> | |
54 | </div> |
|
54 | </div> | |
55 | <% end %> |
|
55 | <% end %> | |
56 | </div> |
|
56 | </div> |
@@ -2,10 +2,13 | |||||
2 |
|
2 | |||
3 | <div class="splitcontentleft"> |
|
3 | <div class="splitcontentleft"> | |
4 | <%= textilizable Setting.welcome_text %> |
|
4 | <%= textilizable Setting.welcome_text %> | |
|
5 | <% if @news.any? %> | |||
5 | <div class="box"> |
|
6 | <div class="box"> | |
6 | <h3><%=l(:label_news_latest)%></h3> |
|
7 | <h3><%=l(:label_news_latest)%></h3> | |
7 | <%= render :partial => 'news/news', :collection => @news %> |
|
8 | <%= render :partial => 'news/news', :collection => @news %> | |
8 | </div> |
|
9 | <%= link_to l(:label_issue_view_all), :controller => 'news' %> | |
|
10 | </div> | |||
|
11 | <% end %> | |||
9 | </div> |
|
12 | </div> | |
10 |
|
13 | |||
11 | <div class="splitcontentright"> |
|
14 | <div class="splitcontentright"> |
@@ -15,6 +15,7 ActionController::Routing::Routes.draw do |map| | |||||
15 |
|
15 | |||
16 | map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations' |
|
16 | map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations' | |
17 | map.connect 'projects/:project_id/issues/:action', :controller => 'issues' |
|
17 | map.connect 'projects/:project_id/issues/:action', :controller => 'issues' | |
|
18 | map.connect 'projects/:project_id/news/:action', :controller => 'news' | |||
18 | map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards' |
|
19 | map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards' | |
19 | map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages' |
|
20 | map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages' | |
20 |
|
21 |
@@ -52,7 +52,7 Redmine::AccessControl.map do |map| | |||||
52 |
|
52 | |||
53 | map.project_module :news do |map| |
|
53 | map.project_module :news do |map| | |
54 | map.permission :manage_news, {:projects => :add_news, :news => [:edit, :destroy, :destroy_comment]}, :require => :member |
|
54 | map.permission :manage_news, {:projects => :add_news, :news => [:edit, :destroy, :destroy_comment]}, :require => :member | |
55 |
map.permission :view_news, { |
|
55 | map.permission :view_news, {:news => [:index, :show]}, :public => true | |
56 | map.permission :comment_news, {:news => :add_comment}, :require => :loggedin |
|
56 | map.permission :comment_news, {:news => :add_comment}, :require => :loggedin | |
57 | end |
|
57 | end | |
58 |
|
58 | |||
@@ -93,7 +93,7 Redmine::MenuManager.map :project_menu do |menu| | |||||
93 | menu.push :label_activity, :controller => 'projects', :action => 'activity' |
|
93 | menu.push :label_activity, :controller => 'projects', :action => 'activity' | |
94 | menu.push :label_roadmap, :controller => 'projects', :action => 'roadmap' |
|
94 | menu.push :label_roadmap, :controller => 'projects', :action => 'roadmap' | |
95 | menu.push :label_issue_plural, { :controller => 'issues', :action => 'index' }, :param => :project_id |
|
95 | menu.push :label_issue_plural, { :controller => 'issues', :action => 'index' }, :param => :project_id | |
96 |
menu.push :label_news_plural, :controller => ' |
|
96 | menu.push :label_news_plural, { :controller => 'news', :action => 'index' }, :param => :project_id | |
97 | menu.push :label_document_plural, :controller => 'projects', :action => 'list_documents' |
|
97 | menu.push :label_document_plural, :controller => 'projects', :action => 'list_documents' | |
98 | menu.push :label_wiki, { :controller => 'wiki', :action => 'index', :page => nil }, :if => Proc.new { |p| p.wiki && !p.wiki.new_record? } |
|
98 | menu.push :label_wiki, { :controller => 'wiki', :action => 'index', :page => nil }, :if => Proc.new { |p| p.wiki && !p.wiki.new_record? } | |
99 | menu.push :label_board_plural, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, :if => Proc.new { |p| p.boards.any? } |
|
99 | menu.push :label_board_plural, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, :if => Proc.new { |p| p.boards.any? } |
@@ -16,51 +16,33 | |||||
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 |
require ' |
|
19 | require 'news_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 |
class |
|
22 | class NewsController; def rescue_action(e) raise e end; end | |
23 |
|
||||
24 | class FeedsControllerTest < Test::Unit::TestCase |
|
|||
25 | fixtures :projects, :users, :members, :roles |
|
|||
26 |
|
23 | |||
|
24 | class NewsControllerTest < Test::Unit::TestCase | |||
|
25 | fixtures :projects, :users, :roles, :members, :enabled_modules | |||
|
26 | ||||
27 | def setup |
|
27 | def setup | |
28 |
@controller = |
|
28 | @controller = NewsController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | end |
|
31 | User.current = nil | |
32 |
|
||||
33 | def test_news |
|
|||
34 | get :news |
|
|||
35 | assert_response :success |
|
|||
36 | assert_template 'news' |
|
|||
37 | assert_not_nil assigns(:news) |
|
|||
38 | end |
|
|||
39 |
|
||||
40 | def test_issues |
|
|||
41 | get :issues |
|
|||
42 | assert_response :success |
|
|||
43 | assert_template 'issues' |
|
|||
44 | assert_not_nil assigns(:issues) |
|
|||
45 | end |
|
32 | end | |
46 |
|
33 | |||
47 |
def test_ |
|
34 | def test_index | |
48 |
get : |
|
35 | get :index | |
49 | assert_response :success |
|
36 | assert_response :success | |
50 |
assert_template ' |
|
37 | assert_template 'index' | |
51 |
assert_not_nil assigns(: |
|
38 | assert_not_nil assigns(:newss) | |
52 | end |
|
39 | assert_nil assigns(:project) | |
53 |
|
||||
54 | def test_project_privacy |
|
|||
55 | get :news, :project_id => 2 |
|
|||
56 | assert_response 403 |
|
|||
57 | end |
|
40 | end | |
58 |
|
41 | |||
59 | def test_rss_key |
|
42 | def test_index_with_project | |
60 | user = User.find(2) |
|
43 | get :index, :project_id => 1 | |
61 | key = user.rss_key |
|
|||
62 |
|
||||
63 | get :news, :project_id => 2, :key => key |
|
|||
64 | assert_response :success |
|
44 | assert_response :success | |
|
45 | assert_template 'index' | |||
|
46 | assert_not_nil assigns(:newss) | |||
65 | end |
|
47 | end | |
66 | end |
|
48 | end |
@@ -65,13 +65,6 class ProjectsControllerTest < Test::Unit::TestCase | |||||
65 | # check that the issues were updated |
|
65 | # check that the issues were updated | |
66 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} |
|
66 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} | |
67 | assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes |
|
67 | assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes | |
68 | end |
|
|||
69 |
|
||||
70 | def test_list_news |
|
|||
71 | get :list_news, :id => 1 |
|
|||
72 | assert_response :success |
|
|||
73 | assert_template 'list_news' |
|
|||
74 | assert_not_nil assigns(:newss) |
|
|||
75 | end |
|
68 | end | |
76 |
|
69 | |||
77 | def test_list_files |
|
70 | def test_list_files |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now