2013-01-20 15:20:50 +04:00
|
|
|
class Admin::ProjectsController < Admin::ApplicationController
|
2012-11-23 07:31:09 +03:00
|
|
|
before_filter :project, only: [:edit, :show, :update, :destroy, :team_update]
|
2011-10-09 00:36:38 +03:00
|
|
|
|
|
|
|
def index
|
2012-11-23 07:31:09 +03:00
|
|
|
@projects = Project.scoped
|
2012-11-23 07:24:09 +03:00
|
|
|
@projects = @projects.where(namespace_id: params[:namespace_id]) if params[:namespace_id].present?
|
2013-01-13 17:24:29 +02:00
|
|
|
@projects = @projects.where(public: true) if params[:public_only].present?
|
2013-01-14 09:44:27 +02:00
|
|
|
@projects = @projects.with_push if params[:with_push].present?
|
2013-01-14 09:37:29 +02:00
|
|
|
@projects = @projects.abandoned if params[:abandoned].present?
|
2012-12-03 21:14:05 +03:00
|
|
|
@projects = @projects.where(namespace_id: nil) if params[:namespace_id] == Namespace.global_id
|
2012-11-23 07:31:09 +03:00
|
|
|
@projects = @projects.search(params[:name]) if params[:name].present?
|
2012-11-23 21:11:09 +03:00
|
|
|
@projects = @projects.includes(:namespace).order("namespaces.path, projects.name ASC").page(params[:page]).per(20)
|
2011-10-09 00:36:38 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2013-01-04 08:43:25 +02:00
|
|
|
@repository = @project.repository
|
2012-12-04 15:22:22 +02:00
|
|
|
@users = User.active
|
2012-11-23 07:31:09 +03:00
|
|
|
@users = @users.not_in_project(@project) if @project.users.present?
|
2012-07-31 08:32:49 +03:00
|
|
|
@users = @users.all
|
2011-10-09 00:36:38 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
2012-01-21 18:06:14 +02:00
|
|
|
def team_update
|
2013-01-04 08:43:25 +02:00
|
|
|
@project.team.add_users_ids(params[:user_ids], params[:project_access])
|
2011-10-09 00:36:38 +03:00
|
|
|
|
2012-11-23 07:31:09 +03:00
|
|
|
redirect_to [:admin, @project], notice: 'Project was successfully updated.'
|
2011-10-09 00:36:38 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2013-01-22 21:15:05 +04:00
|
|
|
project.creator = current_user unless project.creator
|
|
|
|
|
2013-01-22 21:14:00 +04:00
|
|
|
status = ::Projects::UpdateContext.new(project, current_user, params).execute(:admin)
|
2012-01-29 23:59:12 +02:00
|
|
|
|
2012-11-29 07:29:11 +03:00
|
|
|
if status
|
2012-11-23 07:31:09 +03:00
|
|
|
redirect_to [:admin, @project], notice: 'Project was successfully updated.'
|
2011-10-27 16:44:29 +03:00
|
|
|
else
|
2012-08-10 18:07:50 -04:00
|
|
|
render action: "edit"
|
2011-10-09 00:36:38 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2012-12-30 14:09:43 +02:00
|
|
|
# Delete team first in order to prevent multiple gitolite calls
|
2013-01-04 08:43:25 +02:00
|
|
|
@project.team.truncate
|
2012-12-30 14:09:43 +02:00
|
|
|
|
2012-11-23 07:31:09 +03:00
|
|
|
@project.destroy
|
2012-07-31 08:32:49 +03:00
|
|
|
|
2012-11-26 01:22:44 +01:00
|
|
|
redirect_to admin_projects_path, notice: 'Project was successfully deleted.'
|
2012-07-31 08:32:49 +03:00
|
|
|
end
|
2012-11-23 22:25:28 +02:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def project
|
|
|
|
id = params[:project_id] || params[:id]
|
|
|
|
|
2012-11-25 12:26:34 +02:00
|
|
|
@project = Project.find_with_namespace(id)
|
2012-11-23 22:25:28 +02:00
|
|
|
@project || render_404
|
|
|
|
end
|
2011-10-09 00:36:38 +03:00
|
|
|
end
|