comfy_middle_seat 4.5.0 → 4.7.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/.github/workflows/rubyonrails.yml +21 -4
- data/CHANGELOG.md +31 -1
- data/README.md +41 -1
- data/app/assets/javascripts/comfy/admin/cms/diff.js +178 -10
- data/app/assets/stylesheets/comfy/admin/cms/base.sass +88 -0
- data/app/assets/stylesheets/comfy/admin/cms/harbor.sass +4 -0
- data/app/controllers/comfy/admin/cms/snippets_controller.rb +9 -0
- data/app/controllers/comfy/admin/cms/tag_usage_controller.rb +20 -0
- data/app/helpers/comfy/admin/cms/tag_usage_helper.rb +21 -0
- data/app/models/comfy/cms/layout.rb +1 -1
- data/app/views/comfy/admin/cms/revisions/show.html.haml +44 -35
- data/app/views/comfy/admin/cms/snippets/_usage.html.haml +8 -0
- data/app/views/comfy/admin/cms/snippets/edit.html.haml +6 -0
- data/app/views/comfy/admin/cms/snippets/index.html.haml +18 -10
- data/app/views/comfy/admin/cms/tag_usage/_source.html.haml +2 -0
- data/app/views/comfy/admin/cms/tag_usage/index.html.haml +54 -0
- data/app/views/layouts/comfy/admin/cms/_left.html.haml +3 -0
- data/config/initializers/comfy_middle_seat.rb +3 -3
- data/config/locales/ar.yml +23 -0
- data/config/locales/ca.yml +23 -0
- data/config/locales/cs.yml +23 -0
- data/config/locales/da.yml +23 -0
- data/config/locales/de.yml +23 -0
- data/config/locales/en.yml +23 -0
- data/config/locales/es.yml +23 -0
- data/config/locales/fi.yml +23 -0
- data/config/locales/fr.yml +23 -0
- data/config/locales/gr.yml +23 -0
- data/config/locales/hr.yml +23 -0
- data/config/locales/it.yml +23 -0
- data/config/locales/ja.yml +23 -0
- data/config/locales/nb.yml +23 -0
- data/config/locales/nl.yml +23 -0
- data/config/locales/pl.yml +23 -0
- data/config/locales/pt-BR.yml +23 -0
- data/config/locales/ru.yml +23 -0
- data/config/locales/sk.yml +23 -0
- data/config/locales/sv.yml +23 -0
- data/config/locales/tr.yml +23 -0
- data/config/locales/uk.yml +23 -0
- data/config/locales/zh-CN.yml +23 -0
- data/config/locales/zh-TW.yml +23 -0
- data/lib/comfy_middle_seat/configuration.rb +3 -3
- data/lib/comfy_middle_seat/content/snippet_usage.rb +44 -0
- data/lib/comfy_middle_seat/content/tag_usage.rb +129 -0
- data/lib/comfy_middle_seat/content/tag_usage_report.rb +83 -0
- data/lib/comfy_middle_seat/content/tags/helper.rb +1 -1
- data/lib/comfy_middle_seat/content/tags/mixins/file_content.rb +6 -10
- data/lib/comfy_middle_seat/content.rb +3 -0
- data/lib/comfy_middle_seat/routing.rb +1 -0
- data/lib/comfy_middle_seat/version.rb +1 -1
- data/lib/tasks/cms_tag_usage.rake +32 -0
- metadata +10 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
class ComfyMiddleSeat::Content::TagUsageReport
|
|
6
|
+
KINDS = %w[partial helper template].freeze
|
|
7
|
+
STATUSES = {
|
|
8
|
+
'explicitly_allowed' => 'Explicitly allowed',
|
|
9
|
+
'allowed_by_default' => 'Allowed by default',
|
|
10
|
+
'blocked' => 'Blocked'
|
|
11
|
+
}.freeze
|
|
12
|
+
|
|
13
|
+
def initialize(report)
|
|
14
|
+
@report = report
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def json
|
|
18
|
+
JSON.pretty_generate(@report)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def text
|
|
22
|
+
lines = [
|
|
23
|
+
"Tag usage — #{scope}",
|
|
24
|
+
"Sites: #{@report[:sites].map { |site| site[:identifier].inspect }.join(', ')}",
|
|
25
|
+
"Sources scanned: #{@report[:source_count]}",
|
|
26
|
+
@report[:complete] ? 'Scan complete.' : 'Scan incomplete; review warnings.',
|
|
27
|
+
'Counts are saved source fields, not runtime executions.'
|
|
28
|
+
]
|
|
29
|
+
KINDS.each do |kind|
|
|
30
|
+
lines << "\n#{kind.capitalize}s"
|
|
31
|
+
entries = entries_for(kind)
|
|
32
|
+
lines << ' No matching tags found.' if entries.empty?
|
|
33
|
+
entries.each do |entry|
|
|
34
|
+
lines << " #{entry[:name].inspect} — #{STATUSES.fetch(entry[:status])} — #{entry[:sources].size} source(s)"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
"#{lines.join("\n")}\n"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def config
|
|
41
|
+
lines = [
|
|
42
|
+
'# Candidate allowlists only. Review every name before applying.',
|
|
43
|
+
'# Discovery is not security approval; blocked names are included.',
|
|
44
|
+
'# Replacing allowlists blocks omitted names, including existing approved uses.',
|
|
45
|
+
"# Scope: #{scope}. Sites: #{@report[:sites].map { |site| site[:identifier].inspect }.join(', ')}"
|
|
46
|
+
]
|
|
47
|
+
if @report[:scope] != 'all_sites'
|
|
48
|
+
lines << '# Site-filtered report: NOT a complete application-wide allowlist.'
|
|
49
|
+
end
|
|
50
|
+
lines << '# INCOMPLETE SCAN: resolve warnings before using these lists.' unless @report[:complete]
|
|
51
|
+
lines << 'ComfyMiddleSeat.configure do |config|'
|
|
52
|
+
KINDS.each do |kind|
|
|
53
|
+
names = entries_for(kind).map { |entry| entry[:name] }.uniq.sort
|
|
54
|
+
if names.empty?
|
|
55
|
+
lines << " config.allowed_#{kind}s = []"
|
|
56
|
+
else
|
|
57
|
+
lines << " config.allowed_#{kind}s = ["
|
|
58
|
+
names.each { |name| lines << " #{name.inspect}," }
|
|
59
|
+
lines << ' ]'
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
lines << 'end'
|
|
63
|
+
"#{lines.join("\n")}\n"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def warnings
|
|
67
|
+
@report[:warnings].map do |warning|
|
|
68
|
+
source = warning[:source]
|
|
69
|
+
location = "site #{source[:site_id]}, #{source[:type]} #{source[:id]}, field #{source[:field].inspect}"
|
|
70
|
+
"Warning (#{location}): #{warning[:message].inspect}"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
|
|
76
|
+
def scope
|
|
77
|
+
@report[:scope] == 'all_sites' ? 'all sites' : 'selected sites'
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def entries_for(kind)
|
|
81
|
+
@report[:entries].select { |entry| entry[:kind] == kind }.sort_by { |entry| entry[:name] }
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -41,7 +41,7 @@ class ComfyMiddleSeat::Content::Tags::Helper < ComfyMiddleSeat::Content::Tag
|
|
|
41
41
|
def render
|
|
42
42
|
whitelist = ComfyMiddleSeat.config.allowed_helpers
|
|
43
43
|
if whitelist.is_a?(Array)
|
|
44
|
-
content if whitelist.map
|
|
44
|
+
content if whitelist.map(&:to_s).member?(method_name)
|
|
45
45
|
else
|
|
46
46
|
content unless BLACKLIST.member?(method_name)
|
|
47
47
|
end
|
|
@@ -24,22 +24,18 @@ module ComfyMiddleSeat::Content::Tags::Mixins
|
|
|
24
24
|
url_helpers.rails_blob_path(file, only_path: true)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
helpers = ActionController::Base.helpers
|
|
28
|
+
|
|
29
|
+
# Blob and variant URLs are not pipeline assets; HTML builders keep them
|
|
30
|
+
# relative instead of applying image_tag's asset-host settings.
|
|
27
31
|
case as
|
|
28
32
|
when 'link'
|
|
29
|
-
|
|
33
|
+
helpers.content_tag(:a, label, href: attachment_url, class: @class.presence, target: '_blank', rel: 'noopener')
|
|
30
34
|
when 'image'
|
|
31
|
-
|
|
35
|
+
helpers.tag.img(src: attachment_url, class: @class.presence, alt: label, title: label)
|
|
32
36
|
else
|
|
33
37
|
attachment_url
|
|
34
38
|
end
|
|
35
39
|
end
|
|
36
|
-
|
|
37
|
-
private
|
|
38
|
-
|
|
39
|
-
def html_class_attribute
|
|
40
|
-
return if @class.blank?
|
|
41
|
-
|
|
42
|
-
" class='#{@class}'"
|
|
43
|
-
end
|
|
44
40
|
end
|
|
45
41
|
end
|
|
@@ -9,3 +9,6 @@ require_relative 'content/params_parser'
|
|
|
9
9
|
require_relative 'content/tag'
|
|
10
10
|
require_relative 'content/tags'
|
|
11
11
|
require_relative 'content/block'
|
|
12
|
+
require_relative 'content/tag_usage'
|
|
13
|
+
require_relative 'content/tag_usage_report'
|
|
14
|
+
require_relative 'content/snippet_usage'
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
namespace :comfy do
|
|
4
|
+
namespace :cms do
|
|
5
|
+
# The development application and engine share a root, so Rails loads this file twice.
|
|
6
|
+
if Rake::Task.task_defined?('comfy:cms:tag_usage') && Rake::Task['comfy:cms:tag_usage'].actions.any? { |action| action.source_location&.first == __FILE__ }
|
|
7
|
+
next
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
desc 'Inventory CMS partials, helpers and templates (SITE=identifier FORMAT=text|json|config)'
|
|
11
|
+
task tag_usage: :environment do
|
|
12
|
+
format = ENV.fetch('FORMAT', 'text')
|
|
13
|
+
abort 'FORMAT must be text, json or config.' unless %w[text json config].include?(format)
|
|
14
|
+
|
|
15
|
+
sites = Comfy::Cms::Site.all
|
|
16
|
+
scope = 'all_sites'
|
|
17
|
+
if ENV.key?('SITE')
|
|
18
|
+
identifier = ENV.fetch('SITE')
|
|
19
|
+
sites = sites.where(identifier: identifier)
|
|
20
|
+
abort "Unknown site identifier: #{identifier.inspect}" unless sites.exists?
|
|
21
|
+
|
|
22
|
+
scope = 'selected_sites'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
report = ComfyMiddleSeat::Content::TagUsage.new(sites: sites, scope: scope).call
|
|
26
|
+
output = ComfyMiddleSeat::Content::TagUsageReport.new(report)
|
|
27
|
+
$stdout.puts output.public_send(format)
|
|
28
|
+
output.warnings.each { |warning| warn warning }
|
|
29
|
+
abort 'Tag usage scan incomplete; resolve warnings and scan again.' unless report[:complete]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: comfy_middle_seat
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Oleg Khabarov
|
|
@@ -416,12 +416,14 @@ files:
|
|
|
416
416
|
- app/controllers/comfy/admin/cms/revisions/translation_controller.rb
|
|
417
417
|
- app/controllers/comfy/admin/cms/sites_controller.rb
|
|
418
418
|
- app/controllers/comfy/admin/cms/snippets_controller.rb
|
|
419
|
+
- app/controllers/comfy/admin/cms/tag_usage_controller.rb
|
|
419
420
|
- app/controllers/comfy/admin/cms/translations_controller.rb
|
|
420
421
|
- app/controllers/comfy/cms/assets_controller.rb
|
|
421
422
|
- app/controllers/comfy/cms/base_controller.rb
|
|
422
423
|
- app/controllers/comfy/cms/content_controller.rb
|
|
423
424
|
- app/controllers/concerns/comfy/paginate.rb
|
|
424
425
|
- app/controllers/concerns/comfy/reorder_action.rb
|
|
426
|
+
- app/helpers/comfy/admin/cms/tag_usage_helper.rb
|
|
425
427
|
- app/helpers/comfy/admin/cms_helper.rb
|
|
426
428
|
- app/helpers/comfy/cms_helper.rb
|
|
427
429
|
- app/models/comfy/cms/categorization.rb
|
|
@@ -473,9 +475,12 @@ files:
|
|
|
473
475
|
- app/views/comfy/admin/cms/sites/index.html.haml
|
|
474
476
|
- app/views/comfy/admin/cms/sites/new.html.haml
|
|
475
477
|
- app/views/comfy/admin/cms/snippets/_form.html.haml
|
|
478
|
+
- app/views/comfy/admin/cms/snippets/_usage.html.haml
|
|
476
479
|
- app/views/comfy/admin/cms/snippets/edit.html.haml
|
|
477
480
|
- app/views/comfy/admin/cms/snippets/index.html.haml
|
|
478
481
|
- app/views/comfy/admin/cms/snippets/new.html.haml
|
|
482
|
+
- app/views/comfy/admin/cms/tag_usage/_source.html.haml
|
|
483
|
+
- app/views/comfy/admin/cms/tag_usage/index.html.haml
|
|
479
484
|
- app/views/comfy/admin/cms/translations/_form.html.haml
|
|
480
485
|
- app/views/comfy/admin/cms/translations/_sidebar.html.haml
|
|
481
486
|
- app/views/comfy/admin/cms/translations/edit.html.haml
|
|
@@ -577,7 +582,10 @@ files:
|
|
|
577
582
|
- lib/comfy_middle_seat/content/image_transformations.rb
|
|
578
583
|
- lib/comfy_middle_seat/content/params_parser.rb
|
|
579
584
|
- lib/comfy_middle_seat/content/renderer.rb
|
|
585
|
+
- lib/comfy_middle_seat/content/snippet_usage.rb
|
|
580
586
|
- lib/comfy_middle_seat/content/tag.rb
|
|
587
|
+
- lib/comfy_middle_seat/content/tag_usage.rb
|
|
588
|
+
- lib/comfy_middle_seat/content/tag_usage_report.rb
|
|
581
589
|
- lib/comfy_middle_seat/content/tags.rb
|
|
582
590
|
- lib/comfy_middle_seat/content/tags/asset.rb
|
|
583
591
|
- lib/comfy_middle_seat/content/tags/audio.rb
|
|
@@ -643,6 +651,7 @@ files:
|
|
|
643
651
|
- lib/generators/comfy/scaffold/templates/views/show.haml.tt
|
|
644
652
|
- lib/tasks/cms_assets.rake
|
|
645
653
|
- lib/tasks/cms_seeds.rake
|
|
654
|
+
- lib/tasks/cms_tag_usage.rake
|
|
646
655
|
- package-lock.json
|
|
647
656
|
- package.json
|
|
648
657
|
- public/favicon.ico
|