gitlabhq/app/controllers/admin/groups_controller.rb

89 lines
2 KiB
Ruby
Raw Normal View History

class Admin::GroupsController < AdminController
2012-12-25 23:52:20 +01:00
before_filter :group, only: [:edit, :show, :update, :destroy, :project_update, :project_teams_update]
def index
2012-12-10 04:14:05 +01:00
@groups = Group.order('name ASC')
@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
@projects.reject!(&:empty_repo?)
2012-12-25 23:52:20 +01:00
@users = User.active
end
def new
@group = Group.new
end
def edit
end
def create
@group = Group.new(params[:group])
@group.path = @group.name.dup.parameterize if @group.name
@group.owner = current_user
if @group.save
redirect_to [:admin, @group], notice: 'Group was successfully created.'
else
render action: "new"
end
end
def update
group_params = params[:group].dup
owner_id =group_params.delete(:owner_id)
if owner_id
@group.owner = User.find(owner_id)
end
if @group.update_attributes(group_params)
redirect_to [:admin, @group], notice: 'Group was successfully updated.'
else
render action: "edit"
end
end
def project_update
project_ids = params[:project_ids]
Project.where(id: project_ids).each do |project|
project.transfer(@group)
end
redirect_to :back, notice: 'Group was successfully updated.'
end
def remove_project
@project = Project.find(params[:project_id])
@project.transfer(nil)
redirect_to :back, notice: 'Group was successfully updated.'
end
2012-12-25 23:52:20 +01:00
def project_teams_update
@group.add_users_to_project_teams(params[:user_ids], params[:project_access])
2012-12-25 23:52:20 +01:00
redirect_to [:admin, @group], notice: 'Users was successfully added.'
end
def destroy
2012-12-30 13:26:19 +01:00
@group.truncate_teams
@group.destroy
2012-10-22 20:21:34 +02:00
redirect_to admin_groups_path, notice: 'Group was successfully deleted.'
end
private
def group
2012-11-23 20:31:09 +01:00
@group = Group.find_by_path(params[:id])
end
end