Module: Printos::Helpers
- Defined in:
- lib/printos/helpers.rb
Instance Method Summary collapse
- #authorization ⇒ Object
- #check_admin_permission ⇒ Object
- #has_admin_permission? ⇒ Boolean
- #printos_login ⇒ Object
- #signin_url ⇒ Object
- #user_permissions ⇒ Object
Instance Method Details
#authorization ⇒ Object
4 5 6 |
# File 'lib/printos/helpers.rb', line 4 def @authorization ||= PrintosClient.get_instance. end |
#check_admin_permission ⇒ Object
16 17 18 |
# File 'lib/printos/helpers.rb', line 16 def redirect_to signin_url unless end |
#has_admin_permission? ⇒ Boolean
12 13 14 |
# File 'lib/printos/helpers.rb', line 12 def &.include?('admin') end |
#printos_login ⇒ Object
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 printos_login authenticated = false token = [Printos.config.auth_token_key] if token begin PrintosClient.set_instance(token) authenticated = .any? rescue RestClient::Unauthorized end end unless authenticated if request.format.json? render json: '', status: 401, head: :no_content else redirect_to signin_url end end end |
#signin_url ⇒ Object
39 40 41 |
# File 'lib/printos/helpers.rb', line 39 def signin_url "#{Printos.config.api_host}/start/#/signin" end |
#user_permissions ⇒ Object
8 9 10 |
# File 'lib/printos/helpers.rb', line 8 def @permissions ||= [:permissions]&.map { |p| p[:name] } end |