katalyst-koi 5.13.2 → 5.14.0
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 +4 -4
- data/app/controllers/admin/admin_users/tokens_controller.rb +23 -0
- data/app/controllers/admin/device_authorizations_controller.rb +1 -0
- data/app/controllers/admin/sessions/tokens_controller.rb +0 -12
- data/config/routes.rb +1 -1
- data/lib/koi/engine.rb +4 -0
- data/lib/koi/middleware/admin_authentication.rb +30 -2
- data/lib/koi.rb +4 -0
- metadata +3 -2
- /data/app/views/admin/{sessions → admin_users}/tokens/create.turbo_stream.erb +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: df490eb333aaf872c96befe936bdaa567a3d20fa771ca166f4567990e6a1a25a
|
|
4
|
+
data.tar.gz: 15302cc1fa2f1b44db376c2d87a7082703115f729bb47d95d75ac442dcb07969
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 89e7a44277988d785ce2080623d155efb855efabb97e53ba50ce3761cbbf3f8c95a64ff91efea1aefaa8daca8f3184bd1c2441e06c19f49b9c2fe67aa48a26fc
|
|
7
|
+
data.tar.gz: d3b5ffeee0b3a8f95de7053c667a7f139bcae1e28094716cbe8c11ed7a24465268c744eca206b31bdb7aebb11579555dfa1f60914bc5ffecdf07b18028531ccd
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Admin
|
|
4
|
+
module AdminUsers
|
|
5
|
+
# Generates a login link that signs in as the given admin user.
|
|
6
|
+
class TokensController < ApplicationController
|
|
7
|
+
before_action :requires_session_authentication!
|
|
8
|
+
before_action :set_admin_user
|
|
9
|
+
|
|
10
|
+
attr_reader :admin_user
|
|
11
|
+
|
|
12
|
+
def create
|
|
13
|
+
render locals: { token: admin_user.generate_token_for(:password_reset) }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def set_admin_user
|
|
19
|
+
@admin_user = Admin::User.find(params.expect(:admin_user_id))
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -8,6 +8,7 @@ module Admin
|
|
|
8
8
|
rate_limit to: 3, within: 1.minute, only: :create
|
|
9
9
|
skip_before_action :verify_authenticity_token, only: :create
|
|
10
10
|
|
|
11
|
+
before_action :requires_session_authentication!, only: %i[show update]
|
|
11
12
|
before_action :set_device_authorization, only: %i[show update]
|
|
12
13
|
|
|
13
14
|
attr_reader :device_authorization
|
|
@@ -5,8 +5,6 @@ module Admin
|
|
|
5
5
|
class TokensController < ApplicationController
|
|
6
6
|
include Koi::Controller::RecordsAuthentication
|
|
7
7
|
|
|
8
|
-
before_action :set_admin_user, only: %i[create]
|
|
9
|
-
|
|
10
8
|
attr_reader :admin_user
|
|
11
9
|
|
|
12
10
|
def show
|
|
@@ -17,10 +15,6 @@ module Admin
|
|
|
17
15
|
end
|
|
18
16
|
end
|
|
19
17
|
|
|
20
|
-
def create
|
|
21
|
-
render locals: { token: admin_user.generate_token_for(:password_reset) }
|
|
22
|
-
end
|
|
23
|
-
|
|
24
18
|
def update
|
|
25
19
|
if (@admin_user = Admin::User.find_by_token_for(:password_reset, params[:token]))
|
|
26
20
|
create_admin_session!(admin_user)
|
|
@@ -34,12 +28,6 @@ module Admin
|
|
|
34
28
|
redirect_to(new_admin_session_path, status: :see_other, notice: I18n.t("koi.auth.token_invalid"))
|
|
35
29
|
end
|
|
36
30
|
end
|
|
37
|
-
|
|
38
|
-
private
|
|
39
|
-
|
|
40
|
-
def set_admin_user
|
|
41
|
-
@admin_user = Admin::User.find(params.expect(:admin_user_id))
|
|
42
|
-
end
|
|
43
31
|
end
|
|
44
32
|
end
|
|
45
33
|
end
|
data/config/routes.rb
CHANGED
|
@@ -7,7 +7,7 @@ Rails.application.routes.draw do
|
|
|
7
7
|
put :archive, on: :collection
|
|
8
8
|
put :restore, on: :collection
|
|
9
9
|
|
|
10
|
-
resources :tokens, only: %i[create], module: :
|
|
10
|
+
resources :tokens, only: %i[create], module: :admin_users
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
resources :admin_roles, only: %i[index show]
|
data/lib/koi/engine.rb
CHANGED
|
@@ -79,6 +79,10 @@ module Koi
|
|
|
79
79
|
Katalyst::Content.config.errors_component = "Koi::Content::Editor::ErrorsComponent"
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
+
initializer "koi.deprecator" do |app|
|
|
83
|
+
app.deprecators[:koi] = Koi.deprecator
|
|
84
|
+
end
|
|
85
|
+
|
|
82
86
|
initializer "koi.factories", after: "factory_bot.set_factory_paths" do
|
|
83
87
|
FactoryBot.definition_file_paths << root.join("spec/factories") if defined?(FactoryBot)
|
|
84
88
|
end
|
|
@@ -8,7 +8,7 @@ module Koi
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def call(env)
|
|
11
|
-
if env["PATH_INFO"]
|
|
11
|
+
if admin_path?(env["PATH_INFO"])
|
|
12
12
|
admin_call(env)
|
|
13
13
|
else
|
|
14
14
|
@app.call(env)
|
|
@@ -43,8 +43,36 @@ module Koi
|
|
|
43
43
|
|
|
44
44
|
private
|
|
45
45
|
|
|
46
|
+
# Compare paths the way the router will see them, e.g. "//admin" routes to "/admin"
|
|
47
|
+
def normalize_path(path)
|
|
48
|
+
ActionDispatch::Journey::Router::Utils.normalize_path(path)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def admin_path?(path)
|
|
52
|
+
path = normalize_path(path)
|
|
53
|
+
|
|
54
|
+
return false unless path.starts_with?("/admin")
|
|
55
|
+
|
|
56
|
+
unless path == "/admin" || path.starts_with?("/admin/")
|
|
57
|
+
Koi.deprecator.warn(
|
|
58
|
+
"#{path.inspect} is authenticated as an admin path because it starts with \"/admin\". " \
|
|
59
|
+
"Koi 6.0 will only authenticate \"/admin\" and paths under \"/admin/\". " \
|
|
60
|
+
"Move the route under \"/admin/\" to keep it protected.",
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
true
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# The session resource and its nested routes, e.g. "/admin/session", "/admin/session/new".
|
|
68
|
+
def session_path?(path)
|
|
69
|
+
path = normalize_path(path)
|
|
70
|
+
|
|
71
|
+
path == "/admin/session" || path.starts_with?("/admin/session/")
|
|
72
|
+
end
|
|
73
|
+
|
|
46
74
|
def requires_authentication?(request)
|
|
47
|
-
!request.path
|
|
75
|
+
!session_path?(request.path) && !device_flow_request?(request:)
|
|
48
76
|
end
|
|
49
77
|
|
|
50
78
|
def authenticated?
|
data/lib/koi.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: katalyst-koi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 5.
|
|
4
|
+
version: 5.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Katalyst Interactive
|
|
@@ -355,6 +355,7 @@ files:
|
|
|
355
355
|
- app/components/koi/tables/table_component.rb
|
|
356
356
|
- app/controllers/admin/active_storage/direct_uploads_controller.rb
|
|
357
357
|
- app/controllers/admin/admin_roles_controller.rb
|
|
358
|
+
- app/controllers/admin/admin_users/tokens_controller.rb
|
|
358
359
|
- app/controllers/admin/admin_users_controller.rb
|
|
359
360
|
- app/controllers/admin/application_controller.rb
|
|
360
361
|
- app/controllers/admin/background_jobs_controller.rb
|
|
@@ -432,6 +433,7 @@ files:
|
|
|
432
433
|
- app/views/admin/admin_users/index.html.erb
|
|
433
434
|
- app/views/admin/admin_users/new.html.erb
|
|
434
435
|
- app/views/admin/admin_users/show.html.erb
|
|
436
|
+
- app/views/admin/admin_users/tokens/create.turbo_stream.erb
|
|
435
437
|
- app/views/admin/background_jobs/_navigation.html.erb
|
|
436
438
|
- app/views/admin/background_jobs/blocked.html.erb
|
|
437
439
|
- app/views/admin/background_jobs/completed.html.erb
|
|
@@ -459,7 +461,6 @@ files:
|
|
|
459
461
|
- app/views/admin/sessions/new.html.erb
|
|
460
462
|
- app/views/admin/sessions/otp.html.erb
|
|
461
463
|
- app/views/admin/sessions/password.html.erb
|
|
462
|
-
- app/views/admin/sessions/tokens/create.turbo_stream.erb
|
|
463
464
|
- app/views/admin/sessions/tokens/show.html.erb
|
|
464
465
|
- app/views/admin/shared/icons/_close.html.erb
|
|
465
466
|
- app/views/admin/shared/icons/_cross.html.erb
|
|
File without changes
|