self-auth-rails 0.1.1 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7bf53acb259dc5c315fcf6222d30d099a3c95ada6b9bacb5d51554d8dc6ec08
4
- data.tar.gz: 7d0fb909e65049f4f3ae8a16ccb15d0f82510a8d1f03bab09b84b4187aad37b2
3
+ metadata.gz: bf781d804c0ffa2b64e556ee4e4ff2ae9dd7779238270f07fc52a1195d248919
4
+ data.tar.gz: e14c79f5e3707d3746bb68cab347e3188ca7b87a6953baebf550bd128a1e6a8b
5
5
  SHA512:
6
- metadata.gz: 51c1afac76389b629e41e293dd2e1d21826e3629602b3f7a770073a1731168cec1ccec7a66cdcf1a5c61c8d87b8772b9ee28302b6b3296cd92ad2fbe2c1ed477
7
- data.tar.gz: 10e87468d332a8106727f5ecb2c75eab382163df0fbe5468d91dbc11e3a69fcb2fd4e7befdd01a089c8dae1024ef3183b79ceb1a1e295f457ee075e8dde0e61c
6
+ metadata.gz: 82878606f3c836b1be735efd255b0fb2dcae4367f63eaf183a3bf30185666be9b23c361d25b296ccae037377b1c63b3444ca0a790721e2c2a80f0c43be7cd0be
7
+ data.tar.gz: 461433464dfd4c7202c2b711257935a181326eea40c8f6561c18b2c531ecf2a99dc9ff787fccbab75d48910d62c5ffbc071e3de2c8b890c6a172340ea782b552
@@ -1,11 +1,15 @@
1
1
  /* Initialize app when page loads */
2
2
  $(function(){
3
+ if(App.cable.subscriptions.subscriptions.length > 0) {
4
+ if(App.cable.subscriptions.subscriptions[0].identifier.includes("MessagesChannel")) {
5
+ return
6
+ }
7
+ }
3
8
  var Messages = App.cable.subscriptions.create({
4
9
  channel:'MessagesChannel',
5
10
  conversation_id: connectionID()
6
11
  }, {
7
12
  received: function(data) {
8
- console.log(data);
9
13
  if(data.type == "info") {
10
14
  if(data.status == "completed") {
11
15
  console.log("info request");
@@ -16,7 +20,13 @@ $(function(){
16
20
  message = data.message
17
21
  }
18
22
  // TODO: this id no longer exists...
19
- $('#info_messages').append("<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>'+message+'</div>");
23
+ document.querySelector('#info_messages').insertAdjacentHTML(
24
+ 'afterbegin',
25
+ `<div class='alert alert-danger'>
26
+ <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
27
+ ${message}
28
+ </div>`
29
+ )
20
30
  }
21
31
  } else {
22
32
  $("#messages").removeClass('hidden');
@@ -67,9 +77,12 @@ $(function(){
67
77
  if(data.status == "errored") {
68
78
  message = data.message
69
79
  }
70
- $('#messages').append(`<div class="alert alert-warning alert-dismissible show fade"><div class="alert-body"><button class="close" data-dismiss="alert"><span>×</span></button>${message}</div></div>`);
80
+ document.querySelector('#info_messages').insertAdjacentHTML(
81
+ 'afterbegin',
82
+ `<div class="alert alert-warning alert-dismissible show fade"><div class="alert-body"><button class="close" data-dismiss="alert"><span>×</span></button>${message}</div></div>`
83
+ )
71
84
 
72
- $('#messages').show();
85
+ $('#info_messages').show();
73
86
  $('#process').addClass("hidden");
74
87
  $('#non-dl-container').removeClass("hidden");
75
88
 
@@ -105,9 +105,16 @@ function uuidv4() {
105
105
  },
106
106
  error: function (e) {
107
107
  if(e.status == 502) {
108
- $('#info_messages').append("<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>Request timed out, try again later</div>");
108
+ document.querySelector('#info_messages').insertAdjacentHTML(
109
+ 'afterbegin',
110
+ `<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>Request timed out, try again later</div>`
111
+ )
112
+
109
113
  } else {
110
- $('#info_messages').append("<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>"+e.responseJSON.error+"</div>");
114
+ document.querySelector('#info_messages').insertAdjacentHTML(
115
+ 'afterbegin',
116
+ `<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>${e.responseJSON.error}</div>`
117
+ )
111
118
  }
112
119
  $("#profile_help_block").hide();
113
120
  }
@@ -1,4 +1,5 @@
1
1
  module SelfAuthRails
2
2
  class ApplicationController < ::ApplicationController
3
+ layout SelfAuthRails.layout
3
4
  end
4
5
  end
@@ -1,5 +1,5 @@
1
1
  module SelfAuthRails
2
- class SessionsController < ::ApplicationController
2
+ class SessionsController < ApplicationController
3
3
  def new; end
4
4
 
5
5
  # Authenticates a user with the given token
@@ -1,14 +1,14 @@
1
1
  module SelfAuthRails
2
2
  module ApplicationHelper
3
3
  def authenticate_user!
4
- current_url = request.base_url + request.path
4
+ current_url = URI(request.base_url + request.path).request_uri
5
5
 
6
6
  uri = URI(main_app.root_url)
7
7
 
8
- new_url = SelfAuthRails::Engine.routes.url_helpers.new_url(host: uri.host, port: uri.port)
9
- create_url = SelfAuthRails::Engine.routes.url_helpers.create_url(host: uri.host, port: uri.port)
10
- qr_url = SelfAuthRails::Engine.routes.url_helpers.qr_url(host: uri.host, port: uri.port)
11
- dl_url = SelfAuthRails::Engine.routes.url_helpers.dl_url(host: uri.host, port: uri.port)
8
+ new_url = URI(SelfAuthRails::Engine.routes.url_helpers.new_url(host: uri.host, port: uri.port)).request_uri
9
+ create_url = URI(SelfAuthRails::Engine.routes.url_helpers.create_url(host: uri.host, port: uri.port)).request_uri
10
+ qr_url = URI(SelfAuthRails::Engine.routes.url_helpers.qr_url(host: uri.host, port: uri.port)).request_uri
11
+ dl_url = URI(SelfAuthRails::Engine.routes.url_helpers.dl_url(host: uri.host, port: uri.port)).request_uri
12
12
 
13
13
  if [new_url, create_url, qr_url, dl_url].include? current_url
14
14
  redirect_to root_url unless current_user.nil?
@@ -27,7 +27,7 @@ class SelfAuthResponseManagerService
27
27
  return
28
28
  end
29
29
 
30
- unless admin?(self_auth_response.from)
30
+ unless SelfAuthRails.permitted_auth.call(self_auth_response.from)
31
31
  broadcast_status_change channel, STATUS_ERR, message: 'You are forbidden to access this service'
32
32
  return
33
33
  end
@@ -69,8 +69,4 @@ class SelfAuthResponseManagerService
69
69
  @broadcaster.broadcast channel, { status: status, token: token, message: message, type: type }
70
70
  end
71
71
 
72
- # checks if the given id is in the admins list
73
- def admin?(id)
74
- ENV['ADMIN_IDS'].split(',').include? id
75
- end
76
72
  end
@@ -12,6 +12,7 @@
12
12
  <div class="col-12 col-sm-8 offset-sm-2 col-md-6 offset-md-3 col-lg-6 offset-lg-3 col-xl-6 offset-xl-3">
13
13
  <div class="card card-primary">
14
14
  <div class="card-body">
15
+ <div id="info_messages"></div>
15
16
 
16
17
  <div id="dl-container" class="hidden">
17
18
  <div class="col-xs-12">
@@ -1,3 +1,3 @@
1
1
  module SelfAuthRails
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -7,7 +7,9 @@ module SelfAuthRails
7
7
  :auth_facts,
8
8
  :fact_mapping,
9
9
  :authenticated_path,
10
- :authenticated_path
10
+ :authenticated_path,
11
+ :layout,
12
+ :permitted_auth
11
13
 
12
14
  class Engine < ::Rails::Engine
13
15
  default_auth_facts = [:display_name]
@@ -17,6 +19,9 @@ module SelfAuthRails
17
19
  unless SelfAuthRails::self_client.nil?
18
20
  SelfAuthRails.auth_facts ||= default_auth_facts
19
21
  SelfAuthRails.authenticated_path ||= default_authenticated_path
22
+ if SelfAuthRails.permitted_auth.nil?
23
+ SelfAuthRails.permitted_auth ||= Proc.new { |selfid| true }
24
+ end
20
25
 
21
26
  response_manager = SelfAuthResponseManagerService.new(ActionCable.server)
22
27
 
@@ -43,8 +48,4 @@ module SelfAuthRails
43
48
  yield self
44
49
  end
45
50
 
46
- def authenticated_path
47
- SelfAuthRails::authenticated_path || SelfAuthRails::default_authenticated_path
48
- end
49
-
50
51
  end
@@ -34,6 +34,9 @@ if defined?(Rails::Server) && !defined?(::SelfClient)
34
34
  # Optional entry defaulting to '/'.
35
35
  config.authenticated_path = '/'
36
36
 
37
+ # Defines the layout to be used for the authentication page.
38
+ # config.layout = 'login'
39
+
37
40
  # In case you want to persist the authentication returning facts, you
38
41
  # can provide a map for the fact_name and the ActiveModel object property.
39
42
  #
@@ -41,5 +44,11 @@ if defined?(Rails::Server) && !defined?(::SelfClient)
41
44
  # to request and store facts during the authentication process with
42
45
  # config.auth_facts
43
46
  config.fact_mapping = { display_name: :name }
47
+
48
+ # Defines if a given user is permitted to access the service or not.
49
+ # config.permitted_auth = Proc.new do |selfid|
50
+ # true
51
+ # end
52
+
44
53
  end
45
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: self-auth-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrià Cidre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-11 00:00:00.000000000 Z
11
+ date: 2022-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails