Class: Nquery::Admin::GroupsController

Inherits:
BaseController show all
Defined in:
app/controllers/nquery/admin/groups_controller.rb

Constant Summary

Constants included from Nquery::AuthorizesCollection

Nquery::AuthorizesCollection::COLLECTION_REQUIREMENTS

Instance Method Summary collapse

Methods included from Breadcrumbs

#breadcrumbs, #set_breadcrumbs

Instance Method Details

#add_memberObject



40
41
42
43
44
# File 'app/controllers/nquery/admin/groups_controller.rb', line 40

def add_member
  user = User.find(params[:user_id])
  @group.group_memberships.find_or_create_by!(user: user)
  redirect_to admin_group_path(@group), notice: "#{user.name} added to group."
end

#createObject



20
21
22
23
24
25
26
27
# File 'app/controllers/nquery/admin/groups_controller.rb', line 20

def create
  @group = Group.new(group_params.merge(system_group: "custom"))
  if @group.save
    redirect_to admin_groups_path, notice: "Group created."
  else
    render :new, status: :unprocessable_content
  end
end

#editObject



29
30
# File 'app/controllers/nquery/admin/groups_controller.rb', line 29

def edit
end

#indexObject



8
9
10
# File 'app/controllers/nquery/admin/groups_controller.rb', line 8

def index
  @groups = Group.includes(:users).order(:name)
end

#newObject



16
17
18
# File 'app/controllers/nquery/admin/groups_controller.rb', line 16

def new
  @group = Group.new
end

#remove_memberObject



46
47
48
49
50
# File 'app/controllers/nquery/admin/groups_controller.rb', line 46

def remove_member
  membership = @group.group_memberships.find_by!(user_id: params[:user_id])
  membership.destroy unless @group.system_group == "all_users"
  redirect_to admin_group_path(@group), notice: "Member removed."
end

#showObject



12
13
14
# File 'app/controllers/nquery/admin/groups_controller.rb', line 12

def show
  @available_users = User.active.where.not(id: @group.user_ids).order(:email)
end

#updateObject



32
33
34
35
36
37
38
# File 'app/controllers/nquery/admin/groups_controller.rb', line 32

def update
  if @group.update(group_params)
    redirect_to admin_groups_path, notice: "Group updated."
  else
    render :edit, status: :unprocessable_content
  end
end