Skip to content

Commit 83d0e72

Browse files
committed
Release 3.4
1 parent 93dedb2 commit 83d0e72

File tree

7 files changed

+309
-108
lines changed

7 files changed

+309
-108
lines changed

lib/queueit_knownuserv3/integration_config_helpers.rb

Lines changed: 84 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,23 @@ def evaluateTriggerPart(triggerPart, currentPageUrl, request)
7575

7676
class UrlValidatorHelper
7777
def self.evaluate(triggerPart, url)
78-
if (!triggerPart.key?("Operator") ||
78+
if (triggerPart.nil? ||
79+
!triggerPart.key?("Operator") ||
7980
!triggerPart.key?("IsNegative") ||
8081
!triggerPart.key?("IsIgnoreCase") ||
81-
!triggerPart.key?("ValueToCompare") ||
8282
!triggerPart.key?("UrlPart"))
83-
return false;
83+
return false
8484
end
85-
85+
8686
urlPart = UrlValidatorHelper.getUrlPart(triggerPart["UrlPart"], url)
8787

8888
return ComparisonOperatorHelper.evaluate(
8989
triggerPart["Operator"],
9090
triggerPart["IsNegative"],
9191
triggerPart["IsIgnoreCase"],
9292
urlPart,
93-
triggerPart["ValueToCompare"])
93+
triggerPart["ValueToCompare"],
94+
triggerPart["ValuesToCompare"])
9495
end
9596

9697
def self.getUrlPart(urlPart, url)
@@ -115,12 +116,12 @@ def self.getUrlPart(urlPart, url)
115116
class CookieValidatorHelper
116117
def self.evaluate(triggerPart, cookieJar)
117118
begin
118-
if (!triggerPart.key?("Operator") ||
119+
if (triggerPart.nil? ||
120+
!triggerPart.key?("Operator") ||
119121
!triggerPart.key?("IsNegative") ||
120122
!triggerPart.key?("IsIgnoreCase") ||
121-
!triggerPart.key?("ValueToCompare") ||
122123
!triggerPart.key?("CookieName"))
123-
return false;
124+
return false
124125
end
125126

126127
if(cookieJar.nil?)
@@ -137,7 +138,8 @@ def self.evaluate(triggerPart, cookieJar)
137138
triggerPart["IsNegative"],
138139
triggerPart["IsIgnoreCase"],
139140
cookieValue,
140-
triggerPart["ValueToCompare"])
141+
triggerPart["ValueToCompare"],
142+
triggerPart["ValuesToCompare"])
141143
rescue
142144
return false
143145
end
@@ -147,69 +149,88 @@ def self.evaluate(triggerPart, cookieJar)
147149
class UserAgentValidatorHelper
148150
def self.evaluate(triggerPart, userAgent)
149151
begin
150-
if (!triggerPart.key?("Operator") ||
152+
if (triggerPart.nil? ||
153+
!triggerPart.key?("Operator") ||
151154
!triggerPart.key?("IsNegative") ||
152-
!triggerPart.key?("IsIgnoreCase") ||
153-
!triggerPart.key?("ValueToCompare"))
154-
return false;
155+
!triggerPart.key?("IsIgnoreCase"))
156+
return false
155157
end
156-
158+
157159
return ComparisonOperatorHelper.evaluate(
158160
triggerPart["Operator"],
159161
triggerPart["IsNegative"],
160162
triggerPart["IsIgnoreCase"],
161163
userAgent,
162-
triggerPart["ValueToCompare"])
164+
triggerPart["ValueToCompare"],
165+
triggerPart["ValuesToCompare"])
163166
end
164167
end
165168
end
166169

167170
class HttpHeaderValidatorHelper
168171
def self.evaluate(triggerPart, headers)
169-
begin
172+
begin
173+
if (triggerPart.nil? ||
174+
!triggerPart.key?("Operator") ||
175+
!triggerPart.key?("IsNegative") ||
176+
!triggerPart.key?("IsIgnoreCase")
177+
!triggerPart.key?("HttpHeaderName"))
178+
return false
179+
end
180+
170181
headerValue = headers[triggerPart['HttpHeaderName']]
171182
return ComparisonOperatorHelper.evaluate(
172183
triggerPart["Operator"],
173184
triggerPart["IsNegative"],
174185
triggerPart["IsIgnoreCase"],
175186
headerValue,
176-
triggerPart["ValueToCompare"])
187+
triggerPart["ValueToCompare"],
188+
triggerPart["ValuesToCompare"])
177189
rescue
178190
return false
179191
end
180192
end
181193
end
182194

183195
class ComparisonOperatorHelper
184-
def self.evaluate(opt, isNegative, ignoreCase, left, right)
185-
if(left.nil?)
186-
left = ''
196+
def self.evaluate(opt, isNegative, ignoreCase, value, valueToCompare, valuesToCompare)
197+
if (value.nil?)
198+
value = ''
199+
end
200+
201+
if (valueToCompare.nil?)
202+
valueToCompare = ''
187203
end
188-
if(right.nil?)
189-
right = ''
204+
205+
if (valuesToCompare.nil?)
206+
valuesToCompare = []
190207
end
191208

192209
case opt
193210
when "Equals"
194-
return ComparisonOperatorHelper.equals(left, right, isNegative, ignoreCase)
211+
return ComparisonOperatorHelper.equals(value, valueToCompare, isNegative, ignoreCase)
195212
when "Contains"
196-
return ComparisonOperatorHelper.contains(left, right, isNegative, ignoreCase)
213+
return ComparisonOperatorHelper.contains(value, valueToCompare, isNegative, ignoreCase)
197214
when "StartsWith"
198-
return ComparisonOperatorHelper.startsWith(left, right, isNegative, ignoreCase)
215+
return ComparisonOperatorHelper.startsWith(value, valueToCompare, isNegative, ignoreCase)
199216
when "EndsWith"
200-
return ComparisonOperatorHelper.endsWith(left, right, isNegative, ignoreCase)
217+
return ComparisonOperatorHelper.endsWith(value, valueToCompare, isNegative, ignoreCase)
201218
when "MatchesWith"
202-
return ComparisonOperatorHelper.matchesWith(left, right, isNegative, ignoreCase)
219+
return ComparisonOperatorHelper.matchesWith(value, valueToCompare, isNegative, ignoreCase)
220+
when "EqualsAny"
221+
return ComparisonOperatorHelper.equalsAny(value, valuesToCompare, isNegative, ignoreCase)
222+
when "ContainsAny"
223+
return ComparisonOperatorHelper.containsAny(value, valuesToCompare, isNegative, ignoreCase)
203224
else
204225
return false
205226
end
206227
end
207228

208-
def self.equals(left, right, isNegative, ignoreCase)
229+
def self.equals(value, valueToCompare, isNegative, ignoreCase)
209230
if(ignoreCase)
210-
evaluation = left.upcase.eql? right.upcase
231+
evaluation = value.upcase.eql? valueToCompare.upcase
211232
else
212-
evaluation = left.eql? right
233+
evaluation = value.eql? valueToCompare
213234
end
214235

215236
if(isNegative)
@@ -219,29 +240,29 @@ def self.equals(left, right, isNegative, ignoreCase)
219240
end
220241
end
221242

222-
def self.contains(left, right, isNegative, ignoreCase)
223-
if(right.eql? "*")
243+
def self.contains(value, valueToCompare, isNegative, ignoreCase)
244+
if(valueToCompare.eql? "*")
224245
return true
225246
end
226247

227248
if(ignoreCase)
228-
left = left.upcase
229-
right = right.upcase
249+
value = value.upcase
250+
valueToCompare = valueToCompare.upcase
230251
end
231252

232-
evaluation = left.include? right
253+
evaluation = value.include? valueToCompare
233254
if(isNegative)
234255
return !evaluation
235256
else
236257
return evaluation
237258
end
238259
end
239260

240-
def self.startsWith(left, right, isNegative, ignoreCase)
261+
def self.startsWith(value, valueToCompare, isNegative, ignoreCase)
241262
if(ignoreCase)
242-
evaluation = left.upcase.start_with? right.upcase
263+
evaluation = value.upcase.start_with? valueToCompare.upcase
243264
else
244-
evaluation = left.start_with? right
265+
evaluation = value.start_with? valueToCompare
245266
end
246267

247268
if(isNegative)
@@ -251,11 +272,11 @@ def self.startsWith(left, right, isNegative, ignoreCase)
251272
end
252273
end
253274

254-
def self.endsWith(left, right, isNegative, ignoreCase)
275+
def self.endsWith(value, valueToCompare, isNegative, ignoreCase)
255276
if(ignoreCase)
256-
evaluation = left.upcase.end_with? right.upcase
277+
evaluation = value.upcase.end_with? valueToCompare.upcase
257278
else
258-
evaluation = left.end_with? right
279+
evaluation = value.end_with? valueToCompare
259280
end
260281

261282
if(isNegative)
@@ -265,19 +286,37 @@ def self.endsWith(left, right, isNegative, ignoreCase)
265286
end
266287
end
267288

268-
def self.matchesWith(left, right, isNegative, ignoreCase)
289+
def self.matchesWith(value, valueToCompare, isNegative, ignoreCase)
269290
if(ignoreCase)
270-
pattern = Regexp.new(right, Regexp::IGNORECASE)
291+
pattern = Regexp.new(valueToCompare, Regexp::IGNORECASE)
271292
else
272-
pattern = Regexp.new(right)
293+
pattern = Regexp.new(valueToCompare)
273294
end
274295

275-
evaluation = pattern.match(left) != nil
296+
evaluation = pattern.match(value) != nil
276297
if(isNegative)
277298
return !evaluation
278299
else
279300
return evaluation
280301
end
281302
end
303+
304+
def self.equalsAny(value, valuesToCompare, isNegative, ignoreCase)
305+
valuesToCompare.each do |valueToCompare|
306+
if (ComparisonOperatorHelper.equals(value, valueToCompare, false, ignoreCase))
307+
return !isNegative
308+
end
309+
end
310+
return isNegative
311+
end
312+
313+
def self.containsAny(value, valuesToCompare, isNegative, ignoreCase)
314+
valuesToCompare.each do |valueToCompare|
315+
if (ComparisonOperatorHelper.contains(value, valueToCompare, false, ignoreCase))
316+
return !isNegative
317+
end
318+
end
319+
return isNegative
320+
end
282321
end
283322
end

lib/queueit_knownuserv3/known_user.rb

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -226,44 +226,59 @@ def self.validateRequestByIntegrationConfig(currentUrlWithoutQueueITToken, queue
226226
return RequestValidationResult.new(nil, nil, nil, nil)
227227
end
228228

229+
# unspecified or 'Queue' specified
229230
if(!matchedConfig.key?("ActionType") || Utils.isNilOrEmpty(matchedConfig["ActionType"]) || matchedConfig["ActionType"].eql?(ActionTypes::QUEUE))
230-
queueConfig = QueueEventConfig.new
231-
queueConfig.eventId = matchedConfig["EventId"]
232-
queueConfig.queueDomain = matchedConfig["QueueDomain"]
233-
queueConfig.layoutName = matchedConfig["LayoutName"]
234-
queueConfig.culture = matchedConfig["Culture"]
235-
queueConfig.cookieDomain = matchedConfig["CookieDomain"]
236-
queueConfig.extendCookieValidity = matchedConfig["ExtendCookieValidity"]
237-
queueConfig.cookieValidityMinute = matchedConfig["CookieValidityMinute"]
238-
queueConfig.version = customerIntegration["Version"]
239-
240-
case matchedConfig["RedirectLogic"]
241-
when "ForcedTargetUrl"
242-
targetUrl = matchedConfig["ForcedTargetUrl"]
243-
when "EventTargetUrl"
244-
targetUrl = ''
245-
else
246-
targetUrl = currentUrlWithoutQueueITToken
247-
end
248-
249-
return _resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, request, debugEntries)
250-
251-
else # cancel action
252-
cancelConfig = CancelEventConfig.new;
253-
cancelConfig.eventId = matchedConfig["EventId"]
254-
cancelConfig.queueDomain = matchedConfig["QueueDomain"]
255-
cancelConfig.cookieDomain = matchedConfig["CookieDomain"]
256-
cancelConfig.version = customerIntegration["Version"]
257-
258-
return _cancelRequestByLocalConfig(currentUrlWithoutQueueITToken, queueitToken, cancelConfig, customerId, secretKey, request, debugEntries);
231+
handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries)
232+
233+
elsif(matchedConfig["ActionType"].eql?(ActionTypes::CANCEL))
234+
handleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries)
235+
236+
# for all unknown types default to 'Ignore'
237+
else
238+
userInQueueService = getUserInQueueService(request.cookie_jar)
239+
userInQueueService.getIgnoreActionResult()
259240
end
241+
260242
rescue StandardError => stdErr
261243
raise KnownUserError, "integrationConfiguration text was not valid: " + stdErr.message
262244
ensure
263245
setDebugCookie(debugEntries, request.cookie_jar)
264246
end
265247
end
266248

249+
def self.handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries)
250+
queueConfig = QueueEventConfig.new
251+
queueConfig.eventId = matchedConfig["EventId"]
252+
queueConfig.queueDomain = matchedConfig["QueueDomain"]
253+
queueConfig.layoutName = matchedConfig["LayoutName"]
254+
queueConfig.culture = matchedConfig["Culture"]
255+
queueConfig.cookieDomain = matchedConfig["CookieDomain"]
256+
queueConfig.extendCookieValidity = matchedConfig["ExtendCookieValidity"]
257+
queueConfig.cookieValidityMinute = matchedConfig["CookieValidityMinute"]
258+
queueConfig.version = customerIntegration["Version"]
259+
260+
case matchedConfig["RedirectLogic"]
261+
when "ForcedTargetUrl"
262+
targetUrl = matchedConfig["ForcedTargetUrl"]
263+
when "EventTargetUrl"
264+
targetUrl = ''
265+
else
266+
targetUrl = currentUrlWithoutQueueITToken
267+
end
268+
269+
return _resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, request, debugEntries)
270+
end
271+
272+
def self.handleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries)
273+
cancelConfig = CancelEventConfig.new;
274+
cancelConfig.eventId = matchedConfig["EventId"]
275+
cancelConfig.queueDomain = matchedConfig["QueueDomain"]
276+
cancelConfig.cookieDomain = matchedConfig["CookieDomain"]
277+
cancelConfig.version = customerIntegration["Version"]
278+
279+
return _cancelRequestByLocalConfig(currentUrlWithoutQueueITToken, queueitToken, cancelConfig, customerId, secretKey, request, debugEntries);
280+
end
281+
267282
def self.cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, secretKey, request)
268283
debugEntries = Hash.new
269284
begin

lib/queueit_knownuserv3/models.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,6 @@ def initialize(message)
9292
class ActionTypes
9393
CANCEL = "Cancel"
9494
QUEUE = "Queue"
95+
IGNORE = "Ignore"
9596
end
9697
end

lib/queueit_knownuserv3/user_in_queue_service.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
module QueueIt
55
class UserInQueueService
6-
SDK_VERSION = "3.3.2"
6+
SDK_VERSION = "3.4.0"
77

88
def initialize(userInQueueStateRepository)
99
@userInQueueStateRepository = userInQueueStateRepository
@@ -70,7 +70,7 @@ def getQueueITTokenValidationResult(targetUrl, eventId, config, queueParams,cust
7070
!(queueParams.cookieValidityMinute.nil?) ? queueParams.cookieValidityMinute : config.cookieValidityMinute,
7171
!Utils::isNilOrEmpty(config.cookieDomain) ? config.cookieDomain : '',
7272
secretKey)
73-
return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, queueParams.queueId, nil)
73+
return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, queueParams.queueId, nil)
7474
end
7575

7676
def getVaidationErrorResult(customerId, targetUrl, config, qParams, errorCode)
@@ -112,5 +112,9 @@ def getQueryString(customerId, eventId, configVersion, culture, layoutName)
112112
def extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey)
113113
@userInQueueStateRepository.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey)
114114
end
115+
116+
def getIgnoreActionResult()
117+
return RequestValidationResult.new(ActionTypes::IGNORE, nil, nil, nil)
118+
end
115119
end
116120
end

0 commit comments

Comments
 (0)