spina 2.1.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of spina might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a28a0de26915bef00f7a6f1019dbfd0d6e927065daabef573f420892a9e22265
4
- data.tar.gz: 99463e1a9c5525b73c1b348263d177223a8e0c96f1753316c4eb57958865ee9e
3
+ metadata.gz: 10ab1a1559660bdb66bf8122c5ef69a8a4811bd327c60d2622002804c6a8e945
4
+ data.tar.gz: 6568ddd0fba70f0d066a6434e6c1f707d038cdf74d9c7dcbd942f0bf59f125db
5
5
  SHA512:
6
- metadata.gz: 163f8055f3efa7dee70d008bdecd7a94a41ba6ba17937d98cba10ae9ed10e34d2f1d586a14196531c66da2f07aa86ecb3154000cd12f6a883e13ee65ed480ee0
7
- data.tar.gz: da9958a72dc526f1860d77a25820e8122f2a4e58ad6da22f2b6e3621f7b94163211d3eb39b4ac790e710a6ad29bf74afafed985101e53c89527b15a5a616106f
6
+ metadata.gz: 2a04b2b8a07cb6eb7e75f5130c25882e9848d41b9af5a8537db995ff09439b2f3103cd7e75d59896cc6acfc0b7a9e9637ac96ae016b80549d053200dabc12e6a
7
+ data.tar.gz: bc5a8bd8f902f22ff3d4e6ebc215b34a31675af249f9533b55f817d9972c4dd9436a5ca75aa2834c8cdea08140e1a8f8967af5e0563ecfc15205e6bb621489c7
@@ -0,0 +1,17 @@
1
+ module Spina
2
+ module CurrentAccount
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_action :current_account
7
+ helper_method :current_account
8
+ end
9
+
10
+ private
11
+
12
+ def current_account
13
+ Spina::Current.account ||= ::Spina::Account.first
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Spina
2
+ module CurrentTheme
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_action :current_theme
7
+ helper_method :current_theme
8
+ end
9
+
10
+ private
11
+
12
+ def current_theme
13
+ Spina::Current.theme ||= ::Spina::Theme.find_by_name(current_account.theme)
14
+ end
15
+
16
+ end
17
+ end
@@ -1,13 +1,14 @@
1
1
  module Spina
2
2
  module Admin
3
3
  class AdminController < ActionController::Base
4
- include Spina::CurrentMethods
4
+ include Spina.config.authentication.constantize
5
+ include Spina::CurrentAccount, Spina::CurrentTheme
5
6
 
6
7
  helper Spina::Engine.helpers
7
8
 
8
9
  before_action :add_view_path
9
10
  before_action :set_admin_locale
10
- before_action :authorize_spina_user
11
+ before_action :authenticate
11
12
 
12
13
  admin_section :content
13
14
 
@@ -25,14 +26,6 @@ module Spina
25
26
  def set_admin_locale
26
27
  I18n.locale = I18n.default_locale
27
28
  end
28
-
29
- def authorize_spina_user
30
- redirect_to admin_login_path, flash: {information: I18n.t('spina.notifications.login')} unless current_spina_user
31
- end
32
-
33
- def authorize_admin
34
- render status: 401 unless current_spina_user.admin?
35
- end
36
29
 
37
30
  def add_view_path
38
31
  prepend_view_path Spina::Engine.root.join('app/views/spina/admin')
@@ -11,11 +11,11 @@ module Spina
11
11
 
12
12
  if params[:resource_id]
13
13
  @resource = Resource.find(params[:resource_id])
14
- @page_templates = Current.theme.new_page_templates(recommended: @resource.view_template)
14
+ @page_templates = Spina::Current.theme.new_page_templates(recommended: @resource.view_template)
15
15
  @pages = @resource.pages.active.roots.includes(:translations)
16
16
  else
17
17
  @pages = Page.active.sorted.roots.main.includes(:translations)
18
- @page_templates = Current.theme.new_page_templates
18
+ @page_templates = Spina::Current.theme.new_page_templates
19
19
  end
20
20
  end
21
21
 
@@ -3,7 +3,7 @@ module Spina
3
3
  class PasswordResetsController < AdminController
4
4
  layout "spina/admin/sessions"
5
5
 
6
- skip_before_action :authorize_spina_user
6
+ skip_before_action :authenticate
7
7
 
8
8
  def new
9
9
  end
@@ -1,7 +1,7 @@
1
1
  module Spina
2
2
  module Admin
3
3
  class SessionsController < AdminController
4
- skip_before_action :authorize_spina_user
4
+ skip_before_action :authenticate
5
5
 
6
6
  def new
7
7
  end
@@ -1,6 +1,7 @@
1
1
  module Spina
2
2
  module Admin
3
3
  class UsersController < AdminController
4
+ before_action :authorize_authentication_module
4
5
  before_action :authorize_admin, except: [:index]
5
6
  before_action :set_user, only: [:edit, :update, :destroy]
6
7
 
@@ -47,7 +48,7 @@ module Spina
47
48
  end
48
49
 
49
50
  def destroy
50
- if @user != current_spina_user
51
+ if @user != current_spina_user
51
52
  @user.destroy
52
53
  redirect_to spina.admin_users_url, flash: {success: t('spina.users.deleted')}
53
54
  end
@@ -66,6 +67,15 @@ module Spina
66
67
  def set_user
67
68
  @user = User.find(params[:id])
68
69
  end
70
+
71
+ def authorize_authentication_module
72
+ render status: 401 unless Spina.config.authentication == "Spina::Authentication::Sessions"
73
+ end
74
+
75
+ def authorize_admin
76
+ render status: 401 unless current_spina_user.admin?
77
+ end
78
+
69
79
  end
70
80
  end
71
81
  end
@@ -1,5 +1,6 @@
1
1
  class Spina::ApplicationController < Spina.frontend_parent_controller.constantize
2
- include Spina::CurrentMethods
2
+ include Spina.config.authentication.constantize
3
+ include Spina::CurrentAccount, Spina::CurrentTheme
3
4
 
4
5
  helper Spina::Engine.helpers
5
6
 
@@ -1,18 +1,18 @@
1
1
  class Spina::PagesController < Spina::ApplicationController
2
2
  include Spina::Frontend
3
3
 
4
- before_action :current_spina_user_can_view_page?
4
+ before_action :authorize_page
5
5
 
6
6
  helper_method :page
7
7
 
8
8
  def homepage
9
9
  render_with_template(page)
10
10
  end
11
-
11
+
12
12
  private
13
-
14
- def current_spina_user_can_view_page?
15
- raise ActiveRecord::RecordNotFound unless current_spina_user.present? || page.live?
13
+
14
+ def authorize_page
15
+ raise ActiveRecord::RecordNotFound unless page.live? || logged_in?
16
16
  end
17
17
 
18
18
  end
@@ -2,7 +2,7 @@ module Spina
2
2
  module AttachmentsHelper
3
3
 
4
4
  def file_url(file)
5
- main_app.rails_service_blob_path(file.signed_id, file.filename)
5
+ main_app.url_for(file)
6
6
  end
7
7
 
8
8
  end
@@ -53,7 +53,7 @@ module Spina
53
53
  end
54
54
 
55
55
  def slug
56
- url_title&.parameterize
56
+ url_title.to_s.to_slug.normalize(transliterations: Spina.config.transliterations)
57
57
  end
58
58
 
59
59
  def homepage?
@@ -9,6 +9,11 @@
9
9
  <%= heroicon('pencil', style: :solid, class: 'w-4 h-4 mr-1 text-gray-600') %>
10
10
  <%=t 'spina.ui.rename' %>
11
11
  <% end %>
12
+
13
+ <%= link_to file_url(attachment.file), class: "btn btn-default h-7 px-2 mr-2 text-xs" do %>
14
+ <%= heroicon('download', style: :solid, class: 'w-4 h-4 mr-1 text-gray-600') %>
15
+ <%=t 'spina.attachments.download' %>
16
+ <% end %>
12
17
  </div>
13
18
  </turbo-frame>
14
19
 
@@ -40,7 +40,10 @@
40
40
  <% nav.links do %>
41
41
  <%= render Spina::MainNavigation::LinkComponent.new(t('spina.settings.general'), spina.edit_admin_account_path, active: controller_name == "accounts") %>
42
42
  <%= render Spina::MainNavigation::LinkComponent.new(t('spina.website.theme'), spina.edit_admin_theme_path, active: controller_name == "theme") %>
43
- <%= render Spina::MainNavigation::LinkComponent.new(t('spina.settings.users'), spina.admin_users_path, active: controller_name == "users") %>
43
+
44
+ <% if Spina.config.authentication == "Spina::Authentication::Sessions" %>
45
+ <%= render Spina::MainNavigation::LinkComponent.new(t('spina.settings.users'), spina.admin_users_path, active: controller_name == "users") %>
46
+ <% end %>
44
47
 
45
48
  <%= render Spina::Hooks::HookComponent.new(partial: "settings_secondary_navigation") %>
46
49
 
@@ -54,13 +57,15 @@
54
57
  <% end %>
55
58
  </ul>
56
59
 
57
- <ul class="md:block">
58
- <li>
59
- <%= link_to spina.admin_logout_path, class: 'p-3 w-14 block flex justify-center opacity-50 hover:opacity-100 transition duration-200 ease', data: {turbo: false} do %>
60
- <%= heroicon('logout', style: :solid, class: 'h-8 w-8 text-white') %>
61
- <% end %>
62
- </li>
63
- </ul>
60
+ <% if defined?(logout_path) %>
61
+ <ul class="md:block">
62
+ <li>
63
+ <%= link_to logout_path, class: 'p-3 w-14 block flex justify-center opacity-50 hover:opacity-100 transition duration-200 ease', data: {turbo: false} do %>
64
+ <%= heroicon('logout', style: :solid, class: 'h-8 w-8 text-white') %>
65
+ <% end %>
66
+ </li>
67
+ </ul>
68
+ <% end %>
64
69
 
65
70
  </div>
66
71
  </nav>
@@ -106,6 +106,7 @@ en:
106
106
  attachments:
107
107
  choose_attachment: Choose attachment
108
108
  delete_confirmation_html: Are you sure? This attachment <span class='font-semibold'>might</span> be in use on a page.
109
+ download: Download
109
110
  insert: Insert document
110
111
  insert_multiple: Insert documents
111
112
  upload: Upload files
@@ -1,31 +1,47 @@
1
- Spina.configure do |config|
2
- # Set locales
3
- config.locales = [:en]
4
- # Run `rake spina:update_translations` after you add any new locale.
5
-
6
- # Important Note
7
- # ==============
8
-
9
- # You MUST restart your server before changes to this file
10
- # will take effect.
1
+ Spina.configure do |config|
2
+ # Locales
3
+ # ===============
4
+ # All locales your content should be available in.
5
+ # config.locales = [I18n.default_locale]
11
6
 
7
+ # Backend path
8
+ # ===============
12
9
  # Specify a backend path. Defaults to /admin.
13
10
  # config.backend_path = 'admin'
14
11
 
12
+ # Frontend routes
13
+ # ===============
14
+ # Uncomment the config below to disable all frontend routes.
15
+ # You'll have to write your own.
16
+ # config.disable_frontend_routes = true
17
+
18
+ # Embedded image size
19
+ # ===============
20
+ # Images that are inserted in rich text fields are resized automatically.
21
+ # You can define your desired dimensions here.
22
+ # config.embedded_image_size = [2000, 2000]
23
+
24
+ # Parent controller
25
+ # ===============
15
26
  # The parent controller all frontend Spina controllers inherit from
16
27
  # Defaults to ApplicationController
17
28
  # config.frontend_parent_controller = "ApplicationController"
18
29
 
30
+ # Authentication
31
+ # ===============
32
+ # Specify the module that handles authentication
33
+ # You can swap this out for something like Devise, or you can use your own authentication.
34
+ # The default is Spina::Authentication::Sessions and includes basic user management
35
+ # config.authentication = "Spina::Authentication::Sessions"
36
+
19
37
  # Background jobs
20
38
  # ===============
21
- #
22
39
  # By default, all background jobs are queued as :default
23
40
  # config.queues.page_updates = :default
24
41
 
25
42
  # Confetti
26
43
  # ===============
27
- #
28
- # For people who don't appreciate confetti, you can disable that here
44
+ # For people who don't appreciate confetti, you can disable that here.
29
45
  # config.party_pooper = true
30
46
 
31
47
  # Pages Options
@@ -33,4 +49,11 @@ Spina.configure do |config|
33
49
 
34
50
  # Note that you might need to remove cached asset after changing this value
35
51
  # config.max_page_depth = 5
52
+
53
+ # Transliterations
54
+ # ===============
55
+ # Set provided transliterations for normalizing url slugs
56
+ # %i( bulgarian cyrillic danish german greek latin macedonian norwegian
57
+ # romanian russian serbian spanish swedish ukrainian vietnamese)
58
+ # config.transliterations = %i(latin)
36
59
  end
data/lib/spina.rb CHANGED
@@ -7,6 +7,8 @@ require 'spina/theme'
7
7
  require 'spina/tailwind_purger'
8
8
  require 'spina/attr_json_spina_parts_model'
9
9
  require 'spina/attr_json_monkeypatch'
10
+ require 'spina/authentication/sessions'
11
+ require 'spina/authentication/basic'
10
12
 
11
13
  module Spina
12
14
  include ActiveSupport::Configurable
@@ -15,34 +17,42 @@ module Spina
15
17
  PLUGINS = []
16
18
  THEMES = []
17
19
 
18
- config_accessor :backend_path,
20
+ config_accessor :authentication,
21
+ :backend_path,
19
22
  :frontend_parent_controller,
20
23
  :disable_frontend_routes,
21
- :max_page_depth,
24
+ :disable_decorator_load,
22
25
  :locales,
23
26
  :embedded_image_size,
24
27
  :party_pooper,
25
28
  :tailwind_purge_content,
26
- :queues
29
+ :queues,
30
+ :transliterations
27
31
 
28
- # Specify a backend path. Defaults to /admin.
32
+ # Defaults
33
+ self.authentication = "Spina::Authentication::Sessions"
29
34
  self.backend_path = 'admin'
30
-
31
- # The parent controller all frontend Spina controllers inherit from
32
- # Default is ApplicationController
33
- self.frontend_parent_controller = "ApplicationController"
34
-
35
35
  self.disable_frontend_routes = false
36
-
37
- self.max_page_depth = 5
38
-
36
+ self.disable_decorator_load = false
37
+ self.embedded_image_size = [2000, 2000]
38
+ self.frontend_parent_controller = "ApplicationController"
39
39
  self.locales = [I18n.default_locale]
40
+ self.party_pooper = false
41
+ self.transliterations = %i(latin)
40
42
 
41
- # Queues
43
+ # Queues for background jobs
44
+ # - config.queues.page_updates
42
45
  self.queues = ActiveSupport::InheritableOptions.new
43
46
 
44
- # Don't like confetti?
45
- self.party_pooper = false
47
+ # Tailwind purging
48
+ # Spina will by default purge all unused Tailwind classes by scanning
49
+ # the files listed below. You probably don't want to override this in
50
+ # your main app. Spina Plugins can add files to this array.
51
+ self.tailwind_purge_content = Spina::Engine.root.glob("app/views/**/*.*") +
52
+ Spina::Engine.root.glob("app/components/**/*.*") +
53
+ Spina::Engine.root.glob("app/helpers/**/*.*") +
54
+ Spina::Engine.root.glob("app/assets/javascripts/**/*.js") +
55
+ Spina::Engine.root.glob("app/**/tailwind/custom.css")
46
56
 
47
57
  # Images that are embedded in the Trix editor are resized to fit
48
58
  # You can optimize this for your website and go for a smaller (or larger) size
@@ -64,18 +74,4 @@ module Spina
64
74
  config_obj
65
75
  end
66
76
  end
67
-
68
- self.embedded_image_size = [2000, 2000]
69
-
70
-
71
- # Tailwind purging
72
- # Spina will by default purge all unused Tailwind classes by scanning
73
- # the files listed below. You probably don't want to override this in
74
- # your main app. Spina Plugins can add files to this array.
75
- self.tailwind_purge_content = Spina::Engine.root.glob("app/views/**/*.*") +
76
- Spina::Engine.root.glob("app/components/**/*.*") +
77
- Spina::Engine.root.glob("app/helpers/**/*.*") +
78
- Spina::Engine.root.glob("app/assets/javascripts/**/*.js") +
79
- Spina::Engine.root.glob("app/**/tailwind/custom.css")
80
-
81
77
  end
@@ -0,0 +1,24 @@
1
+ module Spina
2
+ module Authentication
3
+ module Basic
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ helper_method :logged_in?
8
+ end
9
+
10
+ def logged_in?
11
+ authenticate
12
+ end
13
+
14
+ private
15
+
16
+ def authenticate
17
+ authenticate_or_request_with_http_basic do |username, password|
18
+ username == Rails.application.credentials.dig(:spina, :username) && password == Rails.application.credentials.dig(:spina, :password)
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ module Spina
2
+ module Authentication
3
+ module Sessions
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ helper_method :current_spina_user
8
+ helper_method :logged_in?
9
+ helper_method :logout_path
10
+ end
11
+
12
+ def current_spina_user
13
+ Spina::Current.user ||= User.find_by(id: session[:spina_user_id]) if session[:spina_user_id]
14
+ end
15
+
16
+ def logged_in?
17
+ current_spina_user
18
+ end
19
+
20
+ def logout_path
21
+ spina.admin_logout_path
22
+ end
23
+
24
+ private
25
+
26
+ def authenticate
27
+ redirect_to admin_login_path, flash: {information: I18n.t('spina.notifications.login')} unless logged_in?
28
+ end
29
+
30
+ end
31
+ end
32
+ end
data/lib/spina/engine.rb CHANGED
@@ -6,6 +6,7 @@ require 'breadcrumbs_on_rails'
6
6
  require 'kaminari'
7
7
  require 'mobility'
8
8
  require 'rack-rewrite'
9
+ require 'babosa'
9
10
  require 'attr_json'
10
11
  require 'view_component/engine'
11
12
 
@@ -15,10 +16,12 @@ module Spina
15
16
 
16
17
  config.autoload_paths += %W( #{config.root}/lib )
17
18
 
18
- config.to_prepare do
19
+ config.to_prepare do
19
20
  # Require decorators from main application
20
- [Rails.root].flatten.map { |p| Dir[p.join('app', 'decorators', '**', '*_decorator.rb')]}.flatten.uniq.each do |decorator|
21
- Rails.configuration.cache_classes ? require(decorator) : load(decorator)
21
+ unless Spina.config.disable_decorator_load
22
+ Dir.glob(Rails.root + "app/decorators/**/*_decorator.rb").each do |decorator|
23
+ require_dependency(decorator)
24
+ end
22
25
  end
23
26
 
24
27
  # Register JSON part types for editing content
data/lib/spina/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spina
2
- VERSION = "2.1.1"
2
+ VERSION = "2.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spina
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bram Jetten
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-13 00:00:00.000000000 Z
11
+ date: 2021-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -206,6 +206,20 @@ dependencies:
206
206
  - - ">="
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: babosa
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
209
223
  description: CMS
210
224
  email:
211
225
  - bram@denkgroot.com
@@ -851,7 +865,8 @@ files:
851
865
  - app/components/spina/user_interface/modal_component.rb
852
866
  - app/components/spina/user_interface/tab_link_component.html.erb
853
867
  - app/components/spina/user_interface/tab_link_component.rb
854
- - app/controllers/concerns/spina/current_methods.rb
868
+ - app/controllers/concerns/spina/current_account.rb
869
+ - app/controllers/concerns/spina/current_theme.rb
855
870
  - app/controllers/concerns/spina/frontend.rb
856
871
  - app/controllers/spina/admin/accounts_controller.rb
857
872
  - app/controllers/spina/admin/admin_controller.rb
@@ -1035,6 +1050,8 @@ files:
1035
1050
  - lib/spina/admin_sectionable.rb
1036
1051
  - lib/spina/attr_json_monkeypatch.rb
1037
1052
  - lib/spina/attr_json_spina_parts_model.rb
1053
+ - lib/spina/authentication/basic.rb
1054
+ - lib/spina/authentication/sessions.rb
1038
1055
  - lib/spina/engine.rb
1039
1056
  - lib/spina/importmap_helper.rb
1040
1057
  - lib/spina/part.rb
@@ -1,34 +0,0 @@
1
- module Spina
2
- module CurrentMethods
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- before_action :set_current_attributes
7
-
8
- helper_method :current_theme
9
- helper_method :current_spina_user
10
- helper_method :current_account
11
- end
12
-
13
- private
14
-
15
- def set_current_attributes
16
- current_theme
17
- current_spina_user
18
- current_account
19
- end
20
-
21
- def current_theme
22
- Spina::Current.theme ||= ::Spina::Theme.find_by_name(current_account.theme)
23
- end
24
-
25
- def current_spina_user
26
- Spina::Current.user ||= ::Spina::User.find_by(id: session[:spina_user_id]) if session[:spina_user_id]
27
- end
28
-
29
- def current_account
30
- Spina::Current.account ||= ::Spina::Account.first
31
- end
32
-
33
- end
34
- end