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 +4 -4
- data/README.md +7 -0
- data/app/controllers/tramway/admin/application_controller.rb +5 -1
- data/app/controllers/tramway/admin/sessions_controller.rb +2 -2
- data/app/helpers/tramway/admin/application_helper.rb +1 -1
- data/app/views/layouts/tramway/admin/shared/_navbar.html.haml +0 -3
- data/lib/tramway/admin/version.rb +1 -1
- data/lib/tramway/admin.rb +30 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52f598a393f67ead5da2a67ef98a7b721edea4cda7c5968dcc5fe2224c75ba11
|
4
|
+
data.tar.gz: 4ea29fb442be1e667e843c813dd4dba340672add79d93437abd3226852e6f8a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
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
|
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
|
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
|
@@ -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')
|
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
|