lato_users 3.0.5 → 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: 2273db9841cc0ac86b190bd03990a5afd85f5a674b6a9bb7c31246734d1606c1
4
- data.tar.gz: 6c4efa1fc4663fead09db714d9e2e2427c60a634150983b49424e500359ece2e
3
+ metadata.gz: 80a39d7a9f51a107f6e8a18bff242e2d7a241c9117b26b24f9d28f70247b98cd
4
+ data.tar.gz: 527e1c61ddddbb3654ae4777204a18f13f72e0aaeb676885127fa4c364aee1fa
5
5
  SHA512:
6
- metadata.gz: 52157baaa30e4d3d168dfb3739f379372993b5989879ab8b4627e51efe9e835375af2e3dd687843240a287d0c7ed37a08879dc4a83642d5b513b684eeed1db42
7
- data.tar.gz: 1123f350f197ae5f5869688a3ee8f63cc8c25ce6531a2f0eebd6f41d95e2160b832606a684fcb4c27a3069ead1c12b894e463e79af36a967459f8b696b27355d
6
+ metadata.gz: f9d97d2b565d701e27c3b11437a5228a4b59d2b3240dbe7d5aed8067a15f79c5de0b71e1bdbfd13bf96c90ef80e9aeeb6180642680edcb2a4d50d89f672cf154
7
+ data.tar.gz: 22f1720480e013b4280f039ff9533ae4177990992fbcc255dbc2ab8007e60e9aa678c070976905dfd49b81c9ea9df42f653cdcb7b66d35dfd408f3e5574c4ebe
data/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  Manage application users on Lato projects.
4
4
 
5
5
  ## Installation
6
+
7
+ Requires Rails 8.1.3.1 or newer in the 8.1 series and Lato 3.25.0 or newer. Existing applications must install the new Lato session migration before deployment; previous sessions are invalidated.
6
8
  Add required dependencies to your application's Gemfile:
7
9
 
8
10
  ```ruby
@@ -40,7 +40,7 @@ module LatoUsers
40
40
  def update
41
41
  @user = Lato::User.find(params[:id])
42
42
  if @user.update(user_params)
43
- redirect_to(params[:redirect_to] || users_path)
43
+ redirect_to(url_from(params[:redirect_to]) || users_path)
44
44
  else
45
45
  render 'edit'
46
46
  end
@@ -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.7"
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.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante
@@ -15,28 +15,34 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 7.1.1
18
+ version: 8.1.3.1
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '8.2'
19
22
  type: :runtime
20
23
  prerelease: false
21
24
  version_requirements: !ruby/object:Gem::Requirement
22
25
  requirements:
23
26
  - - ">="
24
27
  - !ruby/object:Gem::Version
25
- version: 7.1.1
28
+ version: 8.1.3.1
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '8.2'
26
32
  - !ruby/object:Gem::Dependency
27
33
  name: lato
28
34
  requirement: !ruby/object:Gem::Requirement
29
35
  requirements:
30
36
  - - ">="
31
37
  - !ruby/object:Gem::Version
32
- version: '0'
38
+ version: 3.25.0
33
39
  type: :runtime
34
40
  prerelease: false
35
41
  version_requirements: !ruby/object:Gem::Requirement
36
42
  requirements:
37
43
  - - ">="
38
44
  - !ruby/object:Gem::Version
39
- version: '0'
45
+ version: 3.25.0
40
46
  description: A Rails engine to manage application users on Lato projects!
41
47
  email:
42
48
  - me@gregoriogalante.com