Read about our upcoming Code of Conduct on this issue

groups_controller.rb 1.75 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])
Rémy Coutable's avatar
Rémy Coutable committed
13
    @requesters = AccessRequestsFinder.new(@group).execute(current_user)
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: current_user)
46

Kyle Kelley's avatar
Kyle Kelley committed
47
    redirect_to [:admin, @group], notice: 'Users were successfully added.'
48
49
  end

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

53
    redirect_to admin_groups_path, alert: "Group '#{@group.name}' was scheduled for deletion."
54
55
56
57
58
  end

  private

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

  def group_params
63
    params.require(:group).permit(
64
      :avatar,
65
      :description,
66
67
      :lfs_enabled,
      :name,
68
69
      :path,
      :request_access_enabled,
70
      :visibility_level
71
    )
72
  end
73
end