项目删除功能
This commit is contained in:
parent
065cd95714
commit
ca6058d120
|
@ -33,7 +33,8 @@ class ProjectsController < ApplicationController
|
|||
:view_homework_attaches,:join_project, :project_home, :training_execute, :training_task_status]
|
||||
before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course]
|
||||
before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches]
|
||||
before_filter :require_admin, :only => [ :copy, :unarchive, :destroy, :calendar]
|
||||
before_filter :require_admin, :only => [ :copy, :unarchive, :calendar]
|
||||
before_filter :require_admin_or_manager, :only => [ :destroy]
|
||||
before_filter :file
|
||||
|
||||
|
||||
|
@ -793,7 +794,7 @@ class ProjectsController < ApplicationController
|
|||
GITLABTYPE = "Repository::Gitlab"
|
||||
def archive
|
||||
if request.post?
|
||||
if @project.archive && @project.gpid
|
||||
if @project.destroy && @project.gpid
|
||||
# 删除版本库信息
|
||||
begin
|
||||
g = Gitlab.client
|
||||
|
@ -1103,19 +1104,32 @@ class ProjectsController < ApplicationController
|
|||
redirect_to project_url(@project)
|
||||
end
|
||||
|
||||
REP_TYPE = "Repository::Gitlab"
|
||||
# Delete @project
|
||||
def destroy
|
||||
@project_to_destroy = @project
|
||||
@project_to_destroy.destroy
|
||||
ActiveRecord::Base.transaction do
|
||||
g = Gitlab.client
|
||||
g.delete_project(@project.gpid)
|
||||
# 删除Trustie版本库记录
|
||||
repoisitory = Repository.where(:project_id => @project.id, :type => GITLABTYPE).first
|
||||
repoisitory.delete
|
||||
@project.update_column(:gpid, nil)
|
||||
@project.update_column(:forked_from_project_id, nil)
|
||||
@project_to_destroy = @project
|
||||
@project_to_destroy.destroy
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to admin_projects_url }
|
||||
format.api { render_api_ok }
|
||||
if params[:type] == "project"
|
||||
format.html{redirect_to user_path(User.current)}
|
||||
else
|
||||
format.html{redirect_to admin_projects_url(:status => params[:status])}
|
||||
end
|
||||
end
|
||||
# hide project in layout
|
||||
@project = nil
|
||||
end
|
||||
|
||||
REP_TYPE = "Repository::Gitlab"
|
||||
|
||||
# Delete @project's repository
|
||||
def destroy_repository
|
||||
if is_project_manager?(User.current.id, @project.id)
|
||||
|
@ -1294,6 +1308,13 @@ class ProjectsController < ApplicationController
|
|||
return projects
|
||||
end
|
||||
|
||||
#gcmend
|
||||
def require_admin_or_manager
|
||||
return unless require_login
|
||||
if !(User.current.admin? || User.current.manager_of_project?(@project.id))
|
||||
render_403
|
||||
return false
|
||||
end
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ class BidingProject < ActiveRecord::Base
|
|||
attr_accessible :bid_id, :project_id, :user_id, :description,:reward
|
||||
|
||||
belongs_to :bid
|
||||
belongs_to :project
|
||||
# belongs_to :project
|
||||
belongs_to :user
|
||||
|
||||
DESCRIPTION_LENGTH_LIMIT = 500
|
||||
|
|
|
@ -70,8 +70,8 @@ class Project < ActiveRecord::Base
|
|||
has_many :repositories, :dependent => :destroy, conditions: "hidden=false"
|
||||
has_many :changesets, :through => :repository
|
||||
#added by xianbo for delete biding_project
|
||||
has_many :biding_projects, :dependent => :destroy
|
||||
has_many :contesting_projects, :dependent => :destroy
|
||||
# has_many :biding_projects, :dependent => :destroy
|
||||
# has_many :contesting_projects, :dependent => :destroy
|
||||
has_many :softapplications, :through => :projecting_softapplications
|
||||
#ended by xianbo
|
||||
# added by fq
|
||||
|
|
|
@ -928,6 +928,15 @@ class User < Principal
|
|||
end
|
||||
end
|
||||
|
||||
def manager_of_project?(project_id)
|
||||
@result = false
|
||||
mem = Member.where("user_id = ? and project_id = ?", self.id, project_id)
|
||||
unless mem.blank?
|
||||
@result = mem.first.roles.to_s.include?("Manager") ? true : false
|
||||
end
|
||||
return @result
|
||||
end
|
||||
|
||||
# 判断是否是竞赛的主办人
|
||||
def admin_of_contest?(contest)
|
||||
if contest.nil?
|
||||
|
|
|
@ -48,8 +48,8 @@
|
|||
</li>
|
||||
<li class="clear">
|
||||
<% if Member.where(:user_id => User.current.id, :project_id => @project.id).first.try(:roles).to_s.include?("Manager") %>
|
||||
<%= link_to(l(:button_delete_project), { :controller => 'projects', :action => 'archive', :id => @project, :status => params[:status], :type =>"project" },
|
||||
:data => {:confirm => l(:text_delete_project_are_you_sure)}, :method => :post, :class => "sy_btn_grey mr5 fl ml15") unless @project.archived? %>
|
||||
<%= link_to(l(:button_delete_project), project_path(@project, :type => "project"), :method => :delete, :class => 'sy_btn_grey mr5 fl ml15',
|
||||
:data => {:confirm => l(:text_delete_project_are_you_sure)}) %>
|
||||
<p class="fl c_grey">(友情提示:删除操作会彻底删除项目的所有信息,一旦删除不能恢复!)</p>
|
||||
<% end %>
|
||||
<a href="javascript:void(0)" class="sy_btn_blue mr15 fr" onclick="submit_edit_project(<%= @project.id %>);" >保存</a>
|
||||
|
|
Loading…
Reference in New Issue