diff --git a/app/controllers/open_source_projects_controller.rb b/app/controllers/open_source_projects_controller.rb index 55892d457..2c1e1e049 100644 --- a/app/controllers/open_source_projects_controller.rb +++ b/app/controllers/open_source_projects_controller.rb @@ -1,5 +1,8 @@ class OpenSourceProjectsController < ApplicationController + before_filter :find_osp, :only => [:master_apply] + before_filter :require_master, :only => [:master_apply] + helper :sort include SortHelper helper :apply_project_masters @@ -9,6 +12,9 @@ class OpenSourceProjectsController < ApplicationController # GET /open_source_projects # GET /open_source_projects.json def index + @app_dir = params[:app_dir] + @language = params[:language] + @created_at = params[:created_at] per_page_option = 10 @open_source_projects = OpenSourceProject.all @@ -23,6 +29,18 @@ class OpenSourceProjectsController < ApplicationController format.json { render json: @open_source_projects } end end + + def master_apply + @apply = @open_source_project.apply_tips + @applicants = @open_source_project.applicants + + respond_to do |format| + format.html { + render :layout => "base_opensource_p" + } + format.json { render json: @open_source_project } + end + end # GET /open_source_projects/1 # GET /open_source_projects/1.json @@ -127,4 +145,15 @@ class OpenSourceProjectsController < ApplicationController format.json { head :no_content } end end + + private + + def require_master + render_403 unless @open_source_project.admin?(User.current) + end + + def find_osp + @open_source_project = OpenSourceProject.find(params[:id]) + render_404 unless @open_source_project.present? + end end diff --git a/app/helpers/apply_project_masters_helper.rb b/app/helpers/apply_project_masters_helper.rb index a2dccba35..565f8ea04 100644 --- a/app/helpers/apply_project_masters_helper.rb +++ b/app/helpers/apply_project_masters_helper.rb @@ -11,7 +11,7 @@ module ApplyProjectMastersHelper css = apply_css(objects) << options[0].to_s - text = applied ? (allowed ? ("123") : ("123")) : ("231") + text = applied ? (allowed ? l(:you_are_master) : l(:cancel_apply)) : l(:apply_master) url = apply_project_masters_path( :object_type => objects.first.class.to_s.underscore, diff --git a/app/models/apply_project_master.rb b/app/models/apply_project_master.rb index f4d21b2bb..13bd2f372 100644 --- a/app/models/apply_project_master.rb +++ b/app/models/apply_project_master.rb @@ -1,5 +1,6 @@ class ApplyProjectMaster < ActiveRecord::Base # attr_accessible :title, :body + # status 1是申请者,2是版主 belongs_to :apply, :polymorphic => true belongs_to :user diff --git a/app/models/open_source_project.rb b/app/models/open_source_project.rb index 320b79f7e..ca2d0be18 100644 --- a/app/models/open_source_project.rb +++ b/app/models/open_source_project.rb @@ -7,6 +7,10 @@ class OpenSourceProject < ActiveRecord::Base has_many :relative_memos, :class_name => 'RelativeMemo', :foreign_key => 'osp_id', :dependent => :destroy has_many :tags, :through => :project_tags, :class_name => 'Tag' has_many :project_tags, :class_name => 'ProjectTags' + has_many :masters, :class_name => 'ApplyProjectMaster', :as => :apply, :dependent => :delete_all, :conditions => "#{ApplyProjectMaster.table_name}.status = 2" + has_many :admin, :through => :masters, :class_name => 'User' + has_many :apply_tips, :class_name => 'ApplyProjectMaster', :as => :apply, :dependent => :delete_all, :conditions => "#{ApplyProjectMaster.table_name}.status = 1" + has_many :applicants, :class_name => 'User', :through => :apply_tips, :source => :user acts_as_taggable @@ -22,10 +26,20 @@ class OpenSourceProject < ActiveRecord::Base end def applied_by?(user) + self.applies.each do |apply| + if apply.user_id == user.id + return true + end + end false end def allowed?(user) + self.applies.each do |apply| + if apply.user_id == user.id and apply.status == 2 + return true + end + end false end @@ -42,6 +56,14 @@ class OpenSourceProject < ActiveRecord::Base ApplyProjectMaster.delete_all "apply_type = '#{self.class}' AND apply_id = #{self.id} AND user_id = #{user.id}" end + def admin?(user) + if user.admin? or ApplyProjectMaster.find(:all, :conditions => ["user_id = ? and apply_type = 'OpenSourceProject' and apply_id = ? and status = ?", user.id, self.id, 2]).present? + return true + else + return false + end + end + def reset_counters! self.class.reset_counters!(id) end diff --git a/app/views/layouts/base_opensource_p.html.erb b/app/views/layouts/base_opensource_p.html.erb index b982a3a19..3f64996c7 100644 --- a/app/views/layouts/base_opensource_p.html.erb +++ b/app/views/layouts/base_opensource_p.html.erb @@ -47,13 +47,14 @@ <% @open_source_project = OpenSourceProject.find(params[:id])%> - + @@ -104,19 +105,35 @@
- <%= render :partial => 'tags/tag', :locals => {:obj => @open_source_project,:object_flag => "7"}%> + <%= render :partial => 'tags/tag', :locals => {:obj => @open_source_project, :object_flag => "7"}%>
+ + <% if @open_source_project.admin?(User.current) %> +
+
+ 管理 +
+ +
+ +
+ <% end %> +
-
<%#= -
+
+ <%#=
%> <%= render_flash_messages %> diff --git a/app/views/open_source_projects/_os_project.html.erb b/app/views/open_source_projects/_os_project.html.erb index 133f6c4cc..c609110de 100644 --- a/app/views/open_source_projects/_os_project.html.erb +++ b/app/views/open_source_projects/_os_project.html.erb @@ -11,7 +11,7 @@

- <%= 1%> + <%= project.users_count %> <%= content_tag('span', l(:label_x_follow_people,:count =>0)) %>

@@ -21,12 +21,12 @@

- <%= 1 %> + <%= project.commit_count %> <%= content_tag('span', l(:label_since_last_commits)) %>

- <%= 1 %> + <%= project.code_line %> <%= content_tag('span', "行代码") %>

diff --git a/app/views/open_source_projects/index.html.erb b/app/views/open_source_projects/index.html.erb index 032e0a82b..0df5a69d0 100644 --- a/app/views/open_source_projects/index.html.erb +++ b/app/views/open_source_projects/index.html.erb @@ -141,16 +141,17 @@ li {
图片<%= image_tag(url_to_avatar(Project.find(2)), :class => 'avatar2') %>
<%= @open_source_project.name %>
-
+
+
<%= apply_super_user(@open_source_project, User.current) %>