kadmin 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/kadmin/application_controller.rb +2 -18
- data/app/controllers/kadmin/auth_controller.rb +8 -0
- data/app/views/layouts/kadmin/application.html.erb +7 -1
- data/config/routes.rb +1 -0
- data/lib/kadmin/auth/user.rb +6 -1
- data/lib/kadmin/configuration.rb +1 -1
- data/lib/kadmin/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a67342d7ed2220a376c8b010e75b090b078f8b94f053d07a8de7f49f7457c8d
|
4
|
+
data.tar.gz: af6c66e446b5e87cf4a7cd50ef6d94c1d42a2360f8eef72c66728b293bf2a379
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7710e4b73016d2e9d826ec9b6246978e25dccaa19e38cbd22c50830f6824fb5c91b22dd5ef7d75227577b96522ea2d9e0bb9fb505c5ce553307eb1657d327d6
|
7
|
+
data.tar.gz: c3e79b1da1127d9cbd42fcd71e060e34b9c7603fc69c04e8a5e2238ba9bb43a30b6958e2019b3551338a31e19cfcd140f750acc3b2ade37d26ee3cbf6687761b
|
@@ -57,30 +57,14 @@ module Kadmin
|
|
57
57
|
#
|
58
58
|
# organization_scoped_ar is an ActiveRecord that has organization_scope(Organization) scope defined
|
59
59
|
def scoped_find_by!(organization_scoped_ar, id)
|
60
|
-
|
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
|
60
|
+
return organization_scoped_ar.organization_scope(@organization).find(id)
|
73
61
|
end
|
74
62
|
|
75
63
|
# returns all organization_scoped_ar object(s) that are of the user's organization. admin user gets all.
|
76
64
|
# you can chain scopes, e.g. scoped_all(Segments.my_scope) is valid
|
77
65
|
# organization_scoped_ar is an ActiveRecord that has organization_scope(Organization) scope defined
|
78
66
|
def scoped_all(organization_scoped_ar)
|
79
|
-
|
80
|
-
organization_scoped_ar.all
|
81
|
-
else
|
82
|
-
organization_scoped_ar.organization_scope(organization).all
|
83
|
-
end
|
67
|
+
organization_scoped_ar.organization_scope(organization).all
|
84
68
|
end
|
85
69
|
|
86
70
|
def organization
|
@@ -60,6 +60,14 @@ module Kadmin
|
|
60
60
|
}
|
61
61
|
end
|
62
62
|
|
63
|
+
# POST /change_organization
|
64
|
+
def change_organization
|
65
|
+
if authorized_user&.admin?
|
66
|
+
authorized_user.organization = Kadmin::Organization.find(params[:organization_id]).name
|
67
|
+
end
|
68
|
+
redirect_to :dash
|
69
|
+
end
|
70
|
+
|
63
71
|
# @!endgroup
|
64
72
|
|
65
73
|
# @!group Helpers
|
@@ -22,7 +22,13 @@
|
|
22
22
|
<div class="header-block header-block-nav">
|
23
23
|
<ul class="nav-profile">
|
24
24
|
<% if logged_in? %>
|
25
|
-
|
25
|
+
<% if authorized_user.admin? %>
|
26
|
+
<%= form_tag(Kadmin::Engine.routes.url_helpers.auth_change_organization_path) do -%>
|
27
|
+
<%= select_tag('organization_id', options_from_collection_for_select(Kadmin::Organization.all, :id, :name, @organization.id), onchange: "this.form.submit();", class: 'form-control')%>
|
28
|
+
<% end -%>
|
29
|
+
<% else %>
|
30
|
+
<li style="padding-right: 10px;"><%= authorized_user.organization %></li>
|
31
|
+
<% end %>
|
26
32
|
<li><%= link_to(t('kadmin.authorization.logout'), Kadmin::Engine.routes.url_helpers.auth_logout_path) %></li>
|
27
33
|
<% end %>
|
28
34
|
</ul>
|
data/config/routes.rb
CHANGED
@@ -8,5 +8,6 @@ Kadmin::Engine.routes.draw do
|
|
8
8
|
get '/failure', action: :failure, as: :failure
|
9
9
|
get '/unauthorized', action: :unauthorized, as: :unauthorized
|
10
10
|
get '/', action: :login
|
11
|
+
post '/change_organization', action: :change_organization, as: :change_organization
|
11
12
|
end
|
12
13
|
end
|
data/lib/kadmin/auth/user.rb
CHANGED
@@ -5,16 +5,21 @@ module Kadmin
|
|
5
5
|
|
6
6
|
def initialize(email, options = {})
|
7
7
|
@email = email
|
8
|
+
@admin = options[:admin]
|
8
9
|
@organization = options[:organization]
|
9
10
|
@accept = options[:accept]
|
10
11
|
end
|
11
12
|
|
13
|
+
def organization=(organization)
|
14
|
+
@organization = organization if self.admin?
|
15
|
+
end
|
16
|
+
|
12
17
|
def authorized?(_request)
|
13
18
|
return true
|
14
19
|
end
|
15
20
|
|
16
21
|
def admin?
|
17
|
-
return
|
22
|
+
return @admin
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
data/lib/kadmin/configuration.rb
CHANGED
@@ -31,7 +31,7 @@ module Kadmin
|
|
31
31
|
# filter available nav sections with the user's accept string
|
32
32
|
def navbar_items_for_user(user)
|
33
33
|
return [] if user.blank? # no user, no links
|
34
|
-
return @navbar_items if user.accept.blank? # no accept array -> everything is accepted
|
34
|
+
return @navbar_items if user.accept.blank? && user.admin? # no accept array and super admin -> everything is accepted
|
35
35
|
return @navbar_items.select do |navbar_item|
|
36
36
|
user.accept.any? { |accept_string| navbar_item.text =~ /#{accept_string.to_s.split('_').first}/i }
|
37
37
|
end
|
data/lib/kadmin/version.rb
CHANGED
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: 1.0.
|
4
|
+
version: 1.0.6
|
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-12-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|