tybo 0.0.12 → 0.0.14

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: ff316ce32e05b03bd95e99c31631d2c3b8254ec8dce7b592c2860558aaa1d1ff
4
- data.tar.gz: 955dea95c34aaa8ca1eedcdc63fadc91cdbf962ce3c83f6ea99947c5f2b4e563
3
+ metadata.gz: f3e1659738fc5081c5c1f749ee9f5319bda7d3a6c14e00057f6bda6c637080fc
4
+ data.tar.gz: b1c45b98c8a241ee91fa5b3a8a6d8b0be15d5f7fae59c7678b7f2f42480af442
5
5
  SHA512:
6
- metadata.gz: 98f3f107ddb3ad5cd000170ddb9f2ab049a6f2d1cd816467815f99c4c8ba507148e824f4a81d0aede83eae04fa7e24f81a3a5e7a98c630439d35eae8bd5076be
7
- data.tar.gz: 6124736a64b0f9f92f6510e942552c4e72912dcc0297ea367b531ba0cd4bbcf152b7078a6885e4fe05035fa573cde8b1eab66b4a3210830257a997208538e108
6
+ metadata.gz: 40755097ff8fc2b01d7f49e189645c548cea5c3d32bc12df6e3d4f6b498649e0a541f4a4dcbc0dd54e748539b1acb013fab0aa6cfe2b24471ae53f5a28637739
7
+ data.tar.gz: 62597ee9ddf4815d0029e5be88ec1c515c4d8de5959b51e3f7392acfc35d49c8c3203422fbe6e9a5ee1326d53ab212a6b8ab0b96fc688624bf0617b4be3c28fa
data/README.md CHANGED
@@ -34,6 +34,18 @@ $ bundle exec rails g tybo_install
34
34
 
35
35
  ```
36
36
 
37
+ ## Policy
38
+ add your policy logic in ApplicationController eg:
39
+ ```
40
+ rescue_from ActionPolicy::Unauthorized, with: :not_authorized
41
+
42
+
43
+ def not_authorized
44
+ flash[:alert] = I18n.t('bo.unauthorized')
45
+ redirect_to(request.referrer || root_path)
46
+ end
47
+ ```
48
+
37
49
  ## Customize
38
50
 
39
51
  **Update images**: change `logo_url` and `cover_url` in `config/initializer/tybo.rb`
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tybo
2
4
  class ApplicationController < ActionController::Base
3
5
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Tybo::LoginController < ::ApplicationController
3
4
  layout 'devise_admin'
4
5
  def home
@@ -19,6 +19,10 @@ class BoGenerator < Rails::Generators::NamedBase
19
19
  template '_search_bar.html.erb', File.join("app/views/#{options[:namespace]}", "#{plural_name}/_search_bar.html.erb")
20
20
  template 'show.html.erb', File.join("app/views/#{options[:namespace]}", "#{plural_name}/show.html.erb")
21
21
  template 'controller.rb', File.join("app/controllers/#{options[:namespace]}", "#{plural_name}_controller.rb")
22
+ template 'policy.rb', File.join("app/policies/bo/#{options[:namespace]}", "#{file_name.underscore}_policy.rb")
23
+ unless File.exists?("app/policies/bo/#{options[:namespace]}.rb")
24
+ template 'namespace_policy.rb', "app/policies/bo/#{options[:namespace]}_policy.rb"
25
+ end
22
26
  create_translations
23
27
  end
24
28
 
@@ -65,7 +69,7 @@ class BoGenerator < Rails::Generators::NamedBase
65
69
 
66
70
  def permited_params
67
71
  params = {}
68
- action_text_columns= has_one_assoc&.select {|a| a.name == :rich_text_content}
72
+ action_text_columns = has_one_assoc&.select { |a| a.options[:class_name] == 'ActionText::RichText' }
69
73
  model_columns&.map do |col|
70
74
  params["#{col}".to_sym] = nil
71
75
  end
@@ -76,8 +80,10 @@ class BoGenerator < Rails::Generators::NamedBase
76
80
  params["#{association.name.to_s.singularize}_ids".to_sym] = []
77
81
  end
78
82
  has_one_assoc&.map do |association|
79
- attributes = association.klass.column_names.map(&:to_sym).delete_if {|attr| excluded_columns.include?(attr)}
80
- params["#{association.name.to_s.singularize}_attributes".to_sym] = attributes
83
+ next if association.options[:class_name] == 'ActionText::RichText'
84
+
85
+ attributes = association.klass.column_names.map(&:to_sym).delete_if { |attr| excluded_columns.include?(attr) }
86
+ params["#{association.name.to_s.singularize}_attributes".to_sym] = attributes
81
87
  end
82
88
  params
83
89
  end
@@ -2,7 +2,7 @@
2
2
  <!-- Model columns -->
3
3
  <%- bo_model.column_names.each do |column| -%>
4
4
  <%- next if excluded_columns.include?(column.to_sym) || bo_model.reflect_on_all_associations.map(&:foreign_key).include?(column) -%>
5
- <%%= f.input :<%= column %> %>
5
+ <%%= f.input :<%= column %>,label: I18n.t('bo.<%= class_name.underscore %>.attributes.<%= column %>') %>
6
6
  <%- end -%>
7
7
  <!-- belongs_to Associations -->
8
8
  <%- belongs_to_assoc.each do |association| -%>
@@ -11,7 +11,10 @@
11
11
  <!-- has_one Associations -->
12
12
  <%- has_one_assoc.each do |association| -%>
13
13
  <%- if association.options[:class_name] == "ActionText::RichText" -%>
14
- <%%= f.rich_text_area :<%= association.name.to_s.singularize.to_s.remove('rich_text_' )%> %>
14
+ <label class="block my-5 block text-sm font-medium text-gray-700 string optional text-sm font-medium text-gray-600">
15
+ <%%= I18n.t('bo.<%= class_name.underscore %>.attributes.<%=- association.name.to_s.singularize.to_s.remove('rich_text_') -%>') %>
16
+ </label>
17
+ <%%= f.rich_text_area :<%= association.name.to_s.singularize.to_s.remove('rich_text_')%> %>
15
18
  <%- else -%>
16
19
  <%%= render(Forms::HasOneFormComponent.new(title: I18n.t('bo.<%= association.name %>.one') )) do %>
17
20
  <%%= f.simple_fields_for :<%= association.name.to_s %> do |<%= association.name.to_s %>_form| %>
@@ -5,11 +5,15 @@ module <%= options[:namespace].camelize %>
5
5
  before_action :set_<%= class_name.underscore %>, only: %i[show edit destroy update]
6
6
 
7
7
  def index
8
- @q = <%=class_name%>.ransack(params[:q])
8
+ @q = authorized_scope(
9
+ <%=class_name%>.all,
10
+ with: Bo::<%= options[:namespace].camelize %>::<%= class_name %>Policy
11
+ ).ransack(params[:q])
9
12
  @pagy, @<%= class_name.pluralize.underscore %> = pagy(@q.result(distinct: true))
10
13
  end
11
14
 
12
15
  def show
16
+ authorize! @<%= class_name.underscore %>, to: :show?, namespace:, strict_namespace: true
13
17
  <%- has_one_assoc.each do |association| -%>
14
18
  <%- next if association.options[:class_name] == "ActionText::RichText" -%>
15
19
  @<%= class_name.underscore %>.build_<%= association.name %> if @<%= class_name.underscore %>.<%= association.name %>.nil?
@@ -18,16 +22,20 @@ module <%= options[:namespace].camelize %>
18
22
 
19
23
  def new
20
24
  @<%= class_name.underscore %> = <%= class_name %>.new
25
+ authorize! @<%= class_name.underscore %>, to: :new?, namespace:, strict_namespace: true
21
26
  <%- has_one_assoc.each do |association| -%>
22
27
  <%- next if association.options[:class_name] == "ActionText::RichText" -%>
23
28
  @<%= class_name.underscore %>.build_<%= association.name %>
24
29
  <%- end -%>
25
30
  end
26
31
 
27
- def edit; end
32
+ def edit
33
+ authorize! @<%= class_name.underscore %>, to: :edit?, namespace:, strict_namespace: true
34
+ end
28
35
 
29
36
  def create
30
37
  @<%= class_name.underscore %> = <%= class_name %>.new(<%= class_name.underscore %>_params)
38
+ authorize! @<%= class_name.underscore %>, to: :create?, namespace:, strict_namespace: true
31
39
 
32
40
  if @<%= class_name.underscore %>.save
33
41
  flash[:success] = t('bo.record.created')
@@ -38,6 +46,8 @@ module <%= options[:namespace].camelize %>
38
46
  end
39
47
 
40
48
  def update
49
+ authorize! @<%= class_name.underscore %>, to: :update?, namespace:, strict_namespace: true
50
+
41
51
  if @<%= class_name.underscore %>.update(<%= class_name.underscore %>_params)
42
52
  flash[:success] = t('bo.record.updated')
43
53
  redirect_to <%="#{options[:namespace]}_#{class_name.underscore}_path"%>
@@ -47,6 +57,8 @@ module <%= options[:namespace].camelize %>
47
57
  end
48
58
 
49
59
  def destroy
60
+ authorize! @<%= class_name.underscore %>, to: :destroy?, namespace:, strict_namespace: true
61
+
50
62
  @<%= class_name.underscore %>.destroy
51
63
  flash[:success] = t('bo.record.destroyed')
52
64
 
@@ -70,5 +82,9 @@ module <%= options[:namespace].camelize %>
70
82
  <%- end -%>
71
83
  )
72
84
  end
85
+
86
+ def namespace
87
+ @namespace ||= Bo::<%= options[:namespace].camelize %>
88
+ end
73
89
  end
74
90
  end
@@ -0,0 +1,29 @@
1
+ module Bo
2
+ class <%= options[:namespace].camelize %>Policy < ActionPolicy::Base
3
+ def show?
4
+ raise "Add custom policy scope in #{__FILE__}"
5
+ end
6
+
7
+ def new?
8
+ raise "Add custom policy scope in #{__FILE__}"
9
+ end
10
+
11
+ def edit?
12
+ raise "Add custom policy scope in #{__FILE__}"
13
+ end
14
+
15
+ def create?
16
+ raise "Add custom policy scope in #{__FILE__}"
17
+ end
18
+
19
+ def update?
20
+ raise "Add custom policy scope in #{__FILE__}"
21
+ end
22
+
23
+ def destroy?
24
+ raise "Add custom policy scope in #{__FILE__}"
25
+ end
26
+
27
+ relation_scope(&:all)
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ module Bo
2
+ module <%= options[:namespace].camelize %>
3
+ class <%= class_name %>Policy < Bo::<%= options[:namespace].camelize %>Policy
4
+ end
5
+ end
6
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class BoNamespaceGenerator < Rails::Generators::NamedBase
2
4
  source_root File.expand_path("templates", __dir__)
3
5
 
@@ -4,4 +4,5 @@ class <%= class_name %>Controller < ApplicationController
4
4
  include Pagy::Backend
5
5
  layout '<%= class_name.underscore %>'
6
6
  before_action :authenticate_<%= class_name.underscore %>!
7
+ authorize :user, through: :current_<%= class_name.underscore %>
7
8
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bo
4
+ class <%= class_name %>Policy < ActionPolicy::Base
5
+ end
6
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Tybo.configure do |config|
2
4
  # customise logo and cover url
3
5
  # should be an external url or image should be present in (app/assets/images)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  class TyboInstallGenerator < Rails::Generators::Base
3
4
  source_root File.expand_path("templates", __dir__)
data/lib/tybo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tybo
2
- VERSION = '0.0.12'
2
+ VERSION = '0.0.14'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tybo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Delpierre
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-02-13 00:00:00.000000000 Z
12
+ date: 2023-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -241,7 +241,9 @@ files:
241
241
  - lib/generators/bo/templates/controller.rb
242
242
  - lib/generators/bo/templates/index.html.erb
243
243
  - lib/generators/bo/templates/item.html.erb
244
+ - lib/generators/bo/templates/namespace_policy.rb
244
245
  - lib/generators/bo/templates/new.html.erb
246
+ - lib/generators/bo/templates/policy.rb
245
247
  - lib/generators/bo/templates/show.html.erb
246
248
  - lib/generators/bo/utils/files/fr.json
247
249
  - lib/generators/bo/utils/translations.rb
@@ -249,6 +251,7 @@ files:
249
251
  - lib/generators/bo_namespace/bo_namespace_generator.rb
250
252
  - lib/generators/bo_namespace/templates/admin.html.erb
251
253
  - lib/generators/bo_namespace/templates/admin_controller.rb
254
+ - lib/generators/bo_namespace/templates/policy.rb
252
255
  - lib/generators/bo_namespace/templates/seeds.rb
253
256
  - lib/generators/bo_namespace/templates/side_bar.html.erb
254
257
  - lib/generators/tybo_install/templates/application.tailwind.css