strongmind-auth 1.1.98 → 1.1.102
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: d187d5804082b937eb593a7e6097057531cf701cd5f5d6ca5c5e204e70a74ac6
|
4
|
+
data.tar.gz: 0ea33f4dfe029e0adca678d1a5c0da5a4cacdce1757c0b7a80c7680f6d3bd4a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 697183d85bc8ef2a0a338b9d553a822972f59bf84bebb2b2da233f8507be0226726ff87e0da2de6ac7a8f33c418297f2b73b7ebdf5d0c1cb5c5457fc281a2d2c
|
7
|
+
data.tar.gz: 1254bc1891abbfe7b4ab360a552d9c5c27bd6564096ac412daa5a3167c8f4a65e0d074e0d8818bc8ec35113bdd302aa738400d6fc68f3a4f9104554185f5fdfc
|
@@ -6,7 +6,13 @@ 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
|
+
|
13
|
+
navbar = Rails.cache.fetch(user_cache_key_encoded, expires_in: 1.day) do
|
14
|
+
Strongmind::CommonNavFetcher.new(current_user).retrieve(nav_items, common_nav_options)
|
15
|
+
end
|
10
16
|
|
11
17
|
@top_navbar_html = navbar[:top_navbar_html]
|
12
18
|
@bottom_navbar_html = navbar[:bottom_navbar_html]
|
@@ -33,9 +39,51 @@ module StrongMindNav
|
|
33
39
|
|
34
40
|
def common_nav_options
|
35
41
|
{
|
36
|
-
menu_items: menu_items,
|
37
42
|
authenticity_token: form_authenticity_token,
|
38
43
|
show_role_switcher: false
|
39
44
|
}
|
40
45
|
end
|
46
|
+
|
47
|
+
def build_nav_items
|
48
|
+
items = { nav_items: menu_items.map { |item| nav_item_data(item) } }
|
49
|
+
items[:nav_items].first[:is_active] = true unless items[:nav_items].any? { |item| item[:is_active] }
|
50
|
+
items
|
51
|
+
end
|
52
|
+
|
53
|
+
def nav_item_data(item)
|
54
|
+
url = item[:url]
|
55
|
+
{
|
56
|
+
name: item[:name],
|
57
|
+
icon: item[:icon],
|
58
|
+
url: url,
|
59
|
+
is_active: current_page?(url)
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def current_page?(url)
|
66
|
+
request.fullpath == URI.parse(url).path || path_in_request?(url)
|
67
|
+
end
|
68
|
+
|
69
|
+
def path_in_request?(path)
|
70
|
+
sanitized_path = path.gsub('/', '')
|
71
|
+
|
72
|
+
path_to_compare = request.fullpath.split('?').first
|
73
|
+
|
74
|
+
return path_to_compare == '/' if sanitized_path.empty?
|
75
|
+
path_to_compare.include?(sanitized_path) || path_to_compare.include?(sanitized_path.pluralize)
|
76
|
+
end
|
77
|
+
|
78
|
+
def generate_user_cache_key(nav_items)
|
79
|
+
navbar_options_cache_key = nav_items.to_json
|
80
|
+
|
81
|
+
user_cache_key = if current_user.respond_to?(:selected_role_id)
|
82
|
+
"user_#{current_user.uid}_#{current_user.selected_role_id}_#{navbar_options_cache_key}_navbar"
|
83
|
+
else
|
84
|
+
"user_#{current_user.uid}_#{navbar_options_cache_key}_navbar"
|
85
|
+
end
|
86
|
+
|
87
|
+
Digest::SHA256.hexdigest(user_cache_key)
|
88
|
+
end
|
41
89
|
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.102
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|