tramway-admin 4.1 → 4.1.1.1

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: 78639584bbf4b055028b8d32816434c049812c9aa8711fdfcc4c988b22e4d28a
4
- data.tar.gz: fd5f663efbceab4b1ac6aa2276488a2b7f5b287db196564b72419da25f1f2743
3
+ metadata.gz: 6c2958bb2c4d589dbd96ba4fda743bf07db1c9edfa2ac2eeb76a9bd9abdaa752
4
+ data.tar.gz: bc0e26d6d14388987f8d1b107013553ed29f9b29c9cb11a9d4f4cde288fdbc11
5
5
  SHA512:
6
- metadata.gz: d18a9fcb50694c039bfa5bcd702391260312cdc88eaa45922d35564b0a34cdda6049f55299d482a5dfb71ccbc4d3d38407a17156cdcf9705ab89fa6f89a35226
7
- data.tar.gz: 1b8472ecb0adb65f49146cb5896d1757e82e96e07a3ede8c191bcc3f31ceaf0ab3444430b0a9e023dd8179032338b94ebfc975dae7529e81e4e665fe4c31e9a3
6
+ metadata.gz: 48586d888af6d540411509a5b60941a8a05c76d5178158a6366118de16bdd0300bf109e6232ec63b40b02de1ac96a30ad28a87db58c9f6d3d94b1fba30013833
7
+ data.tar.gz: 14ad23a6e151bf9c86e390e2b8b14ab7bc04e3bdbd0cf166e25e5425bd01ada302d5ffcf08b487410ec57eccee4365e611d7ef0dc2fc2c0686fce39801d4c782
data/README.md CHANGED
@@ -574,6 +574,13 @@ end
574
574
 
575
575
  * **Model or Form is not available** - `params[:model]` or `params[:form]` is empty **OR** current user does not have access to model or form in `params[:model]` or `params[:form]`
576
576
 
577
+ ## Change admin user base model
578
+
579
+ *config/initializers/tramway.rb*
580
+ ```ruby
581
+ ::Tramway::Admin.auth_config = { user_model: User, auth_attributes: %i[email username] }
582
+ ```
583
+
577
584
  ## Good features
578
585
 
579
586
  ### Get actions log in admin panel
@@ -20,6 +20,10 @@ module Tramway
20
20
 
21
21
  protected
22
22
 
23
+ def admin_model
24
+ ::Tramway::Admin.admin_model
25
+ end
26
+
23
27
  def check_available!
24
28
  raise 'Tramway::Admin - Model or Form is not available. Looks like current user does not have access to change this model. Update your tramway initializer file' if !model_given? && !form_given?
25
29
  end
@@ -120,7 +124,7 @@ module Tramway
120
124
  end
121
125
 
122
126
  def current_admin
123
- user = Tramway::User::User.find_by id: session[:admin_id]
127
+ user = admin_model.find_by id: session[:admin_id]
124
128
  return false unless user
125
129
 
126
130
  Tramway::User::UserDecorator.decorate user
@@ -6,11 +6,11 @@ class Tramway::Admin::SessionsController < ::Tramway::Admin::ApplicationControll
6
6
  skip_before_action :collections_counts
7
7
 
8
8
  def new
9
- @session_form = ::Tramway::Auth::SessionForm.new ::Tramway::User::User.new
9
+ @session_form = ::Tramway::Auth::SessionForm.new admin_model.new
10
10
  end
11
11
 
12
12
  def create
13
- @session_form = ::Tramway::Auth::SessionForm.new ::Tramway::User::User.find_or_initialize_by email: params[:user][:email]
13
+ @session_form = ::Tramway::Auth::SessionForm.new admin_model.find_or_initialize_by email: params[:user][:email]
14
14
  if @session_form.validate params[:user]
15
15
  admin_sign_in @session_form.model
16
16
  redirect_to Tramway::Admin::Engine.routes.url_helpers.root_path
@@ -29,7 +29,7 @@ module Tramway
29
29
  end
30
30
 
31
31
  def current_admin
32
- user = Tramway::User::User.find_by id: session[:admin_id]
32
+ user = Tramway::Admin.admin_model.find_by id: session[:admin_id]
33
33
  return false unless user
34
34
 
35
35
  Tramway::User::UserDecorator.decorate user
@@ -1,5 +1,4 @@
1
1
  %nav.navbar.navbar-expand-md.navbar-dark.bg-dark
2
- -# FIXME use helper methods
3
2
  - if ::Tramway::Admin.customized_admin_navbar.present?
4
3
  = ::Tramway::Admin.customized_admin_navbar
5
4
  - else
@@ -54,8 +53,6 @@
54
53
  %span.badge.badge-light
55
54
  = @notifications_count
56
55
  %li.nav-item
57
- -# FIXME url_helpers return with /admin for some reason
58
- -#= link_to Tramway::Auth::Engine.routes.url_helpers.session_path(model: Tramway::User::User).sub('/admin', ''), method: :delete, class: 'nav-link' do
59
56
  = link_to '/admin/sign_out', class: 'nav-link' do
60
57
  = fa_icon 'sign-out-alt'
61
58
  = t('helpers.links.sign_out')
@@ -3,8 +3,9 @@
3
3
  .d-flex.flex-row-reverse.filters
4
4
  = form_tag records_path, class: 'form-inline', method: :get do |f|
5
5
  - if searchable_model?(model_class)
6
- .col-md-8
6
+ .input-group
7
7
  = text_field_tag :search, params[:search], class: 'text form-control'
8
+ = submit_tag t('helpers.actions.search'), class: 'btn btn-primary'
8
9
  = hidden_field_tag :model, params[:model]
9
10
  = hidden_field_tag :scope, params[:scope]
10
11
  = hidden_field_tag :filter, (params[:filter].is_a?(ActionController::Parameters) ? params[:filter].permit!.to_h.to_json : params[:filter])
@@ -31,5 +32,3 @@
31
32
  $('#filter_datepicker_begin_date').datepicker();
32
33
  $('#filter_datepicker_end_date').datepicker();
33
34
  });
34
- .col-md-4.submit
35
- = submit_tag t('helpers.actions.search'), class: 'btn btn-primary'
@@ -15,7 +15,7 @@
15
15
  .col
16
16
  = render 'search', model_class: model_class
17
17
  %hr
18
- %ul.nav.nav-tabs
18
+ %ul.nav.nav-tabs.mb-3
19
19
  - if params[:search].present?
20
20
  %li.nav-item
21
21
  = link_to search_tab_title(@records.total_count), '#', class: 'nav-link active'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Admin
5
- VERSION = '4.1'
5
+ VERSION = '4.1.1.1'
6
6
  end
7
7
  end
data/lib/tramway/admin.rb CHANGED
@@ -79,6 +79,37 @@ module Tramway
79
79
  new_hash.merge! pair[0].to_s => pair[1]
80
80
  end
81
81
  end
82
+
83
+ def admin_model
84
+ auth_config.first[:user_model]
85
+ end
86
+
87
+ def auth_config
88
+ @@auth_config ||= [{ user_model: ::Tramway::User::User, auth_attributes: :email }]
89
+ @@auth_config
90
+ end
91
+
92
+ def auth_config=(params)
93
+ if params.is_a? Hash
94
+ @@auth_config = [params]
95
+ elsif params.is_a? Array
96
+ @@auth_config = params
97
+ end
98
+ end
99
+
100
+ def user_based_models
101
+ @@auth_config ||= []
102
+ @@auth_config.map do |conf|
103
+ conf[:user_model]
104
+ end
105
+ end
106
+
107
+ def auth_attributes
108
+ @@auth_config ||= []
109
+ @@auth_config.reduce({}) do |hash, conf|
110
+ hash.merge! conf[:user_model] => conf[:auth_attributes]
111
+ end
112
+ end
82
113
  end
83
114
  end
84
115
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: '4.1'
4
+ version: 4.1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-14 00:00:00.000000000 Z
11
+ date: 2022-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tramway-core