2012-10-02 18:01:40 +02:00
|
|
|
class Admin::GroupsController < AdminController
|
|
|
|
before_filter :group, only: [:edit, :show, :update, :destroy, :project_update]
|
|
|
|
|
|
|
|
def index
|
|
|
|
@groups = Group.scoped
|
|
|
|
@groups = @groups.search(params[:name]) if params[:name].present?
|
|
|
|
@groups = @groups.page(params[:page]).per(20)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@projects = Project.scoped
|
|
|
|
@projects = @projects.not_in_group(@group) if @group.projects.present?
|
|
|
|
@projects = @projects.all
|
2012-12-03 19:14:05 +01:00
|
|
|
@projects.reject!(&:empty_repo?)
|
2012-10-02 18:01:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@group = Group.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@group = Group.new(params[:group])
|
2012-11-27 07:31:15 +01:00
|
|
|
@group.path = @group.name.dup.parameterize if @group.name
|
2012-10-02 18:01:40 +02:00
|
|
|
@group.owner = current_user
|
|
|
|
|
|
|
|
if @group.save
|
|
|
|
redirect_to [:admin, @group], notice: 'Group was successfully created.'
|
|
|
|
else
|
|
|
|
render action: "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2012-10-03 14:02:02 +02:00
|
|
|
group_params = params[:group].dup
|
|
|
|
owner_id =group_params.delete(:owner_id)
|
2012-10-02 18:01:40 +02:00
|
|
|
|
|
|
|
if owner_id
|
|
|
|
@group.owner = User.find(owner_id)
|
|
|
|
end
|
|
|
|
|
2012-10-03 14:02:02 +02:00
|
|
|
if @group.update_attributes(group_params)
|
2012-10-02 18:01:40 +02:00
|
|
|
redirect_to [:admin, @group], notice: 'Group was successfully updated.'
|
|
|
|
else
|
|
|
|
render action: "edit"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_update
|
|
|
|
project_ids = params[:project_ids]
|
2012-11-22 20:41:16 +01:00
|
|
|
|
|
|
|
Project.where(id: project_ids).each do |project|
|
2012-11-24 11:37:30 +01:00
|
|
|
project.transfer(@group)
|
2012-11-22 20:41:16 +01:00
|
|
|
end
|
2012-10-02 18:01:40 +02:00
|
|
|
|
|
|
|
redirect_to :back, notice: 'Group was successfully updated.'
|
|
|
|
end
|
|
|
|
|
2012-10-03 11:49:43 +02:00
|
|
|
def remove_project
|
|
|
|
@project = Project.find(params[:project_id])
|
2012-11-24 11:37:30 +01:00
|
|
|
@project.transfer(nil)
|
2012-10-03 11:49:43 +02:00
|
|
|
|
|
|
|
redirect_to :back, notice: 'Group was successfully updated.'
|
|
|
|
end
|
|
|
|
|
2012-10-02 18:01:40 +02:00
|
|
|
def destroy
|
|
|
|
@group.destroy
|
|
|
|
|
2012-10-22 20:21:34 +02:00
|
|
|
redirect_to admin_groups_path, notice: 'Group was successfully deleted.'
|
2012-10-02 18:01:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def group
|
2012-11-23 20:31:09 +01:00
|
|
|
@group = Group.find_by_path(params[:id])
|
2012-10-02 18:01:40 +02:00
|
|
|
end
|
|
|
|
end
|