lato_users 3.0.5 → 3.0.6

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: 2273db9841cc0ac86b190bd03990a5afd85f5a674b6a9bb7c31246734d1606c1
4
- data.tar.gz: 6c4efa1fc4663fead09db714d9e2e2427c60a634150983b49424e500359ece2e
3
+ metadata.gz: dcee2149bbb4d75dd166fce3e2008f9bdcebc58c9cc9c53a81beb1f7be78b412
4
+ data.tar.gz: 94f6f53942fca11cd59c28f82fc76a988de53e1f294f66f7ea35b90797726058
5
5
  SHA512:
6
- metadata.gz: 52157baaa30e4d3d168dfb3739f379372993b5989879ab8b4627e51efe9e835375af2e3dd687843240a287d0c7ed37a08879dc4a83642d5b513b684eeed1db42
7
- data.tar.gz: 1123f350f197ae5f5869688a3ee8f63cc8c25ce6531a2f0eebd6f41d95e2160b832606a684fcb4c27a3069ead1c12b894e463e79af36a967459f8b696b27355d
6
+ metadata.gz: 7748a34ffd5f3de2271bb42821fdc3f06a5d78bfe38ae321647862970ecf3ff98e1dc0b462435951734710d2e586da2aa0eab36808c541dfcf8db2b81528352a
7
+ data.tar.gz: f4a1bf6ea28450625008191e10132d3266b4cb832086bc183c4e3d6d6a5b61fdd6172d0cb26666cea76a85deaa891b5b33e3e08bb24a4d7ee8a3ae60b7579aae
@@ -99,11 +99,29 @@ module LatoUsers
99
99
  private
100
100
 
101
101
  def user_params
102
- params.require(:user).permit(:email, :first_name, :last_name, :password, :password_confirmation, @available_admin_permissions)
102
+ permission_keys = @available_admin_permissions.map { |permission| permission[:name] }
103
+ params.require(:user).permit(:email, :first_name, :last_name, :password, :password_confirmation, *permission_keys)
103
104
  end
104
105
 
106
+ # Discover admin permissions on Lato::User by column naming convention.
107
+ # Each engine (lato_cms, lato_spaces, ...) adds its own column:
108
+ # - `lato_*_admin` -> boolean, rendered as a checkbox
109
+ # - `lato_*_admin_role` -> integer enum, rendered as a select
105
110
  def load_available_admin_permissions
106
- @available_admin_permissions ||= Lato::User.columns.map(&:name).select { |c| c.start_with?('lato_') && c.end_with?('_admin') }
111
+ @available_admin_permissions ||= Lato::User.column_names.filter_map do |name|
112
+ if name.match?(/\Alato_.+_admin\z/)
113
+ { name: name, type: :boolean }
114
+ elsif name.match?(/\Alato_.+_admin_role\z/)
115
+ { name: name, type: :enum, options: admin_permission_options(name) }
116
+ end
117
+ end
118
+ end
119
+
120
+ # Enum options are owned by the engine that defines the column, exposed as a
121
+ # `Lato::User.<column>_options` class method returning [[label, value], ...].
122
+ def admin_permission_options(name)
123
+ options_method = "#{name}_options"
124
+ Lato::User.respond_to?(options_method) ? Lato::User.public_send(options_method) : []
107
125
  end
108
126
  end
109
127
  end
@@ -79,8 +79,15 @@ user ||= Lato::User.new
79
79
  <div class="accordion-body">
80
80
  <div class="row">
81
81
  <% @available_admin_permissions.each_with_index do |permission, index| %>
82
- <div class="col-12 col-md-6 <%= 'mb-3' unless index == @available_admin_permissions.size - 1 %>">
83
- <%= lato_form_item_input_check form, permission.to_sym, permission.humanize %>
82
+ <% is_enum = permission[:type] == :enum %>
83
+ <div class="<%= is_enum ? 'col-12' : 'col-12 col-md-6' %> <%= 'mb-3' unless index == @available_admin_permissions.size - 1 %>">
84
+ <% label = Lato::User.human_attribute_name(permission[:name]) %>
85
+ <% if is_enum %>
86
+ <%= lato_form_item_label form, permission[:name].to_sym, label %>
87
+ <%= lato_form_item_input_select form, permission[:name].to_sym, permission[:options] %>
88
+ <% else %>
89
+ <%= lato_form_item_input_check form, permission[:name].to_sym, label %>
90
+ <% end %>
84
91
  </div>
85
92
  <% end %>
86
93
  </div>
@@ -1,3 +1,3 @@
1
1
  module LatoUsers
2
- VERSION = "3.0.5"
2
+ VERSION = "3.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lato_users
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.5
4
+ version: 3.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante