Read about our upcoming Code of Conduct on this issue

groups_controller.rb 1.84 KB
Newer Older
1
class Admin::GroupsController < Admin::ApplicationController
Markus Koller's avatar
Markus Koller committed
2
  before_action :group, only: [:edit, :update, :destroy, :project_update, :members_update]
3
4

  def index
Markus Koller's avatar
Markus Koller committed
5
    @groups = Group.with_statistics
6
    @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
Markus Koller's avatar
Markus Koller committed
12
    @group = Group.with_statistics.find_by_full_path(params[:id])
13
    @members = @group.members.order("access_level DESC").page(params[:members_page])
Rémy Coutable's avatar
Rémy Coutable committed
14
    @requesters = AccessRequestsFinder.new(@group).execute(current_user)
Markus Koller's avatar
Markus Koller committed
15
    @projects = @group.projects.with_statistics.page(params[:projects_page])
16
17
18
19
20
21
22
23
24
25
  end

  def new
    @group = Group.new
  end

  def edit
  end

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

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

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

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

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

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

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

  private

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

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