2012-09-16 13:44:54 +02:00
|
|
|
class Admin::ProjectsController < AdminController
|
2012-11-23 05:31:09 +01:00
|
|
|
before_filter :project, only: [:edit, :show, :update, :destroy, :team_update]
|
2011-10-08 23:36:38 +02:00
|
|
|
|
|
|
|
def index
|
2012-11-23 05:31:09 +01:00
|
|
|
@projects = Project.scoped
|
2012-11-23 05:24:09 +01:00
|
|
|
@projects = @projects.where(namespace_id: params[:namespace_id]) if params[:namespace_id].present?
|
2012-11-23 05:31:09 +01:00
|
|
|
@projects = @projects.search(params[:name]) if params[:name].present?
|
2012-11-23 19:11:09 +01:00
|
|
|
@projects = @projects.includes(:namespace).order("namespaces.path, projects.name ASC").page(params[:page]).per(20)
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2012-07-31 07:32:49 +02:00
|
|
|
@users = User.scoped
|
2012-11-23 05:31:09 +01:00
|
|
|
@users = @users.not_in_project(@project) if @project.users.present?
|
2012-07-31 07:32:49 +02:00
|
|
|
@users = @users.all
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
2012-01-21 17:06:14 +01:00
|
|
|
def team_update
|
2012-11-23 05:31:09 +01:00
|
|
|
@project.add_users_ids_to_team(params[:user_ids], params[:project_access])
|
2011-10-08 23:36:38 +02:00
|
|
|
|
2012-11-23 05:31:09 +01:00
|
|
|
redirect_to [:admin, @project], notice: 'Project was successfully updated.'
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2012-02-21 21:46:34 +01:00
|
|
|
owner_id = params[:project].delete(:owner_id)
|
2012-01-29 22:59:12 +01:00
|
|
|
|
2012-09-16 13:44:54 +02:00
|
|
|
if owner_id
|
2012-11-23 05:31:09 +01:00
|
|
|
@project.owner = User.find(owner_id)
|
2012-01-29 22:59:12 +01:00
|
|
|
end
|
|
|
|
|
2012-11-23 05:31:09 +01:00
|
|
|
if @project.update_attributes(params[:project], as: :admin)
|
|
|
|
redirect_to [:admin, @project], notice: 'Project was successfully updated.'
|
2011-10-27 15:44:29 +02:00
|
|
|
else
|
2012-08-11 00:07:50 +02:00
|
|
|
render action: "edit"
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2012-11-23 05:31:09 +01:00
|
|
|
@project.destroy
|
2012-07-31 07:32:49 +02:00
|
|
|
|
2012-11-26 01:22:44 +01:00
|
|
|
redirect_to admin_projects_path, notice: 'Project was successfully deleted.'
|
2012-07-31 07:32:49 +02:00
|
|
|
end
|
2012-11-23 21:25:28 +01:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def project
|
|
|
|
id = params[:project_id] || params[:id]
|
|
|
|
|
2012-11-25 11:26:34 +01:00
|
|
|
@project = Project.find_with_namespace(id)
|
2012-11-23 21:25:28 +01:00
|
|
|
@project || render_404
|
|
|
|
end
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|