kadmin 0.9.5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/kadmin/application_controller.rb +40 -0
- data/app/models/kadmin/organization.rb +4 -0
- data/config/locales/en.yml +1 -1
- data/db/migrate/20180912092525_create_organizations.rb +10 -0
- data/lib/kadmin/auth/user.rb +8 -2
- data/lib/kadmin/auth/user_store.rb +21 -0
- data/lib/kadmin/engine.rb +14 -0
- data/lib/kadmin/version.rb +1 -1
- data/test/factories/organizations.rb +13 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de1ca63ba054b938124830cf649096a45bbc9c424542fde3e51348ca88464c0e
|
4
|
+
data.tar.gz: 03b59bedf32d3146915436c061836c2b9532ac878f41837ca83e04b76129729e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 950a0431e91b2e86f8fc9fe0fbe5042cf8f3aa769c92a47799faeb9a0a63525af026c06b18888d98f1c41a8d4bc1b0dd3aaf58a195151796f18ec3bc1d7b57a6
|
7
|
+
data.tar.gz: 4fcce405b35d4d90ba39ced35aaf22599532c8b534668feeebae15c5d3ffdab102fb25a4a2995756b2d86bef488a6d16fe4c147444de5fc21c10020bc1c6f60f
|
@@ -12,6 +12,7 @@ module Kadmin
|
|
12
12
|
|
13
13
|
before_action :authorize
|
14
14
|
before_action :set_default_format
|
15
|
+
before_action :organization
|
15
16
|
|
16
17
|
# Each controller should specify which navbar section they
|
17
18
|
# belong to, if any. By default, each controller is setup to
|
@@ -51,6 +52,45 @@ module Kadmin
|
|
51
52
|
|
52
53
|
# @!endgroup
|
53
54
|
|
55
|
+
# returns organization_scoped_ar object(s) by id (or array of ids) or throw RecordNotFound in case
|
56
|
+
# id(s) does not exist or is not visible in scope
|
57
|
+
#
|
58
|
+
# organization_scoped_ar is an ActiveRecord that has organization_scope(Organization) scope defined
|
59
|
+
def scoped_find_by!(organization_scoped_ar, id)
|
60
|
+
if authorized_user.admin?
|
61
|
+
if id.is_a?(Array)
|
62
|
+
return organization_scoped_ar.find(id)
|
63
|
+
else
|
64
|
+
return organization_scoped_ar.find_by!(id: id)
|
65
|
+
end
|
66
|
+
else
|
67
|
+
if id.is_a?(Array)
|
68
|
+
return organization_scoped_ar.organization_scope(@organization).find(id)
|
69
|
+
else
|
70
|
+
return organization_scoped_ar.organization_scope(@organization).find_by!(id: id)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# returns all organization_scoped_ar object(s) that are of the user's organization. admin user gets all.
|
76
|
+
# you can chain scopes, e.g. scoped_all(Segments.my_scope) is valid
|
77
|
+
# organization_scoped_ar is an ActiveRecord that has organization_scope(Organization) scope defined
|
78
|
+
def scoped_all(organization_scoped_ar)
|
79
|
+
if authorized_user.admin?
|
80
|
+
organization_scoped_ar.all
|
81
|
+
else
|
82
|
+
organization_scoped_ar.organization_scope(organization).all
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def organization
|
87
|
+
if authorized_user.present?
|
88
|
+
@organization ||= Kadmin::Organization.find_by!(name: authorized_user.organization)
|
89
|
+
end
|
90
|
+
rescue ActiveRecord::RecordNotFound
|
91
|
+
render plain: "Forbidden - organization #{authorized_user.organization} not found in DB", status: :forbidden
|
92
|
+
end
|
93
|
+
|
54
94
|
# @!group Helpers
|
55
95
|
|
56
96
|
protected
|
data/config/locales/en.yml
CHANGED
@@ -14,7 +14,7 @@ en:
|
|
14
14
|
create: Create
|
15
15
|
filter: Filter
|
16
16
|
out_of: out of %{total}
|
17
|
-
dash_message: See the
|
17
|
+
dash_message: See the left navigation bar for the different admin sections. If you are missing authorizations, or if there is any issue at all, contact the Offerista Apps & Services team!
|
18
18
|
error: Error
|
19
19
|
errors:
|
20
20
|
not_found: Requested object not found
|
data/lib/kadmin/auth/user.rb
CHANGED
@@ -1,15 +1,21 @@
|
|
1
1
|
module Kadmin
|
2
2
|
module Auth
|
3
3
|
class User
|
4
|
-
attr_accessor :email
|
4
|
+
attr_accessor :email, :accept, :organization
|
5
5
|
|
6
|
-
def initialize(email)
|
6
|
+
def initialize(email, options = {})
|
7
7
|
@email = email
|
8
|
+
@organization = options[:organization]
|
8
9
|
end
|
9
10
|
|
10
11
|
def authorized?(_request)
|
11
12
|
return true
|
12
13
|
end
|
14
|
+
|
15
|
+
def admin?
|
16
|
+
return true
|
17
|
+
end
|
18
|
+
|
13
19
|
end
|
14
20
|
end
|
15
21
|
end
|
@@ -3,6 +3,7 @@ module Kadmin
|
|
3
3
|
class UserStore
|
4
4
|
def initialize
|
5
5
|
@store = {}
|
6
|
+
load_users!
|
6
7
|
end
|
7
8
|
|
8
9
|
def get(email)
|
@@ -16,6 +17,26 @@ module Kadmin
|
|
16
17
|
def exists?(email)
|
17
18
|
@store.key?(email.to_s.downcase)
|
18
19
|
end
|
20
|
+
|
21
|
+
def load_users!
|
22
|
+
file = Rails.root.join('config', 'admin_users.yml')
|
23
|
+
if File.exists?(file) && File.readable?(file)
|
24
|
+
definitions = YAML.load_file(file.to_s)
|
25
|
+
definitions.each do |definition|
|
26
|
+
email = definition['email']
|
27
|
+
options = {
|
28
|
+
admin: definition.fetch('admin', false),
|
29
|
+
accept: Array.wrap(definition.fetch('accept', [])).map(&:to_sym),
|
30
|
+
organization: definition.fetch('organization', 'offerista') # default organization, needs to exist in DB
|
31
|
+
}
|
32
|
+
|
33
|
+
set(email, Kadmin::Auth.config.user_class.new(email, **options))
|
34
|
+
end
|
35
|
+
else
|
36
|
+
Rails.logger.warn("Can't read admin users auth file at #{file}. Auth might not work")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
private :load_users!
|
19
40
|
end
|
20
41
|
end
|
21
42
|
end
|
data/lib/kadmin/engine.rb
CHANGED
@@ -5,8 +5,22 @@ module Kadmin
|
|
5
5
|
class Engine < ::Rails::Engine
|
6
6
|
isolate_namespace Kadmin
|
7
7
|
|
8
|
+
# push engine factory paths always at the top of the path stack
|
9
|
+
initializer 'kadmin.factories', after: 'factory_bot.set_factory_paths' do
|
10
|
+
factory_paths = File.expand_path('../../../test/factories', __FILE__) # path relative to installation location
|
11
|
+
FactoryBot.definition_file_paths.unshift(factory_paths) if defined?(FactoryBot)
|
12
|
+
end
|
13
|
+
|
8
14
|
initializer 'kadmin.install' do
|
9
15
|
Kadmin.logger = Rails.logger
|
10
16
|
end
|
17
|
+
|
18
|
+
initializer :append_migrations do |app|
|
19
|
+
unless app.root.to_s.match(root.to_s)
|
20
|
+
config.paths['db/migrate'].expanded.each do |expanded_path|
|
21
|
+
app.config.paths['db/migrate'] << expanded_path
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
11
25
|
end
|
12
26
|
end
|
data/lib/kadmin/version.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :kadmin_organization, class: Kadmin::Organization do
|
3
|
+
initialize_with do
|
4
|
+
Kadmin::Organization.where(name: 'offerista').first_or_initialize # take from seeded database
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
factory :kadmin_organization_not_offerista, class: Kadmin::Organization do
|
9
|
+
initialize_with do
|
10
|
+
Kadmin::Organization.where(name: 'profital').first_or_initialize # take from seeded database
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kadmin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Pepin-Perreault
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-
|
13
|
+
date: 2018-10-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- app/helpers/kadmin/application_helper.rb
|
128
128
|
- app/helpers/kadmin/bootstrap_helper.rb
|
129
129
|
- app/helpers/kadmin/charts_helper.rb
|
130
|
+
- app/models/kadmin/organization.rb
|
130
131
|
- app/views/kadmin/auth/login.html.erb
|
131
132
|
- app/views/kadmin/components/_finder.html.erb
|
132
133
|
- app/views/kadmin/components/_finder.js.erb
|
@@ -143,6 +144,7 @@ files:
|
|
143
144
|
- config/initializers/i18n.rb
|
144
145
|
- config/locales/en.yml
|
145
146
|
- config/routes.rb
|
147
|
+
- db/migrate/20180912092525_create_organizations.rb
|
146
148
|
- lib/kadmin.rb
|
147
149
|
- lib/kadmin/auth.rb
|
148
150
|
- lib/kadmin/auth/configuration.rb
|
@@ -157,6 +159,7 @@ files:
|
|
157
159
|
- lib/kadmin/presenter.rb
|
158
160
|
- lib/kadmin/presenter/test_case.rb
|
159
161
|
- lib/kadmin/version.rb
|
162
|
+
- test/factories/organizations.rb
|
160
163
|
- vendor/assets/fonts/fontawesome/fontawesome-webfont.eot
|
161
164
|
- vendor/assets/fonts/fontawesome/fontawesome-webfont.svg
|
162
165
|
- vendor/assets/fonts/fontawesome/fontawesome-webfont.ttf
|