kadmin 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -44
- data/Rakefile +146 -146
- data/app/assets/javascripts/modular/app.js +1388 -1388
- data/app/assets/javascripts/modular/application.js +3 -3
- data/app/assets/javascripts/modular/vendor.js +57671 -57671
- data/app/assets/stylesheets/kadmin/typeahead-select.scss +2 -0
- data/app/assets/stylesheets/modular/app-blue.css +2795 -2795
- data/app/assets/stylesheets/modular/app-custom.css +2795 -2795
- data/app/assets/stylesheets/modular/app-green.css +2795 -2795
- data/app/assets/stylesheets/modular/app-orange.css +2795 -2795
- data/app/assets/stylesheets/modular/app-purple.css +2795 -2795
- data/app/assets/stylesheets/modular/app-red.css +2795 -2795
- data/app/assets/stylesheets/modular/app-seagreen.css +2795 -2795
- data/app/assets/stylesheets/modular/app.css +2795 -2795
- data/app/assets/stylesheets/modular/custom.css +51 -19
- data/app/assets/stylesheets/modular/vendor.css +12999 -12999
- data/app/controllers/kadmin/application_controller.rb +64 -64
- data/app/controllers/kadmin/auth_controller.rb +98 -98
- data/app/controllers/kadmin/concerns/authorized_user.rb +67 -67
- data/app/controllers/kadmin/dash_controller.rb +19 -19
- data/app/decorators/kadmin/finder_decorator.rb +50 -50
- data/app/decorators/kadmin/pager_decorator.rb +33 -33
- data/app/helpers/kadmin/alert_helper.rb +59 -59
- data/app/helpers/kadmin/application_helper.rb +4 -4
- data/app/helpers/kadmin/bootstrap_helper.rb +23 -23
- data/app/helpers/kadmin/form_builder.rb +9 -9
- data/app/helpers/kadmin/forms/inverted_check_box.rb +10 -10
- data/app/helpers/kadmin/navigation_helper.rb +28 -28
- data/app/helpers/kadmin/pagination_helper.rb +95 -95
- data/app/views/kadmin/auth/login.html.erb +4 -4
- data/app/views/kadmin/components/_finder.html.erb +14 -18
- data/app/views/kadmin/components/finder/_empty.html.erb +3 -3
- data/app/views/kadmin/components/finder/_form.erb +10 -10
- data/app/views/kadmin/components/finder/_header.html.erb +14 -11
- data/app/views/kadmin/dash/index.html.erb +5 -5
- data/app/views/kadmin/error.html.erb +5 -5
- data/app/views/kadmin/helpers/_alerts.html.erb +4 -4
- data/app/views/kadmin/helpers/_form_errors.html.erb +10 -10
- data/app/views/layouts/modular/application.html.erb +134 -132
- data/config/initializers/action_view.rb +2 -2
- data/config/initializers/assets.rb +5 -5
- data/config/locales/de.yml +25 -25
- data/config/locales/en.yml +24 -24
- data/config/routes.rb +12 -12
- data/lib/kadmin.rb +22 -22
- data/lib/kadmin/auth.rb +31 -31
- data/lib/kadmin/auth/configuration.rb +66 -66
- data/lib/kadmin/auth/unauthorized_error.rb +14 -14
- data/lib/kadmin/auth/user.rb +15 -15
- data/lib/kadmin/auth/user_store.rb +21 -21
- data/lib/kadmin/configuration.rb +18 -18
- data/lib/kadmin/engine.rb +15 -15
- data/lib/kadmin/error.rb +7 -7
- data/lib/kadmin/errors/authorization.rb +15 -15
- data/lib/kadmin/finder.rb +66 -66
- data/lib/kadmin/form.rb +179 -179
- data/lib/kadmin/pager.rb +93 -93
- data/lib/kadmin/version.rb +3 -3
- data/test/dummy/README.rdoc +28 -28
- data/test/dummy/Rakefile +6 -6
- data/test/dummy/app/assets/javascripts/application.js +13 -13
- data/test/dummy/app/assets/stylesheets/application.css +15 -15
- data/test/dummy/app/controllers/admin/application_controller.rb +11 -11
- data/test/dummy/app/controllers/admin/people_controller.rb +89 -89
- data/test/dummy/app/controllers/admin_controller.rb +4 -4
- data/test/dummy/app/controllers/application_controller.rb +5 -5
- data/test/dummy/app/controllers/authorized_controller.rb +8 -8
- data/test/dummy/app/helpers/application_helper.rb +2 -2
- data/test/dummy/app/models/group.rb +8 -8
- data/test/dummy/app/models/group_person.rb +6 -6
- data/test/dummy/app/models/person.rb +20 -20
- data/test/dummy/app/views/admin/index.html.erb +1 -1
- data/test/dummy/app/views/admin/people/_form.html.erb +34 -34
- data/test/dummy/app/views/admin/people/_table.html.erb +33 -33
- data/test/dummy/app/views/admin/people/edit.html.erb +4 -4
- data/test/dummy/app/views/admin/people/index.html.erb +3 -3
- data/test/dummy/app/views/admin/people/new.html.erb +5 -5
- data/test/dummy/app/views/admin/people/show.html.erb +3 -3
- data/test/dummy/app/views/authorized/index.html.erb +1 -1
- data/test/dummy/app/views/layouts/application.html.erb +14 -14
- data/test/dummy/bin/bundle +3 -3
- data/test/dummy/bin/rails +4 -4
- data/test/dummy/bin/rake +4 -4
- data/test/dummy/bin/setup +29 -29
- data/test/dummy/config.ru +4 -4
- data/test/dummy/config/application.rb +39 -39
- data/test/dummy/config/boot.rb +5 -5
- data/test/dummy/config/database.yml +22 -22
- data/test/dummy/config/environment.rb +5 -5
- data/test/dummy/config/environments/development.rb +41 -41
- data/test/dummy/config/environments/production.rb +79 -79
- data/test/dummy/config/environments/test.rb +42 -42
- data/test/dummy/config/initializers/assets.rb +10 -10
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -7
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -3
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -4
- data/test/dummy/config/initializers/inflections.rb +16 -16
- data/test/dummy/config/initializers/kadmin.rb +24 -24
- data/test/dummy/config/initializers/mime_types.rb +4 -4
- data/test/dummy/config/initializers/session_store.rb +3 -3
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -14
- data/test/dummy/config/locales/en.yml +17 -17
- data/test/dummy/config/routes.rb +13 -13
- data/test/dummy/config/secrets.yml +22 -22
- data/test/dummy/db/migrate/20161006114509_create_people.rb +11 -11
- data/test/dummy/db/migrate/20161006134459_create_groups.rb +11 -11
- data/test/dummy/db/migrate/20161006134746_create_group_people.rb +11 -11
- data/test/dummy/db/schema.rb +43 -43
- data/test/dummy/lib/forms/group_form.rb +16 -16
- data/test/dummy/lib/forms/person_form.rb +19 -19
- data/test/dummy/public/404.html +67 -67
- data/test/dummy/public/422.html +67 -67
- data/test/dummy/public/500.html +66 -66
- data/test/dummy/test/fixtures/children.yml +11 -11
- data/test/dummy/test/fixtures/group_people.yml +11 -11
- data/test/dummy/test/fixtures/groups.yml +11 -11
- data/test/dummy/test/fixtures/people.yml +11 -11
- data/test/dummy/test/models/group_person_test.rb +7 -7
- data/test/dummy/test/models/group_test.rb +7 -7
- data/test/kadmin/form_test.rb +6 -6
- data/test/test_helper.rb +32 -32
- metadata +54 -53
@@ -1,2 +1,2 @@
|
|
1
|
-
# Allow use of custom field tags for form builder
|
2
|
-
ActionView::Base.default_form_builder = Kadmin::FormBuilder
|
1
|
+
# Allow use of custom field tags for form builder
|
2
|
+
ActionView::Base.default_form_builder = Kadmin::FormBuilder
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# Load engine assets
|
2
|
-
# While loading images by extensions seem to work, loading JS and (S)CSS by extension seems
|
3
|
-
# to cause issues, although loading them by filename is fine. Go figure.
|
4
|
-
Rails.application.config.assets.precompile += %w(select2.css select2-bootstrap.css select2.js)
|
5
|
-
Rails.application.config.assets.precompile += Dir.glob("#{Kadmin::Engine.root}/app/assets/**/*").reject { |fn| File.directory?(fn) }
|
1
|
+
# Load engine assets
|
2
|
+
# While loading images by extensions seem to work, loading JS and (S)CSS by extension seems
|
3
|
+
# to cause issues, although loading them by filename is fine. Go figure.
|
4
|
+
Rails.application.config.assets.precompile += %w(select2.css select2-bootstrap.css select2.js)
|
5
|
+
Rails.application.config.assets.precompile += Dir.glob("#{Kadmin::Engine.root}/app/assets/**/*").reject { |fn| File.directory?(fn) }
|
data/config/locales/de.yml
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
de:
|
2
|
-
kadmin:
|
3
|
-
auth:
|
4
|
-
error: Ein Fehler ist aufgetreten; bitte versuche es noch einmal
|
5
|
-
login_required: Eine gültige E-Mail Adresse von Google (@offerista.com) ist erforderlich
|
6
|
-
please_login: Bitte melde Dich an
|
7
|
-
unauthorized: Unberechtigter Zugriff
|
8
|
-
unauthorized_message: Du hast für die gewünschte Seite leider keine Zugriffsrechte; falls Du dies anders siehst, wende Dich bitte an das Apps & Services Team
|
9
|
-
components:
|
10
|
-
finder:
|
11
|
-
clear: Löschen
|
12
|
-
create: Anlegen
|
13
|
-
empty: Nichts zu zeigen
|
14
|
-
filter: Suchen
|
15
|
-
out_of: von %{total}
|
16
|
-
dash_message: Schaue Dir die Bereiche in der Navigationsleiste oben an. Sollte es irgenwelche Probleme geben, oder es Dir im Leben an Zugriffsrechten fehlen, wende Dich bitte an das Apps & Services Team
|
17
|
-
error: Fehler
|
18
|
-
errors:
|
19
|
-
not_found: Objekt nicht gefunden
|
20
|
-
params_missing: Fehlender erforderlicher Parameter
|
21
|
-
unexpected: Unerwartete Fehler
|
22
|
-
unexpected_message: Bei dem Betrieb ist ein unerwarteter Fehler aufgetreten. Bitte entweder nochmal versuchen, oder die Apps & Services Team kontaktieren.
|
23
|
-
forms:
|
24
|
-
please_correct: "Bitte die folgende Felde korrigieren:"
|
25
|
-
welcome: Willkommen zurück, %{user}!
|
1
|
+
de:
|
2
|
+
kadmin:
|
3
|
+
auth:
|
4
|
+
error: Ein Fehler ist aufgetreten; bitte versuche es noch einmal
|
5
|
+
login_required: Eine gültige E-Mail Adresse von Google (@offerista.com) ist erforderlich
|
6
|
+
please_login: Bitte melde Dich an
|
7
|
+
unauthorized: Unberechtigter Zugriff
|
8
|
+
unauthorized_message: Du hast für die gewünschte Seite leider keine Zugriffsrechte; falls Du dies anders siehst, wende Dich bitte an das Apps & Services Team
|
9
|
+
components:
|
10
|
+
finder:
|
11
|
+
clear: Löschen
|
12
|
+
create: Anlegen
|
13
|
+
empty: Nichts zu zeigen
|
14
|
+
filter: Suchen
|
15
|
+
out_of: von %{total}
|
16
|
+
dash_message: Schaue Dir die Bereiche in der Navigationsleiste oben an. Sollte es irgenwelche Probleme geben, oder es Dir im Leben an Zugriffsrechten fehlen, wende Dich bitte an das Apps & Services Team
|
17
|
+
error: Fehler
|
18
|
+
errors:
|
19
|
+
not_found: Objekt nicht gefunden
|
20
|
+
params_missing: Fehlender erforderlicher Parameter
|
21
|
+
unexpected: Unerwartete Fehler
|
22
|
+
unexpected_message: Bei dem Betrieb ist ein unerwarteter Fehler aufgetreten. Bitte entweder nochmal versuchen, oder die Apps & Services Team kontaktieren.
|
23
|
+
forms:
|
24
|
+
please_correct: "Bitte die folgende Felde korrigieren:"
|
25
|
+
welcome: Willkommen zurück, %{user}!
|
data/config/locales/en.yml
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
en:
|
2
|
-
kadmin:
|
3
|
-
auth:
|
4
|
-
error: An error occurred; please try again
|
5
|
-
login_required: A valid Google enabled email is necessary to login
|
6
|
-
please_login: Please authenticate yourself
|
7
|
-
unauthorized: Unauthorized access
|
8
|
-
unauthorized_message: You are not authorized to access this resource; if you think you should be, contact the Apps & Services team
|
9
|
-
components:
|
10
|
-
finder:
|
11
|
-
clear: Clear
|
12
|
-
create: Create
|
13
|
-
empty: Nothing to show
|
14
|
-
filter: Filter
|
15
|
-
out_of: out of %{total}
|
16
|
-
dash_message: See the top navigation bar for the different admin sections. If you are missing authorizations, or if there is any issue at all, contact the Apps & Services team!
|
17
|
-
error: Error
|
18
|
-
errors:
|
19
|
-
not_found: Requested object not found
|
20
|
-
params_missing: Missing required parameters
|
21
|
-
unexpected: Unexpected error
|
22
|
-
unexpected_message: An unexpected error occurred; you can try again, or contact a member of the Apps & Services team.
|
23
|
-
forms:
|
24
|
-
please_correct: "Please correct the following:"
|
1
|
+
en:
|
2
|
+
kadmin:
|
3
|
+
auth:
|
4
|
+
error: An error occurred; please try again
|
5
|
+
login_required: A valid Google enabled email is necessary to login
|
6
|
+
please_login: Please authenticate yourself
|
7
|
+
unauthorized: Unauthorized access
|
8
|
+
unauthorized_message: You are not authorized to access this resource; if you think you should be, contact the Apps & Services team
|
9
|
+
components:
|
10
|
+
finder:
|
11
|
+
clear: Clear
|
12
|
+
create: Create
|
13
|
+
empty: Nothing to show
|
14
|
+
filter: Filter
|
15
|
+
out_of: out of %{total}
|
16
|
+
dash_message: See the top navigation bar for the different admin sections. If you are missing authorizations, or if there is any issue at all, contact the Apps & Services team!
|
17
|
+
error: Error
|
18
|
+
errors:
|
19
|
+
not_found: Requested object not found
|
20
|
+
params_missing: Missing required parameters
|
21
|
+
unexpected: Unexpected error
|
22
|
+
unexpected_message: An unexpected error occurred; you can try again, or contact a member of the Apps & Services team.
|
23
|
+
forms:
|
24
|
+
please_correct: "Please correct the following:"
|
25
25
|
welcome: Moin, moin %{user}!
|
data/config/routes.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
Kadmin::Engine.routes.draw do
|
2
|
-
get '/', controller: :dash, action: :index
|
3
|
-
|
4
|
-
scope '/auth', controller: :auth, as: 'auth', defaults: { format: 'html' } do
|
5
|
-
get '/login', action: :login, as: :login
|
6
|
-
get '/logout', action: :logout, as: :logout
|
7
|
-
get '/:provider/callback', action: :save
|
8
|
-
post '/:provider/callback', action: :save
|
9
|
-
get '/failure', action: :failure, as: :failure
|
10
|
-
get '/unauthorized', action: :unauthorized, as: :unauthorized
|
11
|
-
end
|
12
|
-
end
|
1
|
+
Kadmin::Engine.routes.draw do
|
2
|
+
get '/', controller: :dash, action: :index
|
3
|
+
|
4
|
+
scope '/auth', controller: :auth, as: 'auth', defaults: { format: 'html' } do
|
5
|
+
get '/login', action: :login, as: :login
|
6
|
+
get '/logout', action: :logout, as: :logout
|
7
|
+
get '/:provider/callback', action: :save
|
8
|
+
post '/:provider/callback', action: :save
|
9
|
+
get '/failure', action: :failure, as: :failure
|
10
|
+
get '/unauthorized', action: :unauthorized, as: :unauthorized
|
11
|
+
end
|
12
|
+
end
|
data/lib/kadmin.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require 'kadmin/configuration'
|
2
|
-
require 'kadmin/error'
|
3
|
-
require 'kadmin/engine'
|
4
|
-
require 'kadmin/auth'
|
5
|
-
require 'kadmin/form'
|
6
|
-
require 'kadmin/finder'
|
7
|
-
require 'kadmin/pager'
|
8
|
-
|
9
|
-
module Kadmin
|
10
|
-
class << self
|
11
|
-
delegate :logger, :logger=, to: :config
|
12
|
-
|
13
|
-
def config
|
14
|
-
return @config ||= Kadmin::Configuration.new
|
15
|
-
end
|
16
|
-
|
17
|
-
def configure
|
18
|
-
yield(config) if block_given?
|
19
|
-
return config
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
1
|
+
require 'kadmin/configuration'
|
2
|
+
require 'kadmin/error'
|
3
|
+
require 'kadmin/engine'
|
4
|
+
require 'kadmin/auth'
|
5
|
+
require 'kadmin/form'
|
6
|
+
require 'kadmin/finder'
|
7
|
+
require 'kadmin/pager'
|
8
|
+
|
9
|
+
module Kadmin
|
10
|
+
class << self
|
11
|
+
delegate :logger, :logger=, to: :config
|
12
|
+
|
13
|
+
def config
|
14
|
+
return @config ||= Kadmin::Configuration.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def configure
|
18
|
+
yield(config) if block_given?
|
19
|
+
return config
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/kadmin/auth.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
# Third party dependency
|
2
|
-
require 'omniauth-google-oauth2'
|
3
|
-
|
4
|
-
# Core files
|
5
|
-
require 'kadmin/auth/unauthorized_error'
|
6
|
-
require 'kadmin/auth/configuration'
|
7
|
-
require 'kadmin/auth/user'
|
8
|
-
require 'kadmin/auth/user_store'
|
9
|
-
|
10
|
-
module Kadmin
|
11
|
-
module Auth
|
12
|
-
class << self
|
13
|
-
def users
|
14
|
-
@users ||= config.user_store_class.new
|
15
|
-
end
|
16
|
-
|
17
|
-
def config
|
18
|
-
return @config ||= Kadmin::Auth::Configuration.new
|
19
|
-
end
|
20
|
-
|
21
|
-
def configure
|
22
|
-
yield(config) if block_given?
|
23
|
-
return config
|
24
|
-
end
|
25
|
-
|
26
|
-
def omniauth_provider
|
27
|
-
return config.oauth_credentials.present? ? :google_oauth2 : :developer
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
1
|
+
# Third party dependency
|
2
|
+
require 'omniauth-google-oauth2'
|
3
|
+
|
4
|
+
# Core files
|
5
|
+
require 'kadmin/auth/unauthorized_error'
|
6
|
+
require 'kadmin/auth/configuration'
|
7
|
+
require 'kadmin/auth/user'
|
8
|
+
require 'kadmin/auth/user_store'
|
9
|
+
|
10
|
+
module Kadmin
|
11
|
+
module Auth
|
12
|
+
class << self
|
13
|
+
def users
|
14
|
+
@users ||= config.user_store_class.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def config
|
18
|
+
return @config ||= Kadmin::Auth::Configuration.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def configure
|
22
|
+
yield(config) if block_given?
|
23
|
+
return config
|
24
|
+
end
|
25
|
+
|
26
|
+
def omniauth_provider
|
27
|
+
return config.oauth_credentials.present? ? :google_oauth2 : :developer
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,66 +1,66 @@
|
|
1
|
-
module Kadmin
|
2
|
-
module Auth
|
3
|
-
class Configuration
|
4
|
-
OAuthCredentials = Struct.new(:id, :secret)
|
5
|
-
|
6
|
-
# @return [Kadmin::Auth::Configuration::OAuthCredentials] credentials for OAuth2 authentication; if absent, fallback to :developer provider
|
7
|
-
attr_accessor :oauth_credentials
|
8
|
-
|
9
|
-
# @return [Class<Kadmin::Auth::User>] class to use for authenticated users (mostly for resource authorization)
|
10
|
-
attr_accessor :user_class
|
11
|
-
|
12
|
-
# @return [Class<Kadmin::Auth::UserStore>] class for user lookup/registration
|
13
|
-
attr_accessor :user_store_class
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
@oauth_credentials = nil
|
17
|
-
@user_class = Kadmin::Auth::User
|
18
|
-
@user_store_class = Kadmin::Auth::UserStore
|
19
|
-
@enabled = false
|
20
|
-
end
|
21
|
-
|
22
|
-
# @return [Boolean] true if enabled, false otherwise
|
23
|
-
def enabled?
|
24
|
-
return @enabled
|
25
|
-
end
|
26
|
-
|
27
|
-
# Enables authentication and adds OmniAuth middlewares
|
28
|
-
def enable!
|
29
|
-
unless @enabled
|
30
|
-
append_omniauth_middleware
|
31
|
-
@enabled = true
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Disables authentication and removes OmniAuth middlewares
|
36
|
-
def disable!
|
37
|
-
if @enabled
|
38
|
-
delete_omniauth_middleware
|
39
|
-
@enabled = false
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def append_omniauth_middleware
|
44
|
-
OmniAuth.config.logger = Kadmin.logger
|
45
|
-
OmniAuth.config.path_prefix = File.join(Kadmin.config.mount_path, OmniAuth.config.path_prefix)
|
46
|
-
|
47
|
-
provider_args = case Kadmin::Auth.omniauth_provider
|
48
|
-
when :google_oauth2
|
49
|
-
[:google_oauth2, @oauth_credentials.id, @oauth_credentials.secret]
|
50
|
-
else
|
51
|
-
[:developer, fields: [:email]]
|
52
|
-
end
|
53
|
-
|
54
|
-
Rails.application.config.middleware.use OmniAuth::Builder do
|
55
|
-
provider(*provider_args)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
private :append_omniauth_middleware
|
59
|
-
|
60
|
-
def delete_omniauth_middleware
|
61
|
-
Rails.application.config.middleware.delete OmniAuth::Builder
|
62
|
-
end
|
63
|
-
private :delete_omniauth_middleware
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
1
|
+
module Kadmin
|
2
|
+
module Auth
|
3
|
+
class Configuration
|
4
|
+
OAuthCredentials = Struct.new(:id, :secret)
|
5
|
+
|
6
|
+
# @return [Kadmin::Auth::Configuration::OAuthCredentials] credentials for OAuth2 authentication; if absent, fallback to :developer provider
|
7
|
+
attr_accessor :oauth_credentials
|
8
|
+
|
9
|
+
# @return [Class<Kadmin::Auth::User>] class to use for authenticated users (mostly for resource authorization)
|
10
|
+
attr_accessor :user_class
|
11
|
+
|
12
|
+
# @return [Class<Kadmin::Auth::UserStore>] class for user lookup/registration
|
13
|
+
attr_accessor :user_store_class
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@oauth_credentials = nil
|
17
|
+
@user_class = Kadmin::Auth::User
|
18
|
+
@user_store_class = Kadmin::Auth::UserStore
|
19
|
+
@enabled = false
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Boolean] true if enabled, false otherwise
|
23
|
+
def enabled?
|
24
|
+
return @enabled
|
25
|
+
end
|
26
|
+
|
27
|
+
# Enables authentication and adds OmniAuth middlewares
|
28
|
+
def enable!
|
29
|
+
unless @enabled
|
30
|
+
append_omniauth_middleware
|
31
|
+
@enabled = true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Disables authentication and removes OmniAuth middlewares
|
36
|
+
def disable!
|
37
|
+
if @enabled
|
38
|
+
delete_omniauth_middleware
|
39
|
+
@enabled = false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def append_omniauth_middleware
|
44
|
+
OmniAuth.config.logger = Kadmin.logger
|
45
|
+
OmniAuth.config.path_prefix = File.join(Kadmin.config.mount_path, OmniAuth.config.path_prefix)
|
46
|
+
|
47
|
+
provider_args = case Kadmin::Auth.omniauth_provider
|
48
|
+
when :google_oauth2
|
49
|
+
[:google_oauth2, @oauth_credentials.id, @oauth_credentials.secret]
|
50
|
+
else
|
51
|
+
[:developer, fields: [:email]]
|
52
|
+
end
|
53
|
+
|
54
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
55
|
+
provider(*provider_args)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
private :append_omniauth_middleware
|
59
|
+
|
60
|
+
def delete_omniauth_middleware
|
61
|
+
Rails.application.config.middleware.delete OmniAuth::Builder
|
62
|
+
end
|
63
|
+
private :delete_omniauth_middleware
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
module Kadmin
|
2
|
-
module Auth
|
3
|
-
class UnauthorizedError < Kadmin::Error
|
4
|
-
# Attempts to translate message, if not found returns message as a string
|
5
|
-
def message
|
6
|
-
I18n.t(@message, default: @message)
|
7
|
-
end
|
8
|
-
|
9
|
-
def title
|
10
|
-
I18n.t('kadmin.auth.unauthorized')
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
1
|
+
module Kadmin
|
2
|
+
module Auth
|
3
|
+
class UnauthorizedError < Kadmin::Error
|
4
|
+
# Attempts to translate message, if not found returns message as a string
|
5
|
+
def message
|
6
|
+
I18n.t(@message, default: @message)
|
7
|
+
end
|
8
|
+
|
9
|
+
def title
|
10
|
+
I18n.t('kadmin.auth.unauthorized')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/kadmin/auth/user.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
module Kadmin
|
2
|
-
module Auth
|
3
|
-
class User
|
4
|
-
attr_accessor :email
|
5
|
-
|
6
|
-
def initialize(email)
|
7
|
-
@email = email
|
8
|
-
end
|
9
|
-
|
10
|
-
def authorized?(_request)
|
11
|
-
return true
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
1
|
+
module Kadmin
|
2
|
+
module Auth
|
3
|
+
class User
|
4
|
+
attr_accessor :email
|
5
|
+
|
6
|
+
def initialize(email)
|
7
|
+
@email = email
|
8
|
+
end
|
9
|
+
|
10
|
+
def authorized?(_request)
|
11
|
+
return true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
module Kadmin
|
2
|
-
module Auth
|
3
|
-
class UserStore
|
4
|
-
def initialize
|
5
|
-
@store = {}
|
6
|
-
end
|
7
|
-
|
8
|
-
def get(email)
|
9
|
-
return @store[email.downcase]
|
10
|
-
end
|
11
|
-
|
12
|
-
def set(email, user)
|
13
|
-
@store[email.downcase] = user
|
14
|
-
end
|
15
|
-
|
16
|
-
def exists?(email)
|
17
|
-
@store.key?(email.downcase)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
1
|
+
module Kadmin
|
2
|
+
module Auth
|
3
|
+
class UserStore
|
4
|
+
def initialize
|
5
|
+
@store = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def get(email)
|
9
|
+
return @store[email.downcase]
|
10
|
+
end
|
11
|
+
|
12
|
+
def set(email, user)
|
13
|
+
@store[email.downcase] = user
|
14
|
+
end
|
15
|
+
|
16
|
+
def exists?(email)
|
17
|
+
@store.key?(email.downcase)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|