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 @@ 应用软件: - <%= link_to(c_softapplication.softapplication.name, softapplication_path(c_softapplication.softapplication)) %> + <%= link_to(c_softapplication.softapplication.name, softapplication_path(c_softapplication.softapplication), :target => '_blank') %>
diff --git a/app/views/layouts/_base_footer.html.erb b/app/views/layouts/_base_footer.html.erb index e0551557..0f233465 100644 --- a/app/views/layouts/_base_footer.html.erb +++ b/app/views/layouts/_base_footer.html.erb @@ -27,3 +27,18 @@ + +
+ <%= debug(params) if Rails.env.development? %> + + +
diff --git a/app/views/layouts/_base_softapplication_top_content.html.erb b/app/views/layouts/_base_softapplication_top_content.html.erb new file mode 100644 index 00000000..064e84cf --- /dev/null +++ b/app/views/layouts/_base_softapplication_top_content.html.erb @@ -0,0 +1,20 @@ +
+ + + + + + + + + + + +
创新竞赛社区<%= 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)) : '尚未加入竞赛'%> + + +
+
\ No newline at end of file diff --git a/app/views/layouts/base_contest.html.erb b/app/views/layouts/base_contest.html.erb index b4ba3dd4..2bda701f 100644 --- a/app/views/layouts/base_contest.html.erb +++ b/app/views/layouts/base_contest.html.erb @@ -26,23 +26,23 @@
- - - + + + - - + +
创新竞赛社区<%= l(:label_user_location) %> : - - 创新竞赛社区<%= l(:label_user_location) %> : + +
<%=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 %>
diff --git a/app/views/layouts/base_newcontest.html.erb b/app/views/layouts/base_newcontest.html.erb index ba78cefe..147df524 100644 --- a/app/views/layouts/base_newcontest.html.erb +++ b/app/views/layouts/base_newcontest.html.erb @@ -27,24 +27,24 @@
- - - + + + - - + +
创新竞赛社区<%= l(:label_user_location) %> : - - 创新竞赛社区<%= 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' %> > - <%= 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 %> +
diff --git a/app/views/softapplications/_form.html.erb b/app/views/softapplications/_form.html.erb index 5a046801..b4a9c3c9 100644 --- a/app/views/softapplications/_form.html.erb +++ b/app/views/softapplications/_form.html.erb @@ -1,64 +1,70 @@ -<%= form_for(@softapplication) do |f| %> +<%= form_for(softapplication) do |f| %> - <% if @softapplication.errors.any? %> + <% if softapplication.errors.any? %>
-

<%= pluralize(@softapplication.errors.count, "error") %> prohibited this softapplication from being saved:

+

<%= pluralize(softapplication.errors.count, "error") %> prohibited this softapplication from being saved:

<% end %> - - - <%= l(:label_softapplication_name) %> - * : - <%= f.text_field :name, :required => true, :size => 60, :style => "width:400px;" %> - <%= l(:label_softapplication_name_condition)%> -

+
+ + + <%= l(:label_softapplication_name) %> + * : <%= f.text_field :name, :required => true, :size => 60, :style => "width:400px;" %> + <%= l(:label_softapplication_name_condition)%> + +
+
+ + + <%= l(:label_softapplication_version_available) %> + * : <%= f.text_field :android_min_version_available, :required => true, :size => 60, :style => "width:400px;" %> - - <%= l(:label_softapplication_version_available) %> - * : - <%= f.text_field :android_min_version_available, :required => true, :size => 60, :style => "width:400px;" %> + +
+
+ + + <%= l(:label_softapplication_type) %> -

+ * : <%= f.text_field :app_type_name, :required => true, :size => 60, :style => "width:400px;" %> - - <%= l(:label_softapplication_type) %> - * : - <%= f.text_field :app_type_name, :required => true, :size => 60, :style => "width:400px;" %> + +
+
+ + + <%= l(:label_softapplication_description) %> + * : <%= f.text_field :description, :required => true, :size => 60, :style => "width:400px;" %> -

+ +
+
+ + <%= l(:label_softapplication_developers) %> + * : <%= f.text_field :application_developers, :required => true, :size => 60, :style => "width:400px;" %> - - <%= l(:label_softapplication_description) %> - * : - <%= f.text_field :description, :required => true, :size => 60, :style => "width:400px;" %> - -

- - -
-
- <%=l(:label_upload_softapplication_packets)%> :
-

- <%= render :partial => 'attachments/form' %> -

-
-
- -
-
- <%=l(:label_upload_softapplication_photo)%> :(<%=l(:label_upload_softapplication_photo_condition)%>)
-

- <%= render :partial => 'attachments/form' %> -

-
-
+ +
+
+
+ 上传应用软件包和应用截图 + <%= render_flash_messages %> +

+ <%= render :partial => 'attachments/form' %> +

+

1、<%=l(:label_upload_softapplication_packets_mustpacketed)%>
2、<%=l(:label_upload_softapplication_photo_condition)%>

+

<%=l(:label_updated_caution)%>

+ +
+

+
<%= submit_tag l(:button_create), :onclick => "return true" %>
<% end %> diff --git a/app/views/softapplications/edit.html.erb b/app/views/softapplications/edit.html.erb index f93e091d..c9e0c6f6 100644 --- a/app/views/softapplications/edit.html.erb +++ b/app/views/softapplications/edit.html.erb @@ -1,6 +1,8 @@ -

Editing softapplication

+

<%= l(:label_edit_softapplication)%>

+ +<%= render partial: 'form', locals:{softapplication: @softapplication} %> + + -<%= render 'form' %> -<%= link_to 'Show', @softapplication %> | -<%= link_to 'Back', softapplications_path %> diff --git a/app/views/softapplications/index.html.erb b/app/views/softapplications/index.html.erb index be924587..16a20650 100644 --- a/app/views/softapplications/index.html.erb +++ b/app/views/softapplications/index.html.erb @@ -1,4 +1,4 @@ -

Listing softapplications

+

参赛应用

diff --git a/app/views/softapplications/new.html.erb b/app/views/softapplications/new.html.erb index d5ff2c9c..1112fcfa 100644 --- a/app/views/softapplications/new.html.erb +++ b/app/views/softapplications/new.html.erb @@ -1,76 +1,5 @@

<%= l(:label_release_softapplication)%>

- +<%= render partial: 'form', locals:{softapplication: @softapplication} %> -
- <%= form_for Softapplication.new, :url => {:controller => 'softapplications', :action => 'create'}, :update => "bidding_project_list", :complete => '$("#put-bid-form").hide();', :html => {:multipart => true, :id => 'add_homework_form'} do |f| %> -
- -
- <%= l(:label_softapplication_name) %> - * : - <%= l(:label_softapplication_name_condition)%> - -
-
- - <%= l(:label_softapplication_version_available) %> - * : - - -
-
- - - <%= l(:label_softapplication_type) %> - - * : - - -
-
- - - <%= l(:label_softapplication_description) %> - * : - - -
-
- - - <%= l(:label_softapplication_developers) %> - * : - - -
-
-
- 上传应用软件包和应用截图 - <%= render_flash_messages %> -

- <%= render :partial => 'attachments/form' %> -

-

(<%=l(:label_upload_softapplication_photo_condition)%>)

- -
-
-
<%= submit_tag l(:button_create), :onclick => "return true" %>
- - - - <% end %> - \ No newline at end of file diff --git a/app/views/softapplications/show.html.erb b/app/views/softapplications/show.html.erb index c0234831..b39ab6c6 100644 --- a/app/views/softapplications/show.html.erb +++ b/app/views/softapplications/show.html.erb @@ -1,3 +1,4 @@ +<%=render :partial => 'layouts/base_softapplication_top_content'%>
<%= f.text_field :name, :required => true, :size => 60, :style => "width:400px;" %>
<%= 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;" %>