diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 109afe45..66ed61cf 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -17,7 +17,9 @@ class NewsController < ApplicationController layout 'base' - before_filter :find_project, :authorize, :except => :index + before_filter :find_news, :except => [:new, :index, :preview] + before_filter :find_project, :only => :new + before_filter :authorize, :except => [:index, :preview] before_filter :find_optional_project, :only => :index accept_key_auth :index @@ -36,6 +38,18 @@ class NewsController < ApplicationController def show end + def new + @news = News.new(:project => @project, :author => User.current) + if request.post? + @news.attributes = params[:news] + if @news.save + flash[:notice] = l(:notice_successful_create) + Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added') + redirect_to :controller => 'news', :action => 'index', :project_id => @project + end + end + end + def edit if request.post? and @news.update_attributes(params[:news]) flash[:notice] = l(:notice_successful_update) @@ -64,14 +78,25 @@ class NewsController < ApplicationController redirect_to :action => 'index', :project_id => @project end + def preview + @text = (params[:news] ? params[:news][:description] : nil) + render :partial => 'common/preview' + end + private - def find_project + def find_news @news = News.find(params[:id]) @project = @news.project rescue ActiveRecord::RecordNotFound render_404 end + def find_project + @project = Project.find(params[:project_id]) + rescue ActiveRecord::RecordNotFound + render_404 + end + def find_optional_project return true unless params[:project_id] @project = Project.find(params[:project_id]) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 30e7ef85..9560a451 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -259,19 +259,6 @@ class ProjectsController < ApplicationController render :layout => false if request.xhr? end - # Add a news to @project - def add_news - @news = News.new(:project => @project, :author => User.current) - if request.post? - @news.attributes = params[:news] - if @news.save - flash[:notice] = l(:notice_successful_create) - Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added') - redirect_to :controller => 'news', :action => 'index', :project_id => @project - end - end - end - def add_file if request.post? @version = @project.versions.find_by_id(params[:version_id]) diff --git a/app/views/news/edit.rhtml b/app/views/news/edit.rhtml index 5e015c4c..a7e5e6e3 100644 --- a/app/views/news/edit.rhtml +++ b/app/views/news/edit.rhtml @@ -1,6 +1,14 @@
<% unless @news.summary.empty? %><%=h @news.summary %>
<% end %>
diff --git a/app/views/projects/add_news.rhtml b/app/views/projects/add_news.rhtml
deleted file mode 100644
index a6ecd3da..00000000
--- a/app/views/projects/add_news.rhtml
+++ /dev/null
@@ -1,6 +0,0 @@
-<%=l(:label_news_new)%>
-
-<% labelled_tabular_form_for :news, @news, :url => { :action => "add_news" } do |f| %>
-<%= render :partial => 'news/form', :locals => { :f => f } %>
-<%= submit_tag l(:button_create) %>
-<% end %>
\ No newline at end of file
diff --git a/lib/redmine.rb b/lib/redmine.rb
index 92a1cef1..c4c55a93 100644
--- a/lib/redmine.rb
+++ b/lib/redmine.rb
@@ -51,7 +51,7 @@ Redmine::AccessControl.map do |map|
end
map.project_module :news do |map|
- map.permission :manage_news, {:projects => :add_news, :news => [:edit, :destroy, :destroy_comment]}, :require => :member
+ map.permission :manage_news, {:news => [:new, :edit, :destroy, :destroy_comment]}, :require => :member
map.permission :view_news, {:news => [:index, :show]}, :public => true
map.permission :comment_news, {:news => :add_comment}
end
diff --git a/test/functional/news_controller_test.rb b/test/functional/news_controller_test.rb
index 8a02345f..397e928f 100644
--- a/test/functional/news_controller_test.rb
+++ b/test/functional/news_controller_test.rb
@@ -45,4 +45,15 @@ class NewsControllerTest < Test::Unit::TestCase
assert_template 'index'
assert_not_nil assigns(:newss)
end
+
+ def test_preview
+ get :preview, :project_id => 1,
+ :news => {:title => '',
+ :description => 'News description',
+ :summary => ''}
+ assert_response :success
+ assert_template 'common/_preview'
+ assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' },
+ :content => /News description/
+ end
end