BigW Consortium Gitlab

groups_controller.rb 1.59 KB
Newer Older
1
class Admin::GroupsController < Admin::ApplicationController
2
  before_action :group, only: [:edit, :show, :update, :destroy, :project_update, :members_update]
3 4

  def index
5 6
    @groups = Group.all
    @groups = @groups.sort(@sort = params[:sort])
7
    @groups = @groups.search(params[:name]) if params[:name].present?
8
    @groups = @groups.page(params[:page])
9 10 11
  end

  def show
12
    @members = @group.members.order("access_level DESC").page(params[:members_page])
13
    @requesters = @group.requesters
14
    @projects = @group.projects.page(params[:projects_page])
15 16 17 18 19 20 21 22 23 24
  end

  def new
    @group = Group.new
  end

  def edit
  end

  def create
25
    @group = Group.new(group_params)
26
    @group.name = @group.path.dup unless @group.name
27 28

    if @group.save
29
      @group.add_owner(current_user)
30 31
      redirect_to [:admin, @group], notice: 'Group was successfully created.'
    else
32
      render "new"
33 34 35 36
    end
  end

  def update
37
    if @group.update_attributes(group_params)
38 39
      redirect_to [:admin, @group], notice: 'Group was successfully updated.'
    else
40
      render "edit"
41 42 43
    end
  end

44
  def members_update
45
    @group.add_users(params[:user_ids].split(','), params[:access_level], current_user)
46

47
    redirect_to [:admin, @group], notice: 'Users were successfully added.'
48 49
  end

50
  def destroy
51
    DestroyGroupService.new(@group, current_user).execute
52

randx committed
53
    redirect_to admin_groups_path, notice: 'Group was successfully deleted.'
54 55 56 57 58
  end

  private

  def group
59
    @group ||= Group.find_by(path: params[:id])
60
  end
61 62

  def group_params
63
    params.require(:group).permit(:name, :description, :path, :avatar, :visibility_level)
64
  end
65
end