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