diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..42cb6227 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,115 @@ +GEM + remote: https://rubygems.org/ + specs: + actionmailer (3.2.13) + actionpack (= 3.2.13) + mail (~> 2.5.3) + actionpack (3.2.13) + activemodel (= 3.2.13) + activesupport (= 3.2.13) + builder (~> 3.0.0) + erubis (~> 2.7.0) + journey (~> 1.0.4) + rack (~> 1.4.5) + rack-cache (~> 1.2) + rack-test (~> 0.6.1) + sprockets (~> 2.2.1) + activemodel (3.2.13) + activesupport (= 3.2.13) + builder (~> 3.0.0) + activerecord (3.2.13) + activemodel (= 3.2.13) + activesupport (= 3.2.13) + arel (~> 3.0.2) + tzinfo (~> 0.3.29) + activeresource (3.2.13) + activemodel (= 3.2.13) + activesupport (= 3.2.13) + activesupport (3.2.13) + i18n (= 0.6.1) + multi_json (~> 1.0) + acts-as-taggable-on (2.4.1) + rails (>= 3, < 5) + arel (3.0.2) + builder (3.0.0) + coderay (1.0.9) + erubis (2.7.0) + fastercsv (1.5.0) + hike (1.2.3) + i18n (0.6.1) + journey (1.0.4) + jquery-rails (2.0.3) + railties (>= 3.1.0, < 5.0) + thor (~> 0.14) + json (1.8.0) + mail (2.5.4) + mime-types (~> 1.16) + treetop (~> 1.4.8) + mime-types (1.23) + multi_json (1.7.6) + mysql2 (0.3.11-x86-mingw32) + net-ldap (0.3.1) + polyglot (0.3.3) + rack (1.4.5) + rack-cache (1.2) + rack (>= 0.4) + rack-openid (1.3.1) + rack (>= 1.1.0) + ruby-openid (>= 2.1.8) + rack-ssl (1.3.3) + rack + rack-test (0.6.2) + rack (>= 1.0) + rails (3.2.13) + actionmailer (= 3.2.13) + actionpack (= 3.2.13) + activerecord (= 3.2.13) + activeresource (= 3.2.13) + activesupport (= 3.2.13) + bundler (~> 1.0) + railties (= 3.2.13) + railties (3.2.13) + actionpack (= 3.2.13) + activesupport (= 3.2.13) + rack-ssl (~> 1.3.2) + rake (>= 0.8.7) + rdoc (~> 3.4) + thor (>= 0.14.6, < 2.0) + rake (10.0.4) + rdoc (3.12.2) + json (~> 1.4) + ruby-openid (2.1.8) + seems_rateable (1.0.13) + jquery-rails + rails + sprockets (2.2.2) + hike (~> 1.2) + multi_json (~> 1.0) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + thor (0.18.1) + tilt (1.4.1) + treetop (1.4.14) + polyglot + polyglot (>= 0.3.1) + tzinfo (0.3.37) + +PLATFORMS + x86-mingw32 + +DEPENDENCIES + activerecord-jdbc-adapter (= 1.2.5) + activerecord-jdbcmysql-adapter + acts-as-taggable-on + builder (= 3.0.0) + coderay (~> 1.0.6) + fastercsv (~> 1.5.0) + i18n (~> 0.6.0) + jquery-rails (~> 2.0.2) + mysql2 (~> 0.3.11) + net-ldap (~> 0.3.1) + rack-openid + rails (= 3.2.13) + rdoc (>= 2.4.2) + ruby-openid (~> 2.1.4) + seems_rateable diff --git a/app/controllers/softapplications_controller.rb b/app/controllers/softapplications_controller.rb index 9f14aa11..9cc940bd 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,8 +75,9 @@ class SoftapplicationsController < ApplicationController # PUT /softapplications/1 # PUT /softapplications/1.json def update - @softapplication = Softapplication.find(params[:id]) - + # @softapplication = Softapplication.find(params[:id]) + @softapplication.attachments.map{|attach| attach.destroy } + @softapplication.save_attachments(params[:attachments]) respond_to do |format| if @softapplication.update_attributes(params[:softapplication]) format.html { redirect_to @softapplication, notice: 'Softapplication was successfully updated.' } @@ -92,11 +97,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 home_path } format.json { head :no_content } end end @@ -192,4 +197,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 919760ee..73ae44b4 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|jar|7z|iso)$/i) end def thumbnailable? diff --git a/app/models/softapplication.rb b/app/models/softapplication.rb index 205ede48..6782b243 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 29c985b7..eb179718 100644 --- a/app/views/contests/_list_softapplications.html.erb +++ b/app/views/contests/_list_softapplications.html.erb @@ -6,7 +6,7 @@
创新竞赛社区 | +<%= l(:label_user_location) %> : | ++ |
<%=link_to request.host()+"/contests", :controller=>'contests', :action=>'index' %> | +<%=link_to l(:field_homepage), home_path %> > + <%=link_to l(:label_contest_innovate), :controller=>'contests', :action=>'index' %> > + + <% contest = @softapplication.contests.first %><%= contest ? link_to(contest.name, show_contest_contest_path(contest)) : '尚未加入竞赛'%> + + + | +
创新竞赛社区 | -<%= l(:label_user_location) %> : | -
-
- <%= form_tag(:controller => 'bids', :action => 'contest', :method => :get) do %>
- <%= text_field_tag 'name', params[:name], :size => 20 %>
- <%= hidden_field_tag 'reward_type', @bid.reward_type %>
- <%= hidden_field_tag 'project_type', params[:project_type] %>
- <%= submit_tag l(:label_search), :class => "enterprise", :name => nil %>
- <% end %>
-
- |
+ 创新竞赛社区 | +<%= l(:label_user_location) %> : | +
+
+ <%= form_tag(:controller => 'bids', :action => 'contest', :method => :get) do %>
+ <%= text_field_tag 'name', params[:name], :size => 20 %>
+ <%= hidden_field_tag 'reward_type', @bid.reward_type %>
+ <%= hidden_field_tag 'project_type', params[:project_type] %>
+ <%= submit_tag l(:label_search), :class => "enterprise", :name => nil %>
+ <% end %>
+
+ |
<%=link_to request.host()+"/contest", :controller => 'bids', :action => 'contest' %> | -<%=link_to l(:field_homepage), home_path %> > <%=link_to l(:label_contest_innovate), :controller => 'bids', :action => 'contest' %> > - <%= link_to @bid.name, bid_path %> | +<%=link_to request.host()+"/contest", :controller => 'bids', :action => 'contest' %> | +<%=link_to l(:field_homepage), home_path %> > <%=link_to l(:label_contest_innovate), :controller => 'bids', :action => 'contest' %> > + <%= link_to @bid.name, bid_path %> |
创新竞赛社区 | -<%= l(:label_user_location) %> : | -
-
- <%= form_tag({controller: 'contests', action: 'index'}, method: :get) do %>
- <%= text_field_tag 'name', params[:name], :size => 20 %>
- <%= hidden_field_tag 'project_type', params[:project_type] %>
- <%= submit_tag l(:label_search), :class => "enterprise", :name => nil %>
- <% end %>
-
- |
+ 创新竞赛社区 | +<%= l(:label_user_location) %> : | +
+
+ <%= form_tag({controller: 'contests', action: 'index'}, method: :get) do %>
+ <%= text_field_tag 'name', params[:name], :size => 20 %>
+ <%= hidden_field_tag 'project_type', params[:project_type] %>
+ <%= submit_tag l(:label_search), :class => "enterprise", :name => nil %>
+ <% end %>
+
+ |
<%=link_to request.host()+"/contests", :controller=>'contests', :action=>'index' %> | -<%=link_to l(:field_homepage), home_path %> > - <%=link_to l(:label_contest_innovate), :controller=>'contests', :action=>'index' %> > - <%= link_to @contest.name, show_contest_contest_path %> - | +<%=link_to request.host()+"/contests", :controller=>'contests', :action=>'index' %> | +<%=link_to l(:field_homepage), home_path %> > + <%=link_to l(:label_contest_innovate), :controller=>'contests', :action=>'index' %> > + <%= link_to @contest.name, show_contest_contest_path %> + |
<%= f.text_field :name, :required => true, :size => 60, :style => "width:400px;" %> | - <%= l(:label_softapplication_name_condition)%> -||||
<%= f.text_field :android_min_version_available, :required => true, :size => 60, :style => "width:400px;" %> | - -||||
<%= f.text_field :app_type_name, :required => true, :size => 60, :style => "width:400px;" %> | - -||||
<%= f.text_field :description, :required => true, :size => 60, :style => "width:400px;" %> | - -||||
<%= f.text_field :application_developers, :required => true, :size => 60, :style => "width:400px;" %> | - -