tramway-admin 4.1.0.1 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b44fe24bffc41f9e73369d01d70066b3454fae31e483ba3b83b13a81efd0fbf
4
- data.tar.gz: 21f8c5c22448dc3ac1df74ad91cfc8a1fa4ce82f684bcaf990cc1478549ccb87
3
+ metadata.gz: 52f598a393f67ead5da2a67ef98a7b721edea4cda7c5968dcc5fe2224c75ba11
4
+ data.tar.gz: 4ea29fb442be1e667e843c813dd4dba340672add79d93437abd3226852e6f8a8
5
5
  SHA512:
6
- metadata.gz: 31923f43c6a572341ef1c5561630bae7358a6c943651ed044e45a2a03bdb53e1fe6d85d2cda346829219d14b7fb98c060b8266fa05dc6a84707721fca8621e4e
7
- data.tar.gz: 5873f1f00d1eb3f989d42ac9a3767c38a211ca3b456072ddd6e2c5fed9bd4bf3d1eae7109801ae2902821d397ede0dfb9ad722f37d5e4e319a089ff0cebe4676
6
+ metadata.gz: 00645c93a5d1e36ad76fe059a9fd775146614cb8be7046c119f186bf9f81b00aefe636af0e56cebdebbe8abee5b4b288d3e3f0156bff8e35d336a574c13b555c
7
+ data.tar.gz: cdc9339fac651475ea6853d70096cf2ad3c7826d80668d61feb96012749e16e3f37d09310fbe4dfdedaf58a2457cae8b794ad82be98ea9b1895032d60f12fae6
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')
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Admin
5
- VERSION = '4.1.0.1'
5
+ VERSION = '4.1.1'
6
6
  end
7
7
  end
data/lib/tramway/admin.rb CHANGED
@@ -79,6 +79,36 @@ 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
+ end
90
+
91
+ def auth_config=(params)
92
+ if params.is_a? Hash
93
+ @@auth_config = [params]
94
+ elsif params.is_a? Array
95
+ @@auth_config = params
96
+ end
97
+ end
98
+
99
+ def user_based_models
100
+ @@auth_config ||= []
101
+ @@auth_config.map do |conf|
102
+ conf[:user_model]
103
+ end
104
+ end
105
+
106
+ def auth_attributes
107
+ @@auth_config ||= []
108
+ @@auth_config.reduce({}) do |hash, conf|
109
+ hash.merge! conf[:user_model] => conf[:auth_attributes]
110
+ end
111
+ end
82
112
  end
83
113
  end
84
114
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0.1
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov