tybo 0.0.12 → 0.0.13

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: 2159c6fe429376273f6ba05ab4009d6714a61c09a2fe9d9ad5395c23ad679f69
4
+ data.tar.gz: fedf0c5fc19e0d446fa3ce7ba4d32d8bf6aaf82b64b6138a1fef740cf8bc8c48
5
5
  SHA512:
6
- metadata.gz: 98f3f107ddb3ad5cd000170ddb9f2ab049a6f2d1cd816467815f99c4c8ba507148e824f4a81d0aede83eae04fa7e24f81a3a5e7a98c630439d35eae8bd5076be
7
- data.tar.gz: 6124736a64b0f9f92f6510e942552c4e72912dcc0297ea367b531ba0cd4bbcf152b7078a6885e4fe05035fa573cde8b1eab66b4a3210830257a997208538e108
6
+ metadata.gz: 02e9964ddfc462d39f6f4b112bf255036fe5a6fd76e6a40cf88cefa407f5ab7349a7c9b5e5707a38a5daa627fb676cef6789f7ca7367182846351e47b5202ada
7
+ data.tar.gz: d3d971269635d970e6b1d692b3c5ee489eb948b074eb1c93d01c092d8faba236d6e06fcee2d92f5220ea29514fa3d45097f84552d3e9753a1696cfbb793f4764
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`
@@ -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
@@ -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
+ true
5
+ end
6
+
7
+ def new?
8
+ true
9
+ end
10
+
11
+ def edit?
12
+ true
13
+ end
14
+
15
+ def create?
16
+ true
17
+ end
18
+
19
+ def update?
20
+ true
21
+ end
22
+
23
+ def destroy?
24
+ true
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
@@ -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,4 @@
1
+ module Bo
2
+ class <%= class_name %>Policy < ActionPolicy::Base
3
+ end
4
+ end
data/lib/tybo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tybo
2
- VERSION = '0.0.12'
2
+ VERSION = '0.0.13'
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.13
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-14 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