lato_cms 3.0.6 → 3.0.7

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: cbcd0c46e947f128bf5c6334e7729fbbbe12682c3b2e89d4442bb7b1a73528a4
4
- data.tar.gz: 040ad879939068be79b8078a3a011a40f49f8a35f7539e9d791904b4148df4c2
3
+ metadata.gz: 73f72c7845f56b80f62423a1709a3ea8d5bd80813d8c61b4eaf6af2b353d660c
4
+ data.tar.gz: f222800a0be54f4e7022ecebfe6259515e56fd82554d1784d7bf55fa1a65074e
5
5
  SHA512:
6
- metadata.gz: 1644c351792d4ced7526999d47f250ebb09b3fd5f9de897818465bfa37e00b7623af635309a589b5fb8001ef5d7021c11f7e854738c6054eb719398dc46f8d98
7
- data.tar.gz: 39131b5dd434621e95a147d27287c0479e06ca42f086f73906f185e0a0b64086bc134234315400dc56a6ef20dfab49a867a102eec522f4d41c5e986c9cf9c2f0
6
+ metadata.gz: 59fa3bb5a49ce31a770192a6708c59f95313d44896bb493bf0d009b523f950d8f3165609b38da4dbfa4c239c9e6f7d44f2f8bcd870c7d01c4a3b147d11877c7b
7
+ data.tar.gz: 2d31910d84e7df094b4c85ae3f790bcd8e47e2c66dd7cfd472f9c2fde5016b85b1fbb9de1c7a12a86e8946ea527ab0fe8d8434d6e3ab1e5683df9d1fb402731d
@@ -4,9 +4,11 @@ module LatoCms
4
4
  layout 'lato/application'
5
5
  before_action :authenticate_session
6
6
  before_action :authenticate_group
7
- before_action :authenticate_lato_cms_admin
7
+ before_action :authenticate_lato_cms_access
8
8
  before_action { active_sidebar(:lato_cms); active_navbar(:lato_cms) }
9
9
 
10
+ helper_method :lato_cms_admin?
11
+
10
12
  def index
11
13
  redirect_to lato_cms.pages_path
12
14
  end
@@ -17,10 +19,23 @@ module LatoCms
17
19
  @query_pages ||= LatoCms::Page.for_lato_spaces_group(@session.get(:spaces_group_id))
18
20
  end
19
21
 
20
- def authenticate_lato_cms_admin
21
- return true if @session.user&.lato_cms_admin
22
+ # Section-level guard: any CMS role (operator or admin) may enter.
23
+ def authenticate_lato_cms_access
24
+ return true if @session.user&.lato_cms_access?
22
25
 
23
26
  redirect_to lato.root_path, alert: t('lato_cms.unauthorized_section')
24
27
  end
28
+
29
+ # Action-level guard for page management and translation links: admin only.
30
+ def authenticate_lato_cms_admin
31
+ return true if lato_cms_admin?
32
+
33
+ redirect_to lato_cms.pages_path, alert: t('lato_cms.unauthorized_action')
34
+ end
35
+
36
+ # Exposed to views to conditionally render admin-only controls.
37
+ def lato_cms_admin?
38
+ @session.user&.lato_cms_admin? || false
39
+ end
25
40
  end
26
41
  end
@@ -1,6 +1,16 @@
1
1
  module LatoCms
2
2
  class PagesController < ApplicationController
3
+ # Page management and translation links are reserved to the admin role.
4
+ # Operators keep read access plus field editing and component toggles.
5
+ ADMIN_ONLY_ACTIONS = %i[
6
+ create create_action
7
+ update update_action
8
+ destroy_action
9
+ translations link_translation_action unlink_translation_action
10
+ ].freeze
11
+
3
12
  before_action { active_sidebar(:lato_cms_pages) }
13
+ before_action :authenticate_lato_cms_admin, only: ADMIN_ONLY_ACTIONS
4
14
 
5
15
  def index
6
16
  pages = query_pages
@@ -13,7 +13,7 @@
13
13
  </div>
14
14
  <div class="card-body">
15
15
  <%= lato_index @pages,
16
- custom_actions: {
16
+ custom_actions: lato_cms_admin? ? {
17
17
  create: {
18
18
  path: lato_cms.pages_create_path,
19
19
  icon: 'bi bi-plus',
@@ -25,7 +25,7 @@
25
25
  action_title: t('lato_cms.page_create_title')
26
26
  }
27
27
  }
28
- },
28
+ } : {},
29
29
  pagination_options: [10, 20, 50, 100]
30
30
  %>
31
31
  </div>
@@ -20,8 +20,10 @@
20
20
  <i class="bi bi-globe fs-1 mb-3"></i>
21
21
  <p class="mb-1"><%= t('lato_cms.show_no_preview_title') %></p>
22
22
  <p class="small"><%= t('lato_cms.show_no_preview_description').html_safe %></p>
23
- <%= link_to t('lato_cms.show_edit_settings_cta'), lato_cms.pages_update_path(@page), class: 'btn btn-sm btn-outline-primary mt-2',
24
- data: { lato_action_target: 'trigger', turbo_frame: dom_id(@page, 'form'), action_title: t('lato_cms.page_update_title') } %>
23
+ <% if lato_cms_admin? %>
24
+ <%= link_to t('lato_cms.show_edit_settings_cta'), lato_cms.pages_update_path(@page), class: 'btn btn-sm btn-outline-primary mt-2',
25
+ data: { lato_action_target: 'trigger', turbo_frame: dom_id(@page, 'form'), action_title: t('lato_cms.page_update_title') } %>
26
+ <% end %>
25
27
  </div>
26
28
  </div>
27
29
  <% end %>
@@ -35,7 +37,7 @@
35
37
  <div class="d-flex align-items-center gap-2">
36
38
  <%= lato_cms_page_locale_dropdown(@page) %>
37
39
  <span class="vr"></span>
38
- <%= lato_cms_page_actions_dropdown(@page, show_edit: true, show_translations: true, show_delete: true, hide_show: true) %>
40
+ <%= lato_cms_page_actions_dropdown(@page, show_edit: lato_cms_admin?, show_translations: lato_cms_admin?, show_delete: lato_cms_admin?, hide_show: true) %>
39
41
  <span class="vr"></span>
40
42
  <button class="btn btn-sm btn-outline-primary d-none"
41
43
  title="<%= t('lato_cms.show_hide_panel_tooltip') %>"
@@ -59,15 +61,19 @@
59
61
  <i class="bi bi-file-earmark-code fs-1 mb-3 d-block"></i>
60
62
  <p class="mb-1"><%= t('lato_cms.show_no_template_title') %></p>
61
63
  <p class="small"><%= t('lato_cms.show_no_template_description') %></p>
62
- <%= link_to t('lato_cms.show_edit_settings_cta'), lato_cms.pages_update_path(@page), class: 'btn btn-sm btn-outline-primary mt-2',
63
- data: { lato_action_target: 'trigger', turbo_frame: dom_id(@page, 'form'), action_title: t('lato_cms.page_update_title') } %>
64
+ <% if lato_cms_admin? %>
65
+ <%= link_to t('lato_cms.show_edit_settings_cta'), lato_cms.pages_update_path(@page), class: 'btn btn-sm btn-outline-primary mt-2',
66
+ data: { lato_action_target: 'trigger', turbo_frame: dom_id(@page, 'form'), action_title: t('lato_cms.page_update_title') } %>
67
+ <% end %>
64
68
  </div>
65
69
  <% elsif !@page.template_available? %>
66
70
  <div class="alert alert-warning">
67
71
  <i class="bi bi-exclamation-triangle me-1"></i>
68
72
  <%= t('lato_cms.show_template_unavailable', template_id: @page.template_id) %>
69
- <%= link_to t('lato_cms.show_edit_settings_cta'), lato_cms.pages_update_path(@page), class: 'btn btn-sm btn-outline-warning ms-2',
70
- data: { lato_action_target: 'trigger', turbo_frame: dom_id(@page, 'form'), action_title: t('lato_cms.page_update_title') } %>
73
+ <% if lato_cms_admin? %>
74
+ <%= link_to t('lato_cms.show_edit_settings_cta'), lato_cms.pages_update_path(@page), class: 'btn btn-sm btn-outline-warning ms-2',
75
+ data: { lato_action_target: 'trigger', turbo_frame: dom_id(@page, 'form'), action_title: t('lato_cms.page_update_title') } %>
76
+ <% end %>
71
77
  </div>
72
78
  <% existing_fields = @page.fields.group_by(&:template_component_id) %>
73
79
  <% if existing_fields.any? %>
@@ -1,5 +1,13 @@
1
1
  en:
2
+ activerecord:
3
+ attributes:
4
+ lato/user:
5
+ lato_cms_admin_role: Lato CMS role
2
6
  lato_cms:
7
+ admin_roles:
8
+ none: No access
9
+ operator: Operator
10
+ admin: Administrator
3
11
  cta_show: Show
4
12
  cta_edit: Edit
5
13
  cta_update: Update
@@ -11,6 +19,7 @@ en:
11
19
  fields_saved: Fields saved successfully
12
20
  page_deleted: Page deleted successfully
13
21
  unauthorized_section: You do not have access to this section.
22
+ unauthorized_action: You do not have permission to perform this action.
14
23
  page_delete_failed: Failed to delete page
15
24
  api_page_not_found: Page not found
16
25
  pages_index_title: Pages
@@ -1,5 +1,13 @@
1
1
  it:
2
+ activerecord:
3
+ attributes:
4
+ lato/user:
5
+ lato_cms_admin_role: Ruolo Lato CMS
2
6
  lato_cms:
7
+ admin_roles:
8
+ none: Nessun accesso
9
+ operator: Operatore
10
+ admin: Amministratore
3
11
  cta_show: Visualizza
4
12
  cta_edit: Modifica
5
13
  cta_update: Aggiorna
@@ -11,6 +19,7 @@ it:
11
19
  fields_saved: Campi salvati con successo
12
20
  page_deleted: Pagina eliminata con successo
13
21
  unauthorized_section: Non hai accesso a questa sezione.
22
+ unauthorized_action: Non hai i permessi per eseguire questa azione.
14
23
  page_delete_failed: Impossibile eliminare la pagina
15
24
  api_page_not_found: Pagina non trovata
16
25
  pages_index_title: Pagine
@@ -0,0 +1,18 @@
1
+ class ChangeLatoCmsAdminToLatoCmsAdminRoleOnLatoUser < ActiveRecord::Migration[8.1]
2
+ def up
3
+ add_column :lato_users, :lato_cms_admin_role, :integer, default: 0, null: false
4
+
5
+ # Backfill: true -> 1, false/nil -> 0 (already the column default)
6
+ execute 'UPDATE lato_users SET lato_cms_admin_role = 1 WHERE lato_cms_admin = 1'
7
+
8
+ remove_column :lato_users, :lato_cms_admin
9
+ end
10
+
11
+ def down
12
+ add_column :lato_users, :lato_cms_admin, :boolean, default: false
13
+
14
+ execute 'UPDATE lato_users SET lato_cms_admin = 1 WHERE lato_cms_admin_role = 1'
15
+
16
+ remove_column :lato_users, :lato_cms_admin_role
17
+ end
18
+ end
@@ -3,11 +3,18 @@ module LatoCms
3
3
  # This class contains the default configuration of the engine.
4
4
  ##
5
5
  class Config
6
- attr_accessor :locales, :templates_path
6
+ attr_accessor :locales, :templates_path, :admin_roles
7
7
 
8
8
  def initialize
9
9
  @locales = [:en]
10
10
  @templates_path = 'config/lato_cms'
11
+
12
+ # Admin roles exposed on Lato::User#lato_cms_admin_role and rendered
13
+ # as a select by lato_users. Ordered map of role key => integer value;
14
+ # labels are resolved via i18n (lato_cms.admin_roles.<key>).
15
+ # `operator` has read/edit access; `admin` also manages pages
16
+ # (create, update, delete) and translation links.
17
+ @admin_roles = { none: 0, operator: 1, admin: 2 }
11
18
  end
12
19
  end
13
20
  end
@@ -9,5 +9,32 @@ module LatoCms
9
9
  initializer "lato_cms.precompile" do |app|
10
10
  app.config.assets.precompile << "lato_cms_manifest.js"
11
11
  end
12
+
13
+ # Expose the CMS admin role options on the shared Lato::User model.
14
+ # lato_users (when mounted) discovers the `lato_cms_admin_role` column by
15
+ # convention and calls this method to build the role selector. Defined
16
+ # here so it works regardless of whether lato_users is installed.
17
+ config.to_prepare do
18
+ Lato::User.class_eval do
19
+ # Role options for the lato_cms_admin_role permission.
20
+ # Returns [[label, value], ...] with labels resolved at call time.
21
+ def self.lato_cms_admin_role_options
22
+ LatoCms.config.admin_roles.map do |key, value|
23
+ [I18n.t("lato_cms.admin_roles.#{key}"), value]
24
+ end
25
+ end
26
+
27
+ # True when the user can access the CMS section (operator or admin).
28
+ def lato_cms_access?
29
+ lato_cms_admin_role.to_i.positive?
30
+ end
31
+
32
+ # True when the user has the admin role: full page management
33
+ # (create, update, delete) and translation links.
34
+ def lato_cms_admin?
35
+ lato_cms_admin_role.to_i >= LatoCms.config.admin_roles.fetch(:admin, 0)
36
+ end
37
+ end
38
+ end
12
39
  end
13
40
  end
@@ -1,3 +1,3 @@
1
1
  module LatoCms
2
- VERSION = "3.0.6"
2
+ VERSION = "3.0.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lato_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.6
4
+ version: 3.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante
@@ -148,6 +148,7 @@ files:
148
148
  - db/migrate/20260320070819_create_lato_cms_pages.rb
149
149
  - db/migrate/20260323171241_create_lato_cms_page_fields.rb
150
150
  - db/migrate/20260705000000_add_translation_group_id_to_lato_cms_pages.rb
151
+ - db/migrate/20260712092241_change_lato_cms_admin_to_lato_cms_admin_role_on_lato_user.rb
151
152
  - lib/lato_cms.rb
152
153
  - lib/lato_cms/config.rb
153
154
  - lib/lato_cms/engine.rb