studio-engine 0.135.2 → 0.137.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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +64 -11
  3. data/README.md +10 -0
  4. data/app/assets/javascripts/studio/cropper-1.6.2.min.js +10 -0
  5. data/app/assets/javascripts/studio/page_transition_reveal.js +3 -0
  6. data/app/assets/stylesheets/studio/cropper-1.6.2.min.css +9 -0
  7. data/app/controllers/concerns/studio/connection_flow.rb +215 -0
  8. data/app/controllers/concerns/studio/error_handling.rb +58 -1
  9. data/app/controllers/studio/connections_controller.rb +13 -0
  10. data/app/helpers/studio/page_header_helper.rb +26 -0
  11. data/app/helpers/studio_navbar_helper.rb +22 -0
  12. data/app/javascript/studio/application.js +1 -0
  13. data/app/javascript/studio/cropper.js +2 -2
  14. data/app/javascript/studio/page_header_self_styled.js +194 -0
  15. data/app/javascript/studio/page_transitions.js +42 -11
  16. data/app/javascript/studio/reload_visits.js +93 -0
  17. data/app/models/studio/connection.rb +137 -0
  18. data/app/models/studio/user_session.rb +216 -21
  19. data/app/views/layouts/_navbar.html.erb +11 -4
  20. data/app/views/studio/_cropper_assets.html.erb +14 -9
  21. data/app/views/studio/_legal_page.html.erb +52 -0
  22. data/app/views/studio/_page_header.html.erb +12 -2
  23. data/app/views/studio/page_header/_assets.html.erb +151 -0
  24. data/db/migrate/20261108120000_add_device_revocation_to_studio_user_sessions.rb +28 -0
  25. data/db/migrate/20261108130000_create_studio_connections.rb +35 -0
  26. data/lib/generators/studio/connections/connections_generator.rb +93 -0
  27. data/lib/studio/connections/stand_in.rb +89 -0
  28. data/lib/studio/connections.rb +483 -0
  29. data/lib/studio/engine.rb +14 -1
  30. data/lib/studio/host_schema.rb +53 -2
  31. data/lib/studio/page_header.rb +11 -2
  32. data/lib/studio/version.rb +1 -1
  33. data/lib/studio.rb +70 -0
  34. metadata +16 -1
data/lib/studio/engine.rb CHANGED
@@ -88,7 +88,8 @@ module Studio
88
88
  # app/assets/javascripts/studio: the vendored third-party builds, each
89
89
  # loaded as an ES module (Alpine by the head's type="module" tag,
90
90
  # canvas-confetti and SortableJS through their importmap pins, Leaflet by
91
- # studio/footer_map's import()), and studio/session.js, the one classic
91
+ # studio/footer_map's import(), Cropper.js by studio/_cropper_assets'
92
+ # two tags), and studio/session.js, the one classic
92
93
  # script (layouts/studio/_head says why), with studio/page_transition_reveal.js,
93
94
  # the other classic one. The engine's own modules are under app/javascript,
94
95
  # enumerated below.
@@ -99,6 +100,8 @@ module Studio
99
100
  studio/sortable.js
100
101
  studio/leaflet.js
101
102
  studio/leaflet.css
103
+ studio/cropper-1.6.2.min.js
104
+ studio/cropper-1.6.2.min.css
102
105
  studio/session.js
103
106
  studio/page_transition_full_load.css
104
107
  studio/page_transition_reveal.js
@@ -312,6 +315,14 @@ module Studio
312
315
  app.config.filter_parameters += [/(\A|\.)voice\.(embeddings|embedding|audio)\z/, /\Avoice_embedding\z/]
313
316
  end
314
317
 
318
+ # The connections' log filter (Studio::Connections::LOG_FILTER): each
319
+ # provider's filter_keys by exact key, and the auth code on the connection
320
+ # controllers. One lambda that reads the registry when it runs, so a
321
+ # provider declared in a host initializer, after this, is covered.
322
+ initializer "studio.connections.filter_parameters" do |app|
323
+ app.config.filter_parameters += [Studio::Connections::LOG_FILTER]
324
+ end
325
+
315
326
  initializer "studio.footer_only_eager_load" do
316
327
  next if Studio.active_record?
317
328
 
@@ -429,8 +440,10 @@ module Studio
429
440
  # The host's error_logs, theme_settings and image_caches carry every
430
441
  # column the engine's models write (Studio::HostSchema). Skipped in a
431
442
  # rake task, which boots to migrate rather than to serve.
443
+ # Then the device-session columns, which only warn (docs/DEVICE_SESSIONS.md).
432
444
  if Studio.active_record? && !Studio::HostSchema.inside_rake_task?
433
445
  Studio::HostSchema.check!
446
+ Studio::HostSchema.device_session_check!
434
447
  end
435
448
  end
436
449
 
@@ -125,6 +125,57 @@ module Studio
125
125
  missing
126
126
  end
127
127
 
128
+ # DEVICE SESSIONS (docs/DEVICE_SESSIONS.md). Studio::UserSession checks a
129
+ # logged-out cookie only when studio_user_sessions carries sid and
130
+ # revoked_at; without them it checks nothing and serves as before. That
131
+ # off switch is right for an app that has not installed the migration yet,
132
+ # but silent: a replayed cookie would sign in and nobody would know why.
133
+ # So the boot names the gap. It is a WARNING in every environment and never
134
+ # raises: the release sweep installs the migration, and a host's CI must not
135
+ # go red over a column the next sweep adds.
136
+ DEVICE_SESSION_TABLE = "studio_user_sessions"
137
+ DEVICE_SESSION_COLUMNS = %w[sid revoked_at].freeze
138
+
139
+ # The device-session columns the host lacks: every one of them when the
140
+ # table is absent, else the ones it is short of. Empty when the host checks.
141
+ def missing_device_session_columns(connection)
142
+ return DEVICE_SESSION_COLUMNS.dup unless connection.table_exists?(DEVICE_SESSION_TABLE)
143
+
144
+ DEVICE_SESSION_COLUMNS - connection.columns(DEVICE_SESSION_TABLE).map(&:name)
145
+ end
146
+
147
+ def device_session_message(missing)
148
+ gap = missing == DEVICE_SESSION_COLUMNS ? "has no #{DEVICE_SESSION_TABLE} sid/revoked_at columns" : "#{DEVICE_SESSION_TABLE} is missing #{missing.join(', ')}"
149
+ "studio-engine: this app #{gap}, so a logged-out device's cookie is NOT " \
150
+ "checked and a copy of it still signs in (docs/DEVICE_SESSIONS.md). Run " \
151
+ "bin/rails studio_engine:install:migrations && bin/rails db:migrate."
152
+ end
153
+
154
+ # The boot hook for device sessions. Returns the missing columns (empty when
155
+ # whole, or skipped) and logs a warning, plus a Sentry warning, when any are
156
+ # missing. Never raises. Off when Studio.host_schema_check is false.
157
+ def device_session_check!(connection: nil, mode: self.mode, logger: Rails.logger)
158
+ return [] if mode == false
159
+
160
+ missing =
161
+ begin
162
+ if connection
163
+ missing_device_session_columns(connection)
164
+ else
165
+ ActiveRecord::Base.connection_pool.with_connection { |conn| missing_device_session_columns(conn) }
166
+ end
167
+ rescue ActiveRecord::ActiveRecordError => e
168
+ logger&.debug("[studio-engine] device session schema check skipped: #{e.class}: #{e.message}")
169
+ return []
170
+ end
171
+ return missing if missing.empty?
172
+
173
+ text = device_session_message(missing)
174
+ logger&.warn("[studio-engine] #{text}")
175
+ report_to_sentry(text, level: :warning)
176
+ missing
177
+ end
178
+
128
179
  # True while a rake task is running: the app booted to migrate, install or
129
180
  # precompile, not to serve.
130
181
  def inside_rake_task?
@@ -133,10 +184,10 @@ module Studio
133
184
  ::Rake.application.top_level_tasks.any?
134
185
  end
135
186
 
136
- def report_to_sentry(text)
187
+ def report_to_sentry(text, level: :error)
137
188
  return unless defined?(::Sentry) && ::Sentry.respond_to?(:capture_message)
138
189
 
139
- ::Sentry.capture_message(text, level: :error)
190
+ ::Sentry.capture_message(text, level: level)
140
191
  rescue StandardError
141
192
  nil
142
193
  end
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Studio
4
- # studio/_page_header's one piece of Ruby: the deprecation note for its old free-HTML
5
- # slot (docs/PAGE_HEADER.md, "The four kinds of control").
4
+ # studio/_page_header's Ruby: whether a row is self-styled (self_styled?), and the
5
+ # deprecation note for its old free-HTML slot (docs/PAGE_HEADER.md, "The four kinds of
6
+ # control").
6
7
  #
7
8
  # actions_html still renders for one release. In development only, the first render
8
9
  # that passes it writes one warning to the log per call site, so a host sees each
@@ -16,6 +17,14 @@ module Studio
16
17
  @mutex = Mutex.new
17
18
 
18
19
  class << self
20
+ # Whether this view's rows bring their own CSS and script (config.page_header_self_styled,
21
+ # docs/PAGE_HEADER.md, "In a plain-CSS app"): true, false, or a callable that receives
22
+ # the view. Anything truthy is true.
23
+ def self_styled?(view, setting = Studio.page_header_self_styled)
24
+ setting = setting.call(view) if setting.respond_to?(:call)
25
+ setting ? true : false
26
+ end
27
+
19
28
  # site: the caller's "path:line", so each page warns once. env and logger default to
20
29
  # Rails' and are injectable for a test.
21
30
  def deprecate_actions_html(site: nil, env: rails_env, logger: rails_logger)
@@ -1,3 +1,3 @@
1
1
  module Studio
2
- VERSION = "0.135.2"
2
+ VERSION = "0.137.0"
3
3
  end
data/lib/studio.rb CHANGED
@@ -75,6 +75,8 @@ require "studio/email_smoke"
75
75
  require "studio/mail_transport"
76
76
  require "studio/redis"
77
77
  require "studio/cable"
78
+ require "studio/connections"
79
+ require "studio/connections/stand_in"
78
80
  require "studio/survey"
79
81
  require "studio/survey/breakdown"
80
82
  require "studio/survey/export"
@@ -157,6 +159,16 @@ module Studio
157
159
  mattr_accessor :theme_logos, default: []
158
160
  mattr_accessor :sticky_table_headers, default: false
159
161
 
162
+ # ---- The self-styled page header ------------------------------------------
163
+ # For an app that does not build the engine's Tailwind layer (a plain-CSS app,
164
+ # such as rantly): studio/_page_header then brings its own scoped CSS and the
165
+ # small script for its stuck bar and its Links menu, once per page, as the site
166
+ # footer does (docs/PAGE_HEADER.md, "In a plain-CSS app"). true, false (the
167
+ # default: the row renders exactly as it always has, for a Tailwind app), or a
168
+ # callable that receives the view.
169
+ # Studio::PageHeader.self_styled? reads it.
170
+ mattr_accessor :page_header_self_styled, default: false
171
+
160
172
  # ---- Smooth-load convention ---------------------------------------------
161
173
  # Opt-in per app: renders the view-transition + no-preview metas so Turbo 8
162
174
  # page swaps materialize behind the current page and present with a view
@@ -1189,6 +1201,64 @@ module Studio
1189
1201
  # logged and swallowed — the respondent still lands on the thank-you screen.
1190
1202
  mattr_accessor :on_survey_completed, default: ->(_response) {}
1191
1203
 
1204
+ # ---- Connections (docs/CONNECTIONS.md) ------------------------------------
1205
+ #
1206
+ # The generic OAuth 2.0 connection tooling. The engine names no provider: a
1207
+ # host declares each in an initializer and draws its routes.
1208
+ #
1209
+ # Studio.define_connection :files, label: "Acme Files", env: {...}, ...
1210
+ # # config/routes.rb
1211
+ # Studio.draw_connection_routes(self, :files, path: "admin/files", controller: "admin/files")
1212
+ #
1213
+ # Every option is documented on Studio::Connections::Provider#initialize.
1214
+ def self.define_connection(key, **options)
1215
+ Connections.define(key, **options)
1216
+ end
1217
+
1218
+ def self.connection(key)
1219
+ Connections.fetch(key)
1220
+ end
1221
+
1222
+ # Who may connect, call back and disconnect: a method name on the connection
1223
+ # controller (the host's ApplicationController, through Studio::ErrorHandling,
1224
+ # answers :require_admin), or a callable taking the controller.
1225
+ mattr_accessor :connection_admin_guard, default: :require_admin
1226
+
1227
+ # Draws one provider's connect, callback and disconnect into the host's
1228
+ # routes, and records them for the log filter and the callback URL:
1229
+ #
1230
+ # POST /<path>/connect <as>_connect (also GET when the provider takes no account at Connect)
1231
+ # GET /<path>/callback <as>_callback (the redirect URI to register)
1232
+ # DELETE /<path>/connections/:id <as>_disconnect
1233
+ # GET /<path> <as> (only with show: true)
1234
+ #
1235
+ # controller: the host's own controller including Studio::ConnectionFlow
1236
+ # (default: the engine's Studio::ConnectionsController). show: draws the
1237
+ # page itself at <path> (default: true when the host names its controller).
1238
+ # return_to: the allowlist return_to may name; its first path is the default
1239
+ # (default: ["/<path>"]).
1240
+ def self.draw_connection_routes(router, key, path: "admin/#{key}", controller: nil, as: nil, return_to: nil, show: nil)
1241
+ provider = Connections.fetch(key)
1242
+ path = path.to_s.delete_prefix("/").delete_suffix("/")
1243
+ controller = (controller || "studio/connections").to_s.delete_prefix("/")
1244
+ as = (as || path.tr("/-", "__")).to_s
1245
+ show = controller != "studio/connections" if show.nil?
1246
+ return_paths = Array(return_to || ["/#{path}"]).map(&:to_s)
1247
+ Connections.record_route(Connections::Route.new(provider: provider.key, path:, as:, controller:, return_paths:))
1248
+
1249
+ defaults = { studio_connection: provider.key }
1250
+ router.instance_exec do
1251
+ get "#{path}", to: "#{controller}#show", as: as, defaults: defaults if show
1252
+ # POST-only when the admin names the account at Connect: a GET would skip
1253
+ # the CSRF check, so a link carrying an attacker's account could start a
1254
+ # connection to it in a signed-in admin's session.
1255
+ connect_via = provider.account_source == :connect ? %i[post] : %i[get post]
1256
+ match "#{path}/connect", to: "#{controller}#connect", as: "#{as}_connect", via: connect_via, defaults: defaults
1257
+ get "#{path}/callback", to: "#{controller}#callback", as: "#{as}_callback", defaults: defaults
1258
+ delete "#{path}/connections/:id", to: "#{controller}#disconnect", as: "#{as}_disconnect", defaults: defaults
1259
+ end
1260
+ end
1261
+
1192
1262
  # Define a survey in app code. See Studio::Survey for the DSL.
1193
1263
  def self.define_survey(slug, &block)
1194
1264
  Survey.define(slug, &block)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: studio-engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.135.2
4
+ version: 0.137.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex McRitchie
@@ -423,10 +423,12 @@ files:
423
423
  - app/assets/images/state-flags/wy.svg
424
424
  - app/assets/javascripts/studio/alpine.js
425
425
  - app/assets/javascripts/studio/canvas_confetti.js
426
+ - app/assets/javascripts/studio/cropper-1.6.2.min.js
426
427
  - app/assets/javascripts/studio/leaflet.js
427
428
  - app/assets/javascripts/studio/page_transition_reveal.js
428
429
  - app/assets/javascripts/studio/session.js
429
430
  - app/assets/javascripts/studio/sortable.js
431
+ - app/assets/stylesheets/studio/cropper-1.6.2.min.css
430
432
  - app/assets/stylesheets/studio/leaflet.css
431
433
  - app/assets/stylesheets/studio/page_transition_full_load.css
432
434
  - app/assets/stylesheets/studio/sticky_table_header.css
@@ -442,6 +444,7 @@ files:
442
444
  - app/controllers/concerns/solana/session_auth.rb
443
445
  - app/controllers/concerns/studio/admin_models.rb
444
446
  - app/controllers/concerns/studio/board/reorderable.rb
447
+ - app/controllers/concerns/studio/connection_flow.rb
445
448
  - app/controllers/concerns/studio/error_handling.rb
446
449
  - app/controllers/concerns/studio/geo_detection.rb
447
450
  - app/controllers/concerns/studio/link_consumption.rb
@@ -460,6 +463,7 @@ files:
460
463
  - app/controllers/studio/agent_chats_controller.rb
461
464
  - app/controllers/studio/bookings_controller.rb
462
465
  - app/controllers/studio/component_previews_controller.rb
466
+ - app/controllers/studio/connections_controller.rb
463
467
  - app/controllers/studio/emails_controller.rb
464
468
  - app/controllers/studio/geo_settings_controller.rb
465
469
  - app/controllers/studio/google_setup_requests_controller.rb
@@ -488,6 +492,7 @@ files:
488
492
  - app/helpers/studio/geo_helper.rb
489
493
  - app/helpers/studio/link_preview_helper.rb
490
494
  - app/helpers/studio/loader_helper.rb
495
+ - app/helpers/studio/page_header_helper.rb
491
496
  - app/helpers/studio/public_user_helper.rb
492
497
  - app/helpers/studio/site_footer_helper.rb
493
498
  - app/helpers/studio_email_delivery_helper.rb
@@ -561,10 +566,12 @@ files:
561
566
  - app/javascript/studio/nav_collapse.js
562
567
  - app/javascript/studio/newsletter_modal.js
563
568
  - app/javascript/studio/page_header.js
569
+ - app/javascript/studio/page_header_self_styled.js
564
570
  - app/javascript/studio/page_transitions.js
565
571
  - app/javascript/studio/pinned_stack.js
566
572
  - app/javascript/studio/profile_form.js
567
573
  - app/javascript/studio/pull_to_refresh.js
574
+ - app/javascript/studio/reload_visits.js
568
575
  - app/javascript/studio/sticky_table_header.js
569
576
  - app/javascript/studio/stimulus.js
570
577
  - app/javascript/studio/studio_confetti.js
@@ -595,6 +602,7 @@ files:
595
602
  - app/models/error_log.rb
596
603
  - app/models/image_cache.rb
597
604
  - app/models/session_context.rb
605
+ - app/models/studio/connection.rb
598
606
  - app/models/studio/email_delivery.rb
599
607
  - app/models/studio/email_setting.rb
600
608
  - app/models/studio/enumeral.rb
@@ -656,6 +664,7 @@ files:
656
664
  - app/views/studio/_fizz_layer.html.erb
657
665
  - app/views/studio/_hold_button.html.erb
658
666
  - app/views/studio/_hold_button_guard.html.erb
667
+ - app/views/studio/_legal_page.html.erb
659
668
  - app/views/studio/_leveling_activity_assets.html.erb
660
669
  - app/views/studio/_not_found.html.erb
661
670
  - app/views/studio/_page_header.html.erb
@@ -774,6 +783,7 @@ files:
774
783
  - app/views/studio/newsletter_mailer/subscribed.html.erb
775
784
  - app/views/studio/newsletter_mailer/subscribed.text.erb
776
785
  - app/views/studio/not_found/show.html.erb
786
+ - app/views/studio/page_header/_assets.html.erb
777
787
  - app/views/studio/profile_mailer/email_change_notification.html.erb
778
788
  - app/views/studio/profile_mailer/email_change_notification.text.erb
779
789
  - app/views/studio/profiles/_birthday_fields.html.erb
@@ -870,9 +880,12 @@ files:
870
880
  - db/migrate/20261010120000_add_stored_in_to_image_caches.rb
871
881
  - db/migrate/20261029120000_add_voice_profile_to_users.rb
872
882
  - db/migrate/20261103120000_create_studio_user_sessions.rb
883
+ - db/migrate/20261108120000_add_device_revocation_to_studio_user_sessions.rb
884
+ - db/migrate/20261108130000_create_studio_connections.rb
873
885
  - docs/BOOKING.md
874
886
  - docs/SITE_FOOTER.md
875
887
  - lib/active_storage/service/studio_trash_s3_service.rb
888
+ - lib/generators/studio/connections/connections_generator.rb
876
889
  - lib/generators/studio/site_identity/site_identity_generator.rb
877
890
  - lib/studio-engine.rb
878
891
  - lib/studio.rb
@@ -882,6 +895,8 @@ files:
882
895
  - lib/studio/cable.rb
883
896
  - lib/studio/color_scale.rb
884
897
  - lib/studio/component_gallery.rb
898
+ - lib/studio/connections.rb
899
+ - lib/studio/connections/stand_in.rb
885
900
  - lib/studio/crumbs.rb
886
901
  - lib/studio/email.rb
887
902
  - lib/studio/email_image_generator.rb