usps-support 0.2.24 → 0.2.25
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/concerns/usps/support/admin_menu.rb +24 -0
- data/app/controllers/usps/support/admins_controller.rb +67 -0
- data/app/models/usps/support/policy/admin_context.rb +26 -0
- data/config/routes.rb +10 -0
- data/lib/usps/support/engine.rb +15 -0
- data/lib/usps/support/version.rb +1 -1
- data/lib/usps/support.rb +4 -1
- metadata +8 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9f99b23db7bb362080785a59d911fd245db2c275e711d1c57c7c1e23adad47a6
|
|
4
|
+
data.tar.gz: 7b679be331e8013b9e6c590da7efce055e0166ee3a27aec92273f50f9ef19146
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 62be219931f610630e316702c62a16600db301f8631ccc0035b68e3a9ffddf196931dd94ce17e3f766f09a71f24de8f1b94bdaa15d0748b015687f3a5349bf86
|
|
7
|
+
data.tar.gz: 64e822a0d5625c4aeecb13afb4a2612f99532c2f401d3018ba95d3a955c6ccd3bc26ac386a6e7be27e9f09424fbec33c1d91fc0fcb089bf85c2f23416bf007ad
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Usps::Support
|
|
2
|
+
# Exposes `impersonation` and `admin_menu_expanded` helpers to host views,
|
|
3
|
+
# backed by the session state that AdminsController manages.
|
|
4
|
+
#
|
|
5
|
+
module AdminMenu
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
|
|
8
|
+
included do
|
|
9
|
+
helper_method :impersonation
|
|
10
|
+
helper_method :admin_menu_expanded
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def impersonation
|
|
14
|
+
return @impersonation if defined?(@impersonation)
|
|
15
|
+
|
|
16
|
+
impersonated = Members::Member.find_by(certificate: session.dig('impersonate', 'impersonated'))
|
|
17
|
+
@impersonation = impersonated && { name: impersonated.simple_name, certificate: impersonated.certificate }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def admin_menu_expanded
|
|
21
|
+
session['admin_menu_expand']
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module Usps::Support
|
|
2
|
+
# Shared impersonation and admin-menu-toggle endpoints. See config/routes.rb
|
|
3
|
+
# for the mount point; host apps authenticate via their ApplicationController.
|
|
4
|
+
#
|
|
5
|
+
class AdminsController < ::ApplicationController
|
|
6
|
+
before_action :authorize_admin
|
|
7
|
+
|
|
8
|
+
def impersonate
|
|
9
|
+
@certificate = params[:certificate]
|
|
10
|
+
impersonate!
|
|
11
|
+
render_admin_response(:OK, reload: impersonated.present?)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def cancel
|
|
15
|
+
session.delete('impersonate')
|
|
16
|
+
render_admin_response(:OK, reload: true)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def collapse
|
|
20
|
+
session['admin_menu_expand'] = false
|
|
21
|
+
render_admin_response(:OK)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def expand
|
|
25
|
+
session['admin_menu_expand'] = true
|
|
26
|
+
render_admin_response(:OK)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def authorize_admin
|
|
32
|
+
authorize(:admin)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def impersonate!
|
|
36
|
+
return unless impersonated
|
|
37
|
+
|
|
38
|
+
session['impersonate'] = {
|
|
39
|
+
'admin' => current_user.certificate,
|
|
40
|
+
'impersonated' => impersonated.certificate
|
|
41
|
+
}
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def impersonated
|
|
45
|
+
return @impersonated if defined?(@impersonated)
|
|
46
|
+
return if @certificate.blank?
|
|
47
|
+
|
|
48
|
+
@impersonated = Members::Member.find_by(certificate: @certificate)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def pundit_user
|
|
52
|
+
Usps::Support::Policy::AdminContext.new(current_user, session['impersonate'])
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Apps that expose `react_response!` (toast handling, etc.) will reuse it.
|
|
56
|
+
# Otherwise we render the minimal JSON shape the React admin menu expects.
|
|
57
|
+
#
|
|
58
|
+
# options is spread into the fallback render hash, so it must stay named.
|
|
59
|
+
# rubocop:disable Style/ArgumentsForwarding
|
|
60
|
+
def render_admin_response(status, **options)
|
|
61
|
+
return react_response!(status, **options) if respond_to?(:react_response!, true)
|
|
62
|
+
|
|
63
|
+
render(json: { status: status.to_s.upcase, toasts: [], reload: false, **options })
|
|
64
|
+
end
|
|
65
|
+
# rubocop:enable Style/ArgumentsForwarding
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Usps::Support
|
|
2
|
+
module Policy
|
|
3
|
+
# Pundit user context that carries both the current user and any active
|
|
4
|
+
# impersonation session, so policies can distinguish the acting admin from
|
|
5
|
+
# the impersonated member.
|
|
6
|
+
#
|
|
7
|
+
class AdminContext
|
|
8
|
+
attr_reader :user, :impersonate
|
|
9
|
+
|
|
10
|
+
def initialize(user, impersonate)
|
|
11
|
+
@user = user
|
|
12
|
+
@impersonate = impersonate
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def admin?
|
|
16
|
+
(impersonate&.fetch('impersonated', nil).present? ? original : user).admin?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def original
|
|
22
|
+
Members::Member.find(impersonate['admin'])
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/engine'
|
|
4
|
+
|
|
5
|
+
module Usps
|
|
6
|
+
module Support
|
|
7
|
+
# Rails engine hosting shared controllers, concerns, policies, and routes.
|
|
8
|
+
#
|
|
9
|
+
# Not isolated: host applications share the engine's ApplicationController,
|
|
10
|
+
# helpers, and authentication plumbing.
|
|
11
|
+
#
|
|
12
|
+
class Engine < ::Rails::Engine
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/usps/support/version.rb
CHANGED
data/lib/usps/support.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: usps-support
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.25
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Julian Fiander
|
|
@@ -59,10 +59,15 @@ extensions: []
|
|
|
59
59
|
extra_rdoc_files: []
|
|
60
60
|
files:
|
|
61
61
|
- Readme.md
|
|
62
|
+
- app/controllers/concerns/usps/support/admin_menu.rb
|
|
63
|
+
- app/controllers/usps/support/admins_controller.rb
|
|
64
|
+
- app/models/usps/support/policy/admin_context.rb
|
|
65
|
+
- config/routes.rb
|
|
62
66
|
- lib/usps/all.rb
|
|
63
67
|
- lib/usps/support.rb
|
|
64
68
|
- lib/usps/support/db/members_schema.rb
|
|
65
69
|
- lib/usps/support/db/websites_schema.rb
|
|
70
|
+
- lib/usps/support/engine.rb
|
|
66
71
|
- lib/usps/support/helpers.rb
|
|
67
72
|
- lib/usps/support/helpers/badges_helper.rb
|
|
68
73
|
- lib/usps/support/helpers/flags_helper.rb
|
|
@@ -100,10 +105,10 @@ files:
|
|
|
100
105
|
- lib/usps/support/models/toast.rb
|
|
101
106
|
- lib/usps/support/railtie.rb
|
|
102
107
|
- lib/usps/support/version.rb
|
|
103
|
-
homepage: https://github.com/unitedstatespowersquadrons/usps-
|
|
108
|
+
homepage: https://github.com/unitedstatespowersquadrons/usps-support
|
|
104
109
|
licenses: []
|
|
105
110
|
metadata:
|
|
106
|
-
homepage_uri: https://github.com/unitedstatespowersquadrons/usps-
|
|
111
|
+
homepage_uri: https://github.com/unitedstatespowersquadrons/usps-support
|
|
107
112
|
rubygems_mfa_required: 'true'
|
|
108
113
|
rdoc_options: []
|
|
109
114
|
require_paths:
|