Class: RbacRls::GroupsController

Inherits:
ApplicationController show all
Includes:
ConnectionRlsUserConcern
Defined in:
app/controllers/rbac_rls/groups_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /groups



26
27
28
29
30
31
32
33
34
# File 'app/controllers/rbac_rls/groups_controller.rb', line 26

def create
  @group = Group.new(group_params)

  if @group.save
    redirect_to @group, notice: "Group was successfully created."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject

DELETE /groups/1



46
47
48
49
# File 'app/controllers/rbac_rls/groups_controller.rb', line 46

def destroy
  @group.destroy
  redirect_to groups_url, notice: "Group was successfully destroyed."
end

#editObject

GET /groups/1/edit



22
23
# File 'app/controllers/rbac_rls/groups_controller.rb', line 22

def edit
end

#get_options_selectObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/rbac_rls/groups_controller.rb', line 51

def get_options_select
  @permission = Permission.find_by(id: params[:permission_object_id])

  if @permission.present?
    attrs = @permission.table_name.singularize.camelize.constantize.new.attributes.keys
    if params[:target_select].to_s.to_sym == :table_key_id

      @collection = [attrs, attrs].transpose.to_h if params[:target_select].to_s.to_sym == :table_key_id

    elsif params[:target_select].to_s.to_sym == :table_value_id
      elements = @permission.table_name.singularize.camelize.constantize.all.map(&params[:permission_id].to_s.to_sym)
      @collection = [elements, elements].transpose.to_h
    end

  end
  render json: @collection.to_h.as_json
end

#indexObject

GET /groups



7
8
9
# File 'app/controllers/rbac_rls/groups_controller.rb', line 7

def index
  @groups = Group.all
end

#newObject

GET /groups/new



16
17
18
19
# File 'app/controllers/rbac_rls/groups_controller.rb', line 16

def new
  @group = Group.new
  @group.group_permissions.build()
end

#showObject

GET /groups/1



12
13
# File 'app/controllers/rbac_rls/groups_controller.rb', line 12

def show
end

#updateObject

PATCH/PUT /groups/1



37
38
39
40
41
42
43
# File 'app/controllers/rbac_rls/groups_controller.rb', line 37

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