tramway-admin 1.29.2 → 1.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/tramway/admin/application_controller.rb +18 -6
- data/app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb +8 -2
- data/app/controllers/tramway/admin/records_controller.rb +1 -1
- data/app/controllers/tramway/admin/sessions_controller.rb +40 -0
- data/app/helpers/tramway/admin/actions_helper.rb +2 -2
- data/app/helpers/tramway/admin/application_helper.rb +6 -1
- data/app/views/layouts/tramway/admin/shared/_navbar.html.haml +6 -4
- data/app/views/tramway/admin/sessions/new.html.haml +9 -0
- data/config/routes.rb +2 -1
- data/lib/tramway/admin/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a3193abc0ba418d70dc16809e03ed0dc6d81d7b426a7a0f14db0343cfcd3e54
|
4
|
+
data.tar.gz: b39d546781c693843e04dd1ed2a06ae50179e6880ee43217a4abb28330068fb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c68c4efbc9a38d060b1551e2873285238e08c3f64f87eb06652ecd49494f883b822e4683d95e1dcafa8d018ddba4885a11391833064842011bb3419d8b46c91
|
7
|
+
data.tar.gz: 767f2cc010f4255c29b33f24c42baf092214aba1d086d55e15c3fdd7ef0d8dd69d41e23f039301e85394a33c930ff2867550599345523a04955a8e68cc8b3c1e
|
@@ -31,7 +31,7 @@ module Tramway
|
|
31
31
|
def collections_counts
|
32
32
|
@counts = decorator_class.collections.reduce({}) do |hash, collection|
|
33
33
|
records = model_class.active.send(collection)
|
34
|
-
records = records.send "#{
|
34
|
+
records = records.send "#{current_admin.role}_scope", current_admin.id
|
35
35
|
records = records.ransack(params[:filter]).result if params[:filter].present?
|
36
36
|
hash.merge! collection => records.count
|
37
37
|
end
|
@@ -44,8 +44,10 @@ module Tramway
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def notifications
|
47
|
-
|
48
|
-
|
47
|
+
if current_admin
|
48
|
+
@notifications ||= Tramway::Admin.notificable_queries&.reduce({}) do |hash, notification|
|
49
|
+
hash.merge! notification[0] => notification[1].call(current_admin)
|
50
|
+
end
|
49
51
|
end
|
50
52
|
@notifications
|
51
53
|
end
|
@@ -76,7 +78,7 @@ module Tramway
|
|
76
78
|
end
|
77
79
|
|
78
80
|
def admin_form_class
|
79
|
-
"::#{
|
81
|
+
"::#{current_admin.role.camelize}::#{model_class}Form".constantize
|
80
82
|
end
|
81
83
|
|
82
84
|
def model_given?
|
@@ -89,7 +91,7 @@ module Tramway
|
|
89
91
|
# :tramway, :admin, :application_controller, :form_given, :model_not_included_to_tramway_admin,
|
90
92
|
# model: params[:model]
|
91
93
|
# )
|
92
|
-
raise "Looks like model #{params[:model]} is not included to tramway-admin for `#{
|
94
|
+
#raise "Looks like model #{params[:model]} is not included to tramway-admin for `#{current_admin.role}` role. Add it in the `config/initializers/tramway.rb`. This way `Tramway::Admin.set_available_models(#{params[:model]})`"
|
93
95
|
Tramway::Admin.forms.include? params[:form].underscore.sub(%r{^admin/}, '').sub(/_form$/, '')
|
94
96
|
end
|
95
97
|
|
@@ -105,12 +107,22 @@ module Tramway
|
|
105
107
|
check_models_given? :singleton
|
106
108
|
end
|
107
109
|
|
110
|
+
def current_admin
|
111
|
+
user = Tramway::User::User.find_by id: session[:admin_id]
|
112
|
+
return false unless user
|
113
|
+
Tramway::User::UserDecorator.decorate user
|
114
|
+
end
|
115
|
+
|
108
116
|
private
|
109
117
|
|
110
118
|
def check_models_given?(model_type)
|
111
|
-
models = ::Tramway::Admin.send("#{model_type}_models", role:
|
119
|
+
models = ::Tramway::Admin.send("#{model_type}_models", role: current_admin.role)
|
112
120
|
models.any? && params[:model].in?(models.map(&:to_s))
|
113
121
|
end
|
122
|
+
|
123
|
+
def authenticate_admin!
|
124
|
+
redirect_to '/admin/session/new' if !current_admin && !request.path.in?(['/admin/session/new', '/admin/session'])
|
125
|
+
end
|
114
126
|
end
|
115
127
|
end
|
116
128
|
end
|
@@ -3,8 +3,14 @@
|
|
3
3
|
class Tramway::Admin::HasAndBelongsToManyRecordsController < ::Tramway::Admin::ApplicationController
|
4
4
|
def create
|
5
5
|
base_object = params[:model_class].constantize.find params[:object_id]
|
6
|
-
|
7
|
-
|
6
|
+
form_class = params[:form].constantize
|
7
|
+
record_form = form_class.new base_object
|
8
|
+
sending_params = if params[params[:model_class].underscore].present?
|
9
|
+
params[params[:model_class].underscore]
|
10
|
+
else
|
11
|
+
params[form_class.associated_as]
|
12
|
+
end
|
13
|
+
if record_form.submit sending_params
|
8
14
|
redirect_to params[:redirect].present? ? params[:redirect] : record_path(base_object, model: base_object.class)
|
9
15
|
else
|
10
16
|
redirect_to params[:redirect].present? ? params[:redirect] : record_path(base_object, model: base_object.class)
|
@@ -6,7 +6,7 @@ class Tramway::Admin::RecordsController < ::Tramway::Admin::ApplicationControlle
|
|
6
6
|
records = model_class.active.order(id: :desc).send scope
|
7
7
|
records = records.full_text_search params[:search] if params[:search].present?
|
8
8
|
records = records.ransack(params[:filter]).result if params[:filter].present?
|
9
|
-
records = records.send "#{
|
9
|
+
records = records.send "#{current_admin.role}_scope", current_admin.id
|
10
10
|
@records = decorator_class.decorate records.page params[:page]
|
11
11
|
end
|
12
12
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Tramway::Admin::SessionsController < ::Tramway::Admin::ApplicationController
|
4
|
+
before_action :redirect_if_signed_in, except: :destroy
|
5
|
+
skip_before_action :check_available!
|
6
|
+
skip_before_action :collections_counts
|
7
|
+
|
8
|
+
def new
|
9
|
+
@session_form = ::Tramway::Auth::SessionForm.new ::Tramway::User::User.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
@session_form = ::Tramway::Auth::SessionForm.new ::Tramway::User::User.active.find_or_initialize_by email: params[:user][:email]
|
14
|
+
if @session_form.validate params[:user]
|
15
|
+
admin_sign_in @session_form.model
|
16
|
+
redirect_to Tramway::Admin::Engine.routes.url_helpers.root_path
|
17
|
+
else
|
18
|
+
render :new
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def destroy
|
23
|
+
admin_sign_out
|
24
|
+
redirect_to '/admin/session/new'
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def redirect_if_signed_in
|
30
|
+
redirect_to Tramway::Admin::Engine.routes.url_helpers.root_path if current_admin
|
31
|
+
end
|
32
|
+
|
33
|
+
def admin_sign_in(user)
|
34
|
+
session[:admin_id] = user.id
|
35
|
+
end
|
36
|
+
|
37
|
+
def admin_sign_out
|
38
|
+
session[:admin_id] = nil
|
39
|
+
end
|
40
|
+
end
|
@@ -6,7 +6,7 @@ module Tramway::Admin::ActionsHelper
|
|
6
6
|
association_object,
|
7
7
|
project: (@application_engine || @application.name),
|
8
8
|
model_name: association_object.model.class.name,
|
9
|
-
role:
|
9
|
+
role: current_admin.role,
|
10
10
|
action: :destroy
|
11
11
|
)
|
12
12
|
end
|
@@ -16,7 +16,7 @@ module Tramway::Admin::ActionsHelper
|
|
16
16
|
association_object,
|
17
17
|
project: (@application_engine || @application.name),
|
18
18
|
model_name: association_object.model.class.name,
|
19
|
-
role:
|
19
|
+
role: current_admin.role,
|
20
20
|
action: :update
|
21
21
|
)
|
22
22
|
end
|
@@ -4,7 +4,6 @@ module Tramway
|
|
4
4
|
module Admin
|
5
5
|
module ApplicationHelper
|
6
6
|
include ::FontAwesome5::Rails::IconHelper
|
7
|
-
include AuthManagement
|
8
7
|
include AdditionalButtonsBuilder
|
9
8
|
include ::SmartButtons
|
10
9
|
include CasesHelper
|
@@ -26,6 +25,12 @@ module Tramway
|
|
26
25
|
end
|
27
26
|
::Tramway::Admin.available_models_for(@application_engine || @application.name).map(&:to_s).include?(object_class_name) ? :record : :singleton
|
28
27
|
end
|
28
|
+
|
29
|
+
def current_admin
|
30
|
+
user = Tramway::User::User.find_by id: session[:admin_id]
|
31
|
+
return false unless user
|
32
|
+
Tramway::User::UserDecorator.decorate user
|
33
|
+
end
|
29
34
|
end
|
30
35
|
end
|
31
36
|
end
|
@@ -7,9 +7,9 @@
|
|
7
7
|
%button.navbar-toggler.collapsed{ aria: { controls: :navbar, expanded: "false", label: 'Toggle Navigation' }, data: { target: "#navbar", toggle: :collapse }, type: :button }
|
8
8
|
%span.navbar-toggler-icon
|
9
9
|
.navbar-collapse.collapse#navbar
|
10
|
-
- if
|
10
|
+
- if current_admin
|
11
11
|
%ul.navbar-nav
|
12
|
-
- ::Tramway::Admin.navbar_items_for(@application_engine || @application.name, role:
|
12
|
+
- ::Tramway::Admin.navbar_items_for(@application_engine || @application.name, role: current_admin.role)&.each do |item|
|
13
13
|
- case item.keys.first
|
14
14
|
- when Class
|
15
15
|
- model = item.keys.first
|
@@ -31,7 +31,7 @@
|
|
31
31
|
= dropdown_model_item model: model, route: ::Tramway::Admin::Engine.routes.url_helpers.records_path(model: model, scope: decorator_class(model).collections.first), pluralize: plural(model.model_name).capitalize
|
32
32
|
|
33
33
|
%ul.nav.navbar-nav.ml-auto
|
34
|
-
- if
|
34
|
+
- if current_admin
|
35
35
|
- if @notifications_count.present?
|
36
36
|
- if @notifications_count > 0
|
37
37
|
%li.nav-item.dropdown.notifications
|
@@ -50,7 +50,9 @@
|
|
50
50
|
%span.badge.badge-light
|
51
51
|
= @notifications_count
|
52
52
|
%li.nav-item
|
53
|
-
|
53
|
+
-# FIXME url_helpers return with /admin for some reason
|
54
|
+
-#= link_to Tramway::Auth::Engine.routes.url_helpers.session_path(model: Tramway::User::User).sub('/admin', ''), method: :delete, class: 'nav-link' do
|
55
|
+
= link_to '/admin/sign_out', class: 'nav-link' do
|
54
56
|
= fa_icon 'sign-out-alt'
|
55
57
|
= t('helpers.links.sign_out')
|
56
58
|
- else
|
@@ -0,0 +1,9 @@
|
|
1
|
+
- title
|
2
|
+
.row
|
3
|
+
.col-md-6
|
4
|
+
= simple_form_for @session_form.model, url: '/admin/session', method: :post, html: { class: 'form-horizontal' } do |f|
|
5
|
+
= f.input :email, as: :string
|
6
|
+
= f.input :password
|
7
|
+
= hidden_field_tag :model, @session_form.model.class.to_s
|
8
|
+
= hidden_field_tag :redirect, Tramway::Admin::Engine.routes.url_helpers.root_path
|
9
|
+
= f.button :submit, t('helpers.links.enter'), class: 'btn btn-success'
|
data/config/routes.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Tramway::Admin::Engine.routes.draw do
|
4
|
-
mount Tramway::Auth::Engine, at: '/auth'
|
5
4
|
mount Tramway::Export::Engine, at: '/' if defined? Tramway::Export::Engine
|
6
5
|
|
7
6
|
root to: 'welcome#index'
|
@@ -9,4 +8,6 @@ Tramway::Admin::Engine.routes.draw do
|
|
9
8
|
resources :records
|
10
9
|
resource :singleton, only: %i[new create show edit update]
|
11
10
|
resources :has_and_belongs_to_many_records, only: %i[create destroy]
|
11
|
+
resource :session, only: %i[new create]
|
12
|
+
get 'sign_out', to: 'sessions#destroy'
|
12
13
|
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: 1.
|
4
|
+
version: '1.30'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Kalashnikov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bootstrap-kaminari-views
|
@@ -183,6 +183,7 @@ files:
|
|
183
183
|
- app/controllers/tramway/admin/application_controller.rb
|
184
184
|
- app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
|
185
185
|
- app/controllers/tramway/admin/records_controller.rb
|
186
|
+
- app/controllers/tramway/admin/sessions_controller.rb
|
186
187
|
- app/controllers/tramway/admin/singletons_controller.rb
|
187
188
|
- app/controllers/tramway/admin/welcome_controller.rb
|
188
189
|
- app/controllers/tramway/export/application_controller.rb
|
@@ -207,6 +208,7 @@ files:
|
|
207
208
|
- app/views/tramway/admin/records/index.html.haml
|
208
209
|
- app/views/tramway/admin/records/new.html.haml
|
209
210
|
- app/views/tramway/admin/records/show.html.haml
|
211
|
+
- app/views/tramway/admin/sessions/new.html.haml
|
210
212
|
- app/views/tramway/admin/shared/_show.html.haml
|
211
213
|
- app/views/tramway/admin/shared/errors/server_error.html.haml
|
212
214
|
- app/views/tramway/admin/shared/show/_attribute_tr.html.haml
|