From 0255a61d2f4d1dba0a1904c50cab613c07e6129d Mon Sep 17 00:00:00 2001 From: wanglinchun Date: Thu, 5 Jun 2014 15:23:58 +0800 Subject: [PATCH] dfg --- app/helpers/application_helper.rb | 7 +++++++ app/views/contestnotifications/index.api.rsb | 14 ++++++++++++++ app/views/contestnotifications/show.html.erb | 14 +++++++------- 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 app/views/contestnotifications/index.api.rsb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fd1f6f162..f558f1e7a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -46,6 +46,10 @@ module ApplicationHelper def authorize_for(controller, action) User.current.allowed_to?({:controller => controller, :action => action}, @project) end + + def authorize_for_contest(controller, action) + User.current.allowed_to?({:controller => controller, :action => action}, @contest) + end # Display a link if user is authorized # @@ -57,6 +61,9 @@ module ApplicationHelper link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action]) end + def link_to_if_authorized_contest(name, options = {}, html_options = nil, *parameters_for_method_reference) + link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for_contest(options[:controller] || params[:controller], options[:action]) + end # Displays a link to user's account page if active def link_to_user(user, options={}) if user.is_a?(User) diff --git a/app/views/contestnotifications/index.api.rsb b/app/views/contestnotifications/index.api.rsb new file mode 100644 index 000000000..6509d2915 --- /dev/null +++ b/app/views/contestnotifications/index.api.rsb @@ -0,0 +1,14 @@ +api.array :contestnotifications, api_meta(:total_count => @contestnotifications_count, :offset => @offset, :limit => @limit) do + @contestnotificationss.each do |contestnotifications| + api.contestnotifications do + api.id contestnotifications.id + api.contest(:id => contestnotifications.contest_id, :name => contestnotifications.contest.name) unless contestnotifications.contest.nil? + api.author(:id => contestnotifications.author_id, :name => contestnotifications.author.name) unless contestnotifications.author.nil? + + api.title contestnotifications.title + api.summary contestnotifications.summary + api.description contestnotifications.description + api.created_at contestnotifications.created_at + end + end +end diff --git a/app/views/contestnotifications/show.html.erb b/app/views/contestnotifications/show.html.erb index bd4c8a4f8..ead40aef7 100644 --- a/app/views/contestnotifications/show.html.erb +++ b/app/views/contestnotifications/show.html.erb @@ -38,23 +38,23 @@
<%= watcher_link(@contestnotifications, User.current) %> <%= link_to(l(:button_edit), - edit_news_path(@news), + edit_contest_contestnotification_path(@contestnotifications), :class => 'icon icon-edit', :accesskey => accesskey(:edit), - :onclick => '$("#edit-news").show(); return false;') if User.current.allowed_to?(:manage_contestnotification, @contest) %> - <%= delete_link news_path(@contestnotifications) if User.current.allowed_to?(:manage_contestnotification, @contest) %> + :onclick => '$("#edit-contestnotifications").show(); return false;') if User.current.allowed_to?(:manage_contestnotifications, @contest) %> + <%= delete_link contest_contestnotification_path(@contestnotifications) if User.current.allowed_to?(:manage_contestnotifications, @contest) %>

<%=h @contestnotifications.title %>

-<% if authorize_for('contestnotifications', 'edit') %> -