kadmin 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f717d9066d91ad2a0a1acfd5303d408ff7c5942f0b822828f5fadea2c57d326
4
- data.tar.gz: 66bad7f74122ff12a435d03ffef350acbf0f1eead76b593b42d80229e8d4b424
3
+ metadata.gz: 0a67342d7ed2220a376c8b010e75b090b078f8b94f053d07a8de7f49f7457c8d
4
+ data.tar.gz: af6c66e446b5e87cf4a7cd50ef6d94c1d42a2360f8eef72c66728b293bf2a379
5
5
  SHA512:
6
- metadata.gz: c27975cf9d04ea202c1c0e4a6f72b2f3726a598ffe85d87fa3df8121fa22035385b04ef4016ad9b961a9ece840254074e48bd70659a419650967c7af9b4bf2b6
7
- data.tar.gz: 82394a5cbe9b005bbdec7a9975a4d18291ee68ec864b5402005705d008ed33b52649535970db465660e7dd7ad3fd08431e8ddff9495638e5e3b9bff2ebd9fb79
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
- 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
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
- if authorized_user.admin?
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
- <li style="padding-right: 10px;"><%= authorized_user.organization %></li>
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
@@ -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 true
22
+ return @admin
18
23
  end
19
24
  end
20
25
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Kadmin
2
- VERSION = '1.0.5'.freeze
2
+ VERSION = '1.0.6'.freeze
3
3
  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: 1.0.5
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-11-14 00:00:00.000000000 Z
13
+ date: 2018-12-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails