Module: Printos::Helpers

Defined in:
lib/printos/helpers.rb

Instance Method Summary collapse

Instance Method Details

#authorizationObject



4
5
6
# File 'lib/printos/helpers.rb', line 4

def authorization
  @authorization ||= PrintosClient.get_instance.authorization
end

#check_admin_permissionObject



16
17
18
# File 'lib/printos/helpers.rb', line 16

def check_admin_permission
  redirect_to  unless has_admin_permission?
end

#has_admin_permission?Boolean



12
13
14
# File 'lib/printos/helpers.rb', line 12

def has_admin_permission?
  user_permissions&.include?('admin')
end

#printos_loginObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/printos/helpers.rb', line 20

def 
  authenticated = false
  token = cookies[Printos.config.auth_token_key]
  if token
    begin
      PrintosClient.set_instance(token)
      authenticated = user_permissions.any?
    rescue RestClient::Unauthorized
    end
  end
  unless authenticated
    if request.format.json?
      render json: '', status: 401, head: :no_content
    else
      redirect_to 
    end
  end
end

#signin_urlObject



39
40
41
# File 'lib/printos/helpers.rb', line 39

def 
  "#{Printos.config.api_host}/start/#/signin"
end

#user_permissionsObject



8
9
10
# File 'lib/printos/helpers.rb', line 8

def user_permissions
  @permissions ||= authorization[:permissions]&.map { |p| p[:name] }
end