diff --git a/app/controllers/contestnotifications_controller.rb b/app/controllers/contestnotifications_controller.rb
index 47d85fe2b..0d05d6ca1 100644
--- a/app/controllers/contestnotifications_controller.rb
+++ b/app/controllers/contestnotifications_controller.rb
@@ -4,8 +4,8 @@ class ContestnotificationsController < ApplicationController
layout 'base_newcontest'
default_search_scope :contestnotifications
model_object Contestnotification
- before_filter :find_model_object, :except => [:new, :create, :index]
- before_filter :find_contest_from_association, :except => [:new, :create, :index]
+ # before_filter :find_model_object, :except => [:new, :create, :index]
+ # before_filter :find_contest_from_association, :except => [:new, :create, :index]
before_filter :find_contest_by_contest_id, :only => [:new, :create]
before_filter :find_contest
before_filter :find_author
@@ -14,6 +14,8 @@ class ContestnotificationsController < ApplicationController
accept_rss_auth :index
accept_api_auth :index
+ before_filter :access_edit_destroy, only: [:edit ,:update, :destroy]
+
def find_author
@user = @contest.author
render_404 if @user.nil?
@@ -93,7 +95,7 @@ class ContestnotificationsController < ApplicationController
# GET /contestnotifications/1/edit
def edit
- # @contestnotification = Contestnotification.find(params[:id])
+ @contestnotification = Contestnotification.find(params[:id])
end
# POST /contestnotifications
@@ -137,12 +139,13 @@ class ContestnotificationsController < ApplicationController
# format.json { render json: @contestnotification.errors, status: :unprocessable_entity }
# end
# end
+ @contestnotification = Contestnotification.find(params[:id])
@contestnotification.safe_attributes = params[:contestnotification]
@contestnotification.save_attachments(params[:attachments])
if @contestnotification.save
render_attachment_warning_if_needed(@contestnotification)
flash[:notice] = l(:notice_successful_update)
- redirect_to contest_contestnotification_path(@contestnotification)
+ redirect_to contest_contestnotification_path(@contestnotification.contest, @contestnotification)
else
render :action => 'edit'
end
@@ -172,4 +175,12 @@ class ContestnotificationsController < ApplicationController
render_404
end
+ def access_edit_destroy
+ if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?)
+ return true
+ else
+ render_403
+ end
+ end
+
end
diff --git a/app/controllers/previews_controller.rb b/app/controllers/previews_controller.rb
index 2ca2cef9e..579f8caa8 100644
--- a/app/controllers/previews_controller.rb
+++ b/app/controllers/previews_controller.rb
@@ -16,7 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class PreviewsController < ApplicationController
- before_filter :find_project, :find_attachments, :find_contest
+ before_filter :find_project, :find_attachments, :find_contest, except: [:contestnotification]
def issue
@issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
@@ -42,6 +42,12 @@ class PreviewsController < ApplicationController
render :partial => 'common/preview'
end
+ def contestnotification
+ @previewed = Contestnotification.find(params[:id])
+ @text = (params[:contestnotification] ? params[:contestnotification][:description] : nil)
+ render :partial => 'common/preview'
+ end
+
private
def find_project
diff --git a/app/views/contestnotifications/edit.html.erb b/app/views/contestnotifications/edit.html.erb
index f0b5fdfe9..7b91d922c 100644
--- a/app/views/contestnotifications/edit.html.erb
+++ b/app/views/contestnotifications/edit.html.erb
@@ -1,9 +1,9 @@
<%=l(:label_news)%>
-<%= labelled_form_for @contestnotifications, :html => { :id => 'contestnotifications-form', :multipart => true, :method => :put } do |f| %>
+<%= labelled_form_for @contestnotification, url: contest_contestnotification_path, :html => { :id => 'contestnotifications-form', :multipart => true, :method => :put } do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
-<%= preview_link preview_contestnotifications_path(:project_id => @contest, :id => @contestnotifications), 'contestnotifications-form' %>
+<%= preview_link preview_contestnotifications_path(id: @contestnotification), 'contestnotifications-form' %>
<% end %>
diff --git a/app/views/contestnotifications/index.html.erb b/app/views/contestnotifications/index.html.erb
index c71c9703d..e05abbdc8 100644
--- a/app/views/contestnotifications/index.html.erb
+++ b/app/views/contestnotifications/index.html.erb
@@ -42,7 +42,10 @@
<%= link_to_user(contestnotifications.author) if contestnotifications.respond_to?(:author) %>
<%= l(:label_project_notice) %><%= link_to h(contestnotifications.title), contest_contestnotification_path(@contest, contestnotifications) %>
- <%= delete_link contest_contestnotification_path(@contest, contestnotifications) if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?) %>
+
+ <%= link_to l(:button_edit), edit_contest_contestnotification_path(@contest, contestnotifications) if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?) %>
+ <%= delete_link contest_contestnotification_path(@contest, contestnotifications) if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?) %>
+
|
diff --git a/app/views/contestnotifications/show.html.erb b/app/views/contestnotifications/show.html.erb
index d2c3ff13f..152d0d02a 100644
--- a/app/views/contestnotifications/show.html.erb
+++ b/app/views/contestnotifications/show.html.erb
@@ -1,10 +1,10 @@
- <%#= link_to(l(:button_edit),
+ <%= link_to(l(:button_edit),
edit_contest_contestnotification_path(@contest, @contestnotification),
:class => 'icon icon-edit',
:accesskey => accesskey(:edit),
- :onclick => '$("#edit-contestnotifications").show(); return true;') if User.current %>
+ :onclick => '$("#edit-contestnotifications").show(); return true;') if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?)%>
<%= delete_link contest_contestnotification_path(@contest, @contestnotification) if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?) %>
diff --git a/config/routes.rb b/config/routes.rb
index 3937a2e20..ce75eafd7 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -73,11 +73,11 @@ RedmineApp::Application.routes.draw do
#resources :contestnotifications, :only => [:index, :show, :edit, :update, :destroy]
# match '/contestnotifications/:id/notificationcomments', :to => 'notificationcomments#create', :via => :post
# match '/contestnotifications/:id/notificationcomments/:notificationcomment_id', :to => 'notificationcomments#destroy', :via => :delete
- # match '/contestnotifications/preview', :controller => 'previews', :action => 'contestnotifications', :as => 'preview_contestnotifications', :via => [:get, :post, :put]
+ match '/contestnotifications/preview', :controller => 'previews', :action => 'contestnotification', :as => 'preview_contestnotifications', :via => [:get, :post, :put]
## new added by linchun #新竞赛相关
resources :contests, only: [:index] do
resources :contestnotifications do
- get 'preview', on: :collection
+ # get 'preview', on: :collection
resources :notificationcomments
end