strongmind-auth 1.1.100 → 1.1.104
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e28c44ee15358c2cd005c765701a0bae728a8f731a26bd983cc89b98f22f93a0
|
4
|
+
data.tar.gz: f9002365819bfc3cb943d6b432406d4aaf8c0874bf661abff9f86ffda05727a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4105b0026dab50a2394d3bdbd788bb4bb921fe268670b2a4020688568dbb34d02a47c4fc32ddea6c7aea8600226a3dc6fd1c7090d3e11f9b80730caf4f6c1036
|
7
|
+
data.tar.gz: 0dbc0726df726ff5ae0baf5e1c6e3548d55b239f9da13ef48a248f4ffc16e24b267656a973a2572954d92bc982b09ae452a3ae8b9cde0ce5afe2370f33e02a8d
|
@@ -6,7 +6,12 @@ module StrongMindNav
|
|
6
6
|
|
7
7
|
def fetch_common_nav
|
8
8
|
begin
|
9
|
-
|
9
|
+
nav_items = build_nav_items
|
10
|
+
|
11
|
+
user_cache_key_encoded = generate_user_cache_key(nav_items)
|
12
|
+
navbar = Rails.cache.fetch(user_cache_key_encoded, expires_in: 30.seconds) do
|
13
|
+
Strongmind::CommonNavFetcher.new(current_user).retrieve(nav_items, common_nav_options)
|
14
|
+
end
|
10
15
|
|
11
16
|
@top_navbar_html = navbar[:top_navbar_html]
|
12
17
|
@bottom_navbar_html = navbar[:bottom_navbar_html]
|
@@ -33,9 +38,55 @@ module StrongMindNav
|
|
33
38
|
|
34
39
|
def common_nav_options
|
35
40
|
{
|
36
|
-
menu_items: menu_items,
|
37
41
|
authenticity_token: form_authenticity_token,
|
38
42
|
show_role_switcher: false
|
39
43
|
}
|
40
44
|
end
|
45
|
+
|
46
|
+
def build_nav_items
|
47
|
+
items = { nav_items: menu_items.map { |item| nav_item_data(item) } }
|
48
|
+
items[:nav_items].first[:is_active] = true unless items[:nav_items].any? { |item| item[:is_active] }
|
49
|
+
items
|
50
|
+
end
|
51
|
+
|
52
|
+
def nav_item_data(item)
|
53
|
+
url = item[:url]
|
54
|
+
{
|
55
|
+
name: item[:name],
|
56
|
+
icon: item[:icon],
|
57
|
+
url: url,
|
58
|
+
is_active: current_page?(url)
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def current_page?(url)
|
65
|
+
request.fullpath == URI.parse(url).path || path_in_request?(url)
|
66
|
+
end
|
67
|
+
|
68
|
+
def path_in_request?(path)
|
69
|
+
sanitized_path = path.gsub('/', '')
|
70
|
+
|
71
|
+
path_to_compare = request.fullpath.split('?').first
|
72
|
+
|
73
|
+
return path_to_compare == '/' if sanitized_path.empty?
|
74
|
+
path_to_compare.include?(sanitized_path) || path_to_compare.include?(sanitized_path.pluralize)
|
75
|
+
end
|
76
|
+
|
77
|
+
def generate_user_cache_key(nav_items)
|
78
|
+
navbar_options_cache_key = nav_items.to_json
|
79
|
+
session_token = session[:_csrf_token]
|
80
|
+
user = "user_#{current_user.uid}"
|
81
|
+
|
82
|
+
user_cache_key = if current_user.respond_to?(:selected_role_id)
|
83
|
+
role = "role_#{current_user.selected_role_id}"
|
84
|
+
|
85
|
+
[session_token, user, role, navbar_options_cache_key, 'navbar'].join('_')
|
86
|
+
else
|
87
|
+
[session_token, user, navbar_options_cache_key, 'navbar'].join('_')
|
88
|
+
end
|
89
|
+
|
90
|
+
Digest::SHA256.hexdigest(user_cache_key)
|
91
|
+
end
|
41
92
|
end
|
@@ -5,7 +5,7 @@ require 'platform_sdk'
|
|
5
5
|
module Strongmind
|
6
6
|
# This class is responsible for fetching the common navbar data from SM Central
|
7
7
|
class CommonNavFetcher
|
8
|
-
attr_reader :user, :
|
8
|
+
attr_reader :user, :auth_client
|
9
9
|
|
10
10
|
include Rails.application.routes.url_helpers
|
11
11
|
|
@@ -13,40 +13,25 @@ module Strongmind
|
|
13
13
|
|
14
14
|
class UserNotFoundError < StandardError; end
|
15
15
|
|
16
|
-
def initialize(user
|
16
|
+
def initialize(user)
|
17
17
|
raise Strongmind::Exceptions::UserNotFoundError, 'User not found' unless user.present?
|
18
|
-
raise ArgumentError, 'Request not found' unless request.present?
|
19
18
|
raise ArgumentError, 'Identity base URL not found at IDENTITY_BASE_URL in environment' unless ENV['IDENTITY_BASE_URL'].present?
|
20
19
|
raise ArgumentError, 'Identity client ID not found at IDENTITY_CLIENT_ID in environment' unless ENV['IDENTITY_CLIENT_ID'].present?
|
21
20
|
raise ArgumentError, 'Identity client secret not found at IDENTITY_CLIENT_SECRET in environment' unless ENV['IDENTITY_CLIENT_SECRET'].present?
|
22
21
|
|
23
22
|
@user = user
|
24
|
-
@request = request
|
25
23
|
@auth_client = PlatformSdk::Identity::AuthClient.new(
|
26
24
|
ENV.fetch('IDENTITY_BASE_URL'), ENV.fetch('IDENTITY_CLIENT_ID'), ENV.fetch('IDENTITY_CLIENT_SECRET')
|
27
25
|
)
|
28
26
|
end
|
29
27
|
|
30
|
-
def retrieve(nav_options)
|
31
|
-
response = fetch_navbar_data(
|
28
|
+
def retrieve(nav_items, nav_options)
|
29
|
+
response = fetch_navbar_data(nav_items, nav_options)
|
32
30
|
parse_navbar(response)
|
33
31
|
end
|
34
32
|
|
35
33
|
private
|
36
34
|
|
37
|
-
def current_page?(url)
|
38
|
-
request.fullpath == URI.parse(url).path || path_in_request?(url)
|
39
|
-
end
|
40
|
-
|
41
|
-
def path_in_request?(path)
|
42
|
-
sanitized_path = path.gsub('/', '')
|
43
|
-
|
44
|
-
path_to_compare = request.fullpath.split('?').first
|
45
|
-
|
46
|
-
return path_to_compare == '/' if sanitized_path.empty?
|
47
|
-
path_to_compare.include?(sanitized_path) || path_to_compare.include?(sanitized_path.pluralize)
|
48
|
-
end
|
49
|
-
|
50
35
|
def fetch_navbar_data(nav_items, nav_options)
|
51
36
|
session = refresh_session
|
52
37
|
access_token = session[:access_token]
|
@@ -95,21 +80,5 @@ module Strongmind
|
|
95
80
|
def parse_navbar(response)
|
96
81
|
JSON.parse(response.body, symbolize_names: true) if response
|
97
82
|
end
|
98
|
-
|
99
|
-
def build_nav_items(menu_items)
|
100
|
-
items = { nav_items: menu_items.map { |item| nav_item_data(item) } }
|
101
|
-
items[:nav_items].first[:is_active] = true unless items[:nav_items].any? { |item| item[:is_active] }
|
102
|
-
items
|
103
|
-
end
|
104
|
-
|
105
|
-
def nav_item_data(item)
|
106
|
-
url = item[:url]
|
107
|
-
{
|
108
|
-
name: item[:name],
|
109
|
-
icon: item[:icon],
|
110
|
-
url: url,
|
111
|
-
is_active: current_page?(url)
|
112
|
-
}
|
113
|
-
end
|
114
83
|
end
|
115
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strongmind-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.104
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Team Belding
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|