katalyst-koi 4.15.0 → 4.16.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.
@@ -77,7 +77,7 @@ module Admin
77
77
  end
78
78
 
79
79
  def admin_user_params
80
- params.require(:admin).permit(:name, :email, :password, :archived)
80
+ params.expect(admin: %i[name email password archived])
81
81
  end
82
82
 
83
83
  class Collection < Admin::Collection
@@ -64,7 +64,7 @@ module Admin
64
64
  private
65
65
 
66
66
  def credential_params
67
- params.require(:admin_credential).permit(:nickname, :response)
67
+ params.expect(admin_credential: %i[nickname response])
68
68
  end
69
69
 
70
70
  def set_admin_user
@@ -36,7 +36,7 @@ module Admin
36
36
  private
37
37
 
38
38
  def otp_params
39
- params.require(:admin).permit(:otp_secret, :token)
39
+ params.expect(admin: %i[otp_secret token])
40
40
  end
41
41
 
42
42
  def set_admin_user
@@ -102,7 +102,7 @@ module Admin
102
102
  end
103
103
 
104
104
  def session_params
105
- params.require(:admin).permit(:email, :password, :token, :response)
105
+ params.expect(admin: %i[email password token response])
106
106
  end
107
107
 
108
108
  def update_last_sign_in(admin_user)
@@ -52,7 +52,7 @@ module Admin
52
52
  private
53
53
 
54
54
  def url_rewrite_params
55
- params.require(:url_rewrite).permit(:from, :to, :status_code, :active)
55
+ params.expect(url_rewrite: %i[from to status_code active])
56
56
  end
57
57
 
58
58
  def set_url_rewrite
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Admin
4
+ class WellKnownsController < ApplicationController
5
+ before_action :set_well_known, only: %i[show edit update destroy]
6
+
7
+ def index
8
+ collection = Collection.new.with_params(params).apply(::WellKnown.strict_loading.all)
9
+
10
+ render locals: { collection: }
11
+ end
12
+
13
+ def show
14
+ render locals: { well_known: @well_known }
15
+ end
16
+
17
+ def new
18
+ render locals: { well_known: ::WellKnown.new }
19
+ end
20
+
21
+ def edit
22
+ render locals: { well_known: @well_known }
23
+ end
24
+
25
+ def create
26
+ @well_known = ::WellKnown.new(well_known_params)
27
+
28
+ if @well_known.save
29
+ redirect_to [:admin, @well_known], status: :see_other
30
+ else
31
+ render :new, locals: { well_known: @well_known }, status: :unprocessable_content
32
+ end
33
+ end
34
+
35
+ def update
36
+ if @well_known.update(well_known_params)
37
+ redirect_to action: :show, status: :see_other
38
+ else
39
+ render :edit, locals: { well_known: @well_known }, status: :unprocessable_content
40
+ end
41
+ end
42
+
43
+ def destroy
44
+ @well_known.destroy!
45
+
46
+ redirect_to action: :index, status: :see_other
47
+ end
48
+
49
+ private
50
+
51
+ # Only allow a list of trusted parameters through.
52
+ def well_known_params
53
+ params.expect(well_known: %i[name purpose content_type content])
54
+ end
55
+
56
+ # Use callbacks to share common setup or constraints between actions.
57
+ def set_well_known
58
+ @well_known = ::WellKnown.find(params[:id])
59
+ end
60
+
61
+ class Collection < Admin::Collection
62
+ config.sorting = :name
63
+ config.paginate = true
64
+
65
+ attribute :name, :string
66
+ attribute :purpose, :string
67
+ attribute :content_type, :string
68
+ attribute :content, :string
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class WellKnownsController < ApplicationController
4
+ before_action :set_well_known
5
+
6
+ def show
7
+ render renderable: @well_known
8
+ end
9
+
10
+ private
11
+
12
+ def set_well_known
13
+ @well_known = WellKnown.find_by!(name: params[:name])
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ class WellKnown < ApplicationRecord
4
+ CONTENT_TYPES = {
5
+ text: "text/plain",
6
+ json: "application/json",
7
+ }.freeze
8
+
9
+ enum :content_type, CONTENT_TYPES
10
+
11
+ validates :name, :purpose, :content_type, presence: true
12
+ validates :name, uniqueness: { case_sensitive: true }
13
+
14
+ scope :admin_search, ->(query) do
15
+ where(arel_table[:name].matches("%#{query}%"))
16
+ end
17
+
18
+ def render_in(view_context)
19
+ view_context.render(plain: content)
20
+ end
21
+
22
+ def format
23
+ content_type.to_sym
24
+ end
25
+ end
@@ -15,7 +15,8 @@
15
15
  <ol class="flow">
16
16
  <li>Install an MFA app. Most password managers support MFA.</li>
17
17
  <li>Scan this code using your mobile device or password manager:<br>
18
- <%== RQRCode::QRCode.new(admin.otp.provisioning_uri(admin.email)).as_svg(
18
+ <% otp_app_name = t("koi.auth.otp_app_name", host: URI.parse(root_url).host, email: admin.email) %>
19
+ <%== RQRCode::QRCode.new(admin.otp.provisioning_uri(otp_app_name)).as_svg(
19
20
  color: "000",
20
21
  shape_rendering: "crispEdges",
21
22
  module_size: 3,
@@ -0,0 +1,6 @@
1
+ <%= form.govuk_text_field :name %>
2
+ <%= form.govuk_text_field :purpose %>
3
+ <%= form.govuk_collection_radio_buttons(
4
+ :content_type, WellKnown::CONTENT_TYPES, :first, :second, small: true
5
+ ) %>
6
+ <%= form.govuk_text_area :content %>
@@ -0,0 +1,12 @@
1
+ <% content_for :header do %>
2
+ <%= render(Koi::Header::EditComponent.new(resource: well_known)) %>
3
+ <% end %>
4
+
5
+ <%= form_with(model: well_known, url: admin_well_known_path(well_known)) do |form| %>
6
+ <%= render "fields", form: %>
7
+
8
+ <div class="actions">
9
+ <%= form.admin_save %>
10
+ <%= form.admin_delete %>
11
+ </div>
12
+ <% end %>
@@ -0,0 +1,15 @@
1
+ <% content_for :header do %>
2
+ <%= render(Koi::Header::IndexComponent.new(model: WellKnown)) do |component| %>
3
+ <% component.with_action "New", new_admin_well_known_path %>
4
+ <% end %>
5
+ <% end %>
6
+
7
+ <%= table_query_with(collection:) %>
8
+
9
+ <%= table_with(collection:) do |row| %>
10
+ <% row.select %>
11
+ <% row.link :name %>
12
+ <% row.text :purpose %>
13
+ <% end %>
14
+
15
+ <%= table_pagination_with(collection:) %>
@@ -0,0 +1,11 @@
1
+ <% content_for :header do %>
2
+ <%= render(Koi::Header::NewComponent.new(model: WellKnown)) %>
3
+ <% end %>
4
+
5
+ <%= form_with(model: well_known, url: admin_well_knowns_path) do |form| %>
6
+ <%= render "fields", form: %>
7
+
8
+ <div class="actions">
9
+ <%= form.admin_save %>
10
+ </div>
11
+ <% end %>
@@ -0,0 +1,19 @@
1
+ <% content_for :header do %>
2
+ <%= render(Koi::Header::ShowComponent.new(resource: well_known)) %>
3
+ <% end %>
4
+
5
+ <h2>Summary</h2>
6
+
7
+ <%= summary_table_with(model: well_known) do |row| %>
8
+ <% row.link :name %>
9
+ <% row.text :purpose %>
10
+ <% row.text :content_type %>
11
+ <% row.text :content %>
12
+ <% end %>
13
+
14
+ <div class="actions">
15
+ <%= button_to "Delete", admin_well_known_path(well_known),
16
+ class: "button button--secondary",
17
+ method: :delete,
18
+ form: { data: { turbo_confirm: "Are you sure?" } } %>
19
+ </div>
@@ -9,6 +9,7 @@ en:
9
9
  admin: "%e %B %Y"
10
10
  koi:
11
11
  auth:
12
+ otp_app_name: "%{host}/admin"
12
13
  token_invalid: "Token invalid or consumed already"
13
14
  token_consumed: "Please create a password or passkey"
14
15
  labels:
data/config/routes.rb CHANGED
@@ -7,7 +7,6 @@ Rails.application.routes.draw do
7
7
  resources :tokens, param: :token, only: %i[show update], token: /[^\/]+/
8
8
  end
9
9
 
10
- resources :url_rewrites
11
10
  resources :admin_users do
12
11
  resources :credentials, only: %i[new create destroy]
13
12
  resource :otp, only: %i[new create destroy]
@@ -19,6 +18,8 @@ Rails.application.routes.draw do
19
18
 
20
19
  resource :cache, only: %i[destroy]
21
20
  resource :dashboard, only: %i[show]
21
+ resources :well_knowns
22
+ resources :url_rewrites
22
23
 
23
24
  root to: redirect("admin/dashboard")
24
25
  end
@@ -28,4 +29,6 @@ Rails.application.routes.draw do
28
29
  mount Katalyst::Navigation::Engine, at: "navigation"
29
30
  mount Flipper::UI.app(Flipper) => "flipper" if Object.const_defined?("Flipper::UI")
30
31
  end
32
+
33
+ resources :well_knowns, path: ".well-known", param: :name, only: %i[show], name: /[^\/]+/
31
34
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateWellKnowns < ActiveRecord::Migration[8.0]
4
+ def change
5
+ create_table :well_knowns do |t|
6
+ t.string :name, index: { unique: true }
7
+ t.string :purpose
8
+ t.string :content_type
9
+ t.string :content
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -50,9 +50,9 @@ class <%= controller_class_name %>Controller < ApplicationController
50
50
  # Only allow a list of trusted parameters through.
51
51
  def <%= "#{singular_table_name}_params" %>
52
52
  <%- if attributes_names.empty? -%>
53
- params.fetch(:<%= singular_table_name %>, {})
53
+ params.expect(<%= singular_table_name %>: [])
54
54
  <%- else -%>
55
- params.require(:<%= singular_table_name %>).permit(<%= permitted_params %>)
55
+ params.expect(<%= singular_table_name %>: [<%= permitted_params %>])
56
56
  <%- end -%>
57
57
  end
58
58
 
@@ -9,4 +9,5 @@ Koi::Menu.modules = {
9
9
  Koi::Menu.advanced = {
10
10
  "Admin Users" => "/admin/admin_users",
11
11
  "URL Rewriter" => "/admin/url_rewrites",
12
+ "Well Knowns" => "/admin/well_knowns",
12
13
  }
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :well_known do
5
+ name { Faker::Internet.base64 }
6
+ purpose { Faker::Lorem.sentence }
7
+ content_type { :text }
8
+ content { Faker::Internet.base64 }
9
+ end
10
+ end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katalyst-koi
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.15.0
4
+ version: 4.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katalyst Interactive
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-16 00:00:00.000000000 Z
10
+ date: 2025-02-04 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rails
@@ -234,7 +233,6 @@ dependencies:
234
233
  - - ">="
235
234
  - !ruby/object:Gem::Version
236
235
  version: '3.5'
237
- description:
238
236
  email:
239
237
  - developers@katalyst.com.au
240
238
  executables: []
@@ -375,11 +373,13 @@ files:
375
373
  - app/controllers/admin/sessions_controller.rb
376
374
  - app/controllers/admin/tokens_controller.rb
377
375
  - app/controllers/admin/url_rewrites_controller.rb
376
+ - app/controllers/admin/well_knowns_controller.rb
378
377
  - app/controllers/concerns/koi/controller/has_admin_users.rb
379
378
  - app/controllers/concerns/koi/controller/has_attachments.rb
380
379
  - app/controllers/concerns/koi/controller/has_webauthn.rb
381
380
  - app/controllers/concerns/koi/controller/is_admin_controller.rb
382
381
  - app/controllers/concerns/koi/controller/json_web_token.rb
382
+ - app/controllers/well_knowns_controller.rb
383
383
  - app/helpers/koi/application_helper.rb
384
384
  - app/helpers/koi/date_helper.rb
385
385
  - app/helpers/koi/definition_list_helper.rb
@@ -394,6 +394,7 @@ files:
394
394
  - app/models/concerns/koi/model/archivable.rb
395
395
  - app/models/concerns/koi/model/otp.rb
396
396
  - app/models/url_rewrite.rb
397
+ - app/models/well_known.rb
397
398
  - app/views/admin/admin_users/_fields.html+self.erb
398
399
  - app/views/admin/admin_users/_fields.html.erb
399
400
  - app/views/admin/admin_users/archived.html.erb
@@ -425,6 +426,11 @@ files:
425
426
  - app/views/admin/url_rewrites/index.html.erb
426
427
  - app/views/admin/url_rewrites/new.html.erb
427
428
  - app/views/admin/url_rewrites/show.html.erb
429
+ - app/views/admin/well_knowns/_fields.html.erb
430
+ - app/views/admin/well_knowns/edit.html.erb
431
+ - app/views/admin/well_knowns/index.html.erb
432
+ - app/views/admin/well_knowns/new.html.erb
433
+ - app/views/admin/well_knowns/show.html.erb
428
434
  - app/views/katalyst/content/asides/_aside.html+form.erb
429
435
  - app/views/katalyst/content/columns/_column.html+form.erb
430
436
  - app/views/katalyst/content/contents/_content.html+form.erb
@@ -465,6 +471,7 @@ files:
465
471
  - db/migrate/20230602033610_add_archived_to_admin_users.rb
466
472
  - db/migrate/20231211005214_add_status_code_to_url_rewrites.rb
467
473
  - db/migrate/20241214060913_add_otp_secret_to_admin_users.rb
474
+ - db/migrate/20250204060748_create_well_knowns.rb
468
475
  - db/seeds.rb
469
476
  - lib/generators/koi/active_record/active_record_generator.rb
470
477
  - lib/generators/koi/admin/USAGE
@@ -504,12 +511,12 @@ files:
504
511
  - lib/koi/release.rb
505
512
  - spec/factories/admins.rb
506
513
  - spec/factories/url_rewrites.rb
514
+ - spec/factories/well_knowns.rb
507
515
  homepage: https://github.com/katalyst/koi
508
516
  licenses:
509
517
  - MIT
510
518
  metadata:
511
519
  rubygems_mfa_required: 'true'
512
- post_install_message:
513
520
  rdoc_options: []
514
521
  require_paths:
515
522
  - lib
@@ -524,8 +531,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
524
531
  - !ruby/object:Gem::Version
525
532
  version: '0'
526
533
  requirements: []
527
- rubygems_version: 3.5.22
528
- signing_key:
534
+ rubygems_version: 3.6.2
529
535
  specification_version: 4
530
536
  summary: Koi CMS admin framework
531
537
  test_files: []