Class: LatoSpaces::ApplicationController

Inherits:
Lato::ApplicationController
  • Object
show all
Includes:
Groupable
Defined in:
app/controllers/lato_spaces/application_controller.rb

Direct Known Subclasses

GroupsController, MembershipsController

Instance Method Summary collapse

Methods included from Groupable

#authenticate_group, #session_group_create, #session_group_destroy

Instance Method Details

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/lato_spaces/application_controller.rb', line 9

def index
  @memberships = LatoSpaces::Membership.where(lato_user_id: @session.user_id).order(created_at: :desc)
  @groups = LatoSpaces::Group.joins(:lato_spaces_memberships).where(lato_spaces_memberships: { lato_user_id: @session.user_id }).order(name: :asc)

  if LatoSpaces.config. && LatoSpaces.config.setgroup_redirect_path && @session.get(:spaces_group_id).blank? && @groups.size == 1
    group_id = @groups.first&.id
    if group_id && session_group_create(group_id)
      redirect_to Rails.application.routes.url_helpers.send(LatoSpaces.config.setgroup_redirect_path)
      return
    end
  end

  if LatoSpaces.config. && LatoSpaces.config.setgroup_redirect_path && @session.get(:spaces_group_id).blank?
    group_id = @groups.first&.id
    if group_id && session_group_create(group_id)
      redirect_to Rails.application.routes.url_helpers.send(LatoSpaces.config.setgroup_redirect_path)
      return
    end
  end
end

#setgroupObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/lato_spaces/application_controller.rb', line 30

def setgroup
  success_redirect_path = LatoSpaces.config.setgroup_redirect_path ? Rails.application.routes.url_helpers.send(LatoSpaces.config.setgroup_redirect_path) : lato_spaces.root_path

  respond_to do |format|
    if session_group_create(params[:id])
      format.html { redirect_to success_redirect_path }
      format.json { render json: {} }
    else
      format.html { redirect_to lato_spaces.root_path, alert: 'Error on changing group.' }
      format.json { render json: { error: 'Error on changing group.' }, status: :unprocessable_entity }
    end
  end
end

#setpreferredObject



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/lato_spaces/application_controller.rb', line 44

def setpreferred
  membership = LatoSpaces::Membership.find_by(lato_user_id: @session.user_id, lato_spaces_group_id: params[:id])

  respond_to do |format|
    if membership&.set_preferred
      format.html { redirect_to lato_spaces.root_path }
      format.json { render json: {} }
    else
      format.html { redirect_to lato_spaces.root_path, alert: 'Error on changing preferred group.' }
      format.json { render json: { error: 'Error on changing preferred group.' }, status: :unprocessable_entity }
    end
  end
end