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])%>
- 图片 |
+ <%= image_tag(url_to_avatar(Project.find(2)), :class => 'avatar2') %> |
<%= @open_source_project.name %>
-
+
+
<%= apply_super_user(@open_source_project, User.current) %>
|
@@ -104,19 +105,35 @@
+
+ <% 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 @@
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 {
@@ -159,14 +160,38 @@ li {
-
网络类型:
-
更多
+ 应用方向:
+ <%= link_to "操作系统相关", open_source_projects_path(:app_dir => "操作系统相关", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
+ <%= link_to "管理和监控", open_source_projects_path(:app_dir => "管理和监控", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
+ <%= link_to "游戏/娱乐", open_source_projects_path(:app_dir => "游戏/娱乐", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
+ <%= link_to "应用工具", open_source_projects_path(:app_dir => "应用工具", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
+ <%= link_to "数据库相关", open_source_projects_path(:app_dir => "数据库相关", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
+ <%= link_to "服务器软件", open_source_projects_path(:app_dir => "服务器软件", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
+ <%= link_to "网站系统", open_source_projects_path(:app_dir => "网站系统", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
+ <%= link_to "插件和扩展", open_source_projects_path(:app_dir => "插件和扩展", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
-
网络类型:
-
更多
+ 开发语言:
+ <%= link_to "java", open_source_projects_path(:language => "java", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
+ <%= link_to "c++", open_source_projects_path(:language => "c++", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
+ <%= link_to "c", open_source_projects_path(:language => "c", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
+ <%= link_to "c#", open_source_projects_path(:language => "c#", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
+ <%= link_to "ruby", open_source_projects_path(:language => "ruby", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
+ <%= link_to "其他", open_source_projects_path(:language => "其他", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
+
+
+
+
+
+
创立时间:
+ <%= link_to "2013", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2013"), :class => "nav-more J_More show" %>
+ <%= link_to "2012", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2012"), :class => "nav-more J_More show" %>
+ <%= link_to "2011", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2011"), :class => "nav-more J_More show" %>
+ <%= link_to "2010", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2010"), :class => "nav-more J_More show" %>
+ <%= link_to "更早", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "更早"), :class => "nav-more J_More show" %>
+
diff --git a/app/views/open_source_projects/master_apply.html.erb b/app/views/open_source_projects/master_apply.html.erb
new file mode 100644
index 000000000..8120d780b
--- /dev/null
+++ b/app/views/open_source_projects/master_apply.html.erb
@@ -0,0 +1,83 @@
+
+
\ No newline at end of file
diff --git a/config/locales/zh.yml b/config/locales/zh.yml
index 1877e1d33..77db00aa8 100644
--- a/config/locales/zh.yml
+++ b/config/locales/zh.yml
@@ -1808,3 +1808,7 @@ zh:
label_sumbit_empty: 搜索内容不能为空
no_use: 没有帮助
cancel_no_use: 撤销没有帮助
+ cancel_apply: 取消申请
+ apply_master: 申请成为版主
+ you_are_master: 您是该项目的版主
+
diff --git a/config/routes.rb b/config/routes.rb
index d357eff01..e2d4b2fd8 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -29,8 +29,9 @@ RedmineApp::Application.routes.draw do
collection do
match 'search', via: [:get, :post]
end
- resources :relative_memos do
-
+ resources :relative_memos
+ member do
+ match 'master_apply', via: [:get, :post]
end
end