tramway-admin 4.1.0.1 → 4.1.1.2

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: 1b095e980505070f6ddb9ded9968c7f198be43e2ae59780ebc40d3c3d36a82bf
4
+ data.tar.gz: c7f39e7067138cb066efcaf42ce749be48ecccd95ce069a76d1e6e2e0e0507af
5
5
  SHA512:
6
- metadata.gz: 31923f43c6a572341ef1c5561630bae7358a6c943651ed044e45a2a03bdb53e1fe6d85d2cda346829219d14b7fb98c060b8266fa05dc6a84707721fca8621e4e
7
- data.tar.gz: 5873f1f00d1eb3f989d42ac9a3767c38a211ca3b456072ddd6e2c5fed9bd4bf3d1eae7109801ae2902821d397ede0dfb9ad722f37d5e4e319a089ff0cebe4676
6
+ metadata.gz: df4321ccd6d3ed5de4c3ed66eedc911b9cbe62eab20b9d6a92c8662a0cebd16bc3489dc22ab16d8459b22b2bc25ca3ddbb3fecb36642068eab5ff3531d16906b
7
+ data.tar.gz: 75c1af828a91e189d14e929b1d6ae75a6cdf9d2cbb9291c502ddca3de52104f062f470dcaaa2347a1892605d4d9f80be379b99209b5f1f6dd44cdaa124edbc9c
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')
@@ -10,7 +10,7 @@
10
10
  = link_to fa_icon('pencil-alt'), edit_path, class: 'btn btn-warning btn-xs'
11
11
  - if public_path(object)
12
12
  = link_to fa_icon(:share), public_path(object), class: 'btn btn-primary btn-xs'
13
- - buttons = object.additional_buttons[:show]
13
+ - buttons = object.additional_buttons&.dig :show
14
14
  - buttons&.each do |button|
15
15
  - build_button button
16
16
  %hr
@@ -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.2'
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.0.1
4
+ version: 4.1.1.2
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-18 00:00:00.000000000 Z
11
+ date: 2022-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tramway-core