diff --git a/Gemfile.lock b/Gemfile.lock index 40caae261..42cb62272 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,7 +75,7 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) - rake (10.1.0) + rake (10.0.4) rdoc (3.12.2) json (~> 1.4) ruby-openid (2.1.8) diff --git a/app/controllers/softapplications_controller.rb b/app/controllers/softapplications_controller.rb index 9f14aa118..9163f5473 100644 --- a/app/controllers/softapplications_controller.rb +++ b/app/controllers/softapplications_controller.rb @@ -1,4 +1,8 @@ class SoftapplicationsController < ApplicationController + before_filter :find_softapplication, only: [:edit, :update, :destroy] + before_filter :editable, only: [:edit, :update] + before_filter :destroyable, only: :destroy + # GET /softapplications # GET /softapplications.json def index @@ -71,7 +75,7 @@ class SoftapplicationsController < ApplicationController # PUT /softapplications/1 # PUT /softapplications/1.json def update - @softapplication = Softapplication.find(params[:id]) + # @softapplication = Softapplication.find(params[:id]) respond_to do |format| if @softapplication.update_attributes(params[:softapplication]) @@ -92,11 +96,11 @@ class SoftapplicationsController < ApplicationController # DELETE /softapplications/1 # DELETE /softapplications/1.json def destroy - @softapplication = Softapplication.find(params[:id]) + # @softapplication = Softapplication.find(params[:id]) @softapplication.destroy respond_to do |format| - format.html { redirect_to softapplications_url } + format.html { redirect_to :back } format.json { head :no_content } end end @@ -192,4 +196,24 @@ class SoftapplicationsController < ApplicationController #format.api { render_api_ok } end end + + private + def find_softapplication + @softapplication = Softapplication.find_by_id(params[:id]) + end + + def editable + unless @softapplication.editable_by? User.current + render_403 + return false + end + end + + def destroyable + unless @softapplication.destroyable_by? User.current + render_403 + return false + end + end + end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 919760ee3..3ce64d695 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -181,7 +181,7 @@ class Attachment < ActiveRecord::Base end def pack? - !!(self.filename =~ /\.(zip|rar|tar|gz)$/i) + !!(self.filename =~ /\.(zip|rar|tar|gz|exe)$/i) end def thumbnailable? diff --git a/app/models/softapplication.rb b/app/models/softapplication.rb index 205ede48b..6782b2436 100644 --- a/app/models/softapplication.rb +++ b/app/models/softapplication.rb @@ -7,7 +7,7 @@ class Softapplication < ActiveRecord::Base has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :contesting_softapplications, :dependent => :destroy belongs_to :user - belongs_to :contest + has_many :contests, :through => :contesting_softapplications def add_jour(user, notes, reference_user_id = 0, options = {}) if options.count == 0 @@ -21,6 +21,13 @@ class Softapplication < ActiveRecord::Base def set_commit(commit) self.update_attribute(:commit, commit) end - + + def editable_by? usr + usr.admin? || self.user == usr + end + + def destroyable_by? usr + self.user == usr || usr.admin? + end end diff --git a/app/views/contests/_list_softapplications.html.erb b/app/views/contests/_list_softapplications.html.erb index 29c985b7e..5646f5d12 100644 --- a/app/views/contests/_list_softapplications.html.erb +++ b/app/views/contests/_list_softapplications.html.erb @@ -8,6 +8,7 @@ <%= link_to(c_softapplication.softapplication.name, softapplication_path(c_softapplication.softapplication)) %> + <%= link_to '删除', c_softapplication.softapplication, method: :delete, data: { confirm: '您确定要删除吗?' } %>
diff --git a/app/views/layouts/_base_footer.html.erb b/app/views/layouts/_base_footer.html.erb index bba5b2166..a941a7d1f 100644 --- a/app/views/layouts/_base_footer.html.erb +++ b/app/views/layouts/_base_footer.html.erb @@ -1,28 +1,43 @@
+
+ <%= debug(params) if Rails.env.development? %> + +
diff --git a/app/views/softapplications/index.html.erb b/app/views/softapplications/index.html.erb index be9245876..16a206508 100644 --- a/app/views/softapplications/index.html.erb +++ b/app/views/softapplications/index.html.erb @@ -1,4 +1,4 @@ -

Listing softapplications

+

参赛应用