usps-support 0.2.23 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '080904d8a62c91987b2636b03553504e62dcac2b36bce4f6bb2cf72acf23885b'
4
- data.tar.gz: 4ebfa6b6df1dbf65b2ed001049b992b0163ab87ce6d5737085ea60c45d092947
3
+ metadata.gz: 9f99b23db7bb362080785a59d911fd245db2c275e711d1c57c7c1e23adad47a6
4
+ data.tar.gz: 7b679be331e8013b9e6c590da7efce055e0166ee3a27aec92273f50f9ef19146
5
5
  SHA512:
6
- metadata.gz: d75e9ec3ac5fe55498740a81d41c96e80c84305461005e8fedf0d620424354a69bbf976cb971de32abc439011431603598690069a1fe0e31dd62baaa12fd81a6
7
- data.tar.gz: 8fc9eb6bebe7c1cb8a64e3b1eae6915bae3e12af7dccd2bdb8b01cb340b3acdc9988d8bdbc527adbfb317357662705ecde2da1eb8a70d59c677597c3214499a7
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,10 @@
1
+ Usps::Support::Engine.routes.draw do
2
+ resource :admin, only: [], controller: '/usps/support/admins' do
3
+ collection do
4
+ post :impersonate
5
+ post :expand
6
+ post :collapse
7
+ delete :cancel
8
+ end
9
+ end
10
+ end
@@ -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
@@ -11,6 +11,10 @@ module Usps::Support::Models
11
11
  client.check_suites_for_ref("#{ORG}/#{repo}", branch).check_suites
12
12
  end
13
13
 
14
+ def check_runs(repo, check_suite_id)
15
+ client.check_runs_for_check_suite("#{ORG}/#{repo}", check_suite_id).check_runs
16
+ end
17
+
14
18
  def fetch_head_commit(repo, branch)
15
19
  sha = client.ref("#{ORG}/#{repo}", "heads/#{branch}").object.sha
16
20
  client.commit("#{ORG}/#{repo}", sha).commit
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Support
5
- VERSION = '0.2.23'
5
+ VERSION = '0.2.25'
6
6
  end
7
7
  end
data/lib/usps/support.rb CHANGED
@@ -15,5 +15,8 @@ require_relative 'support/models'
15
15
  require_relative 'support/lib'
16
16
 
17
17
  # :nocov:
18
- require 'usps/support/railtie' if defined?(Rails)
18
+ if defined?(Rails)
19
+ require 'usps/support/railtie'
20
+ require 'usps/support/engine'
21
+ end
19
22
  # :nocov:
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.23
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-rails
108
+ homepage: https://github.com/unitedstatespowersquadrons/usps-support
104
109
  licenses: []
105
110
  metadata:
106
- homepage_uri: https://github.com/unitedstatespowersquadrons/usps-rails
111
+ homepage_uri: https://github.com/unitedstatespowersquadrons/usps-support
107
112
  rubygems_mfa_required: 'true'
108
113
  rdoc_options: []
109
114
  require_paths: