Allow child businesses to use parent service points without grant
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
87ff082279
commit
e40e87efe0
1 changed files with 35 additions and 24 deletions
|
|
@ -263,33 +263,44 @@
|
||||||
{ datasource = "payfrit" }
|
{ datasource = "payfrit" }
|
||||||
)>
|
)>
|
||||||
<cfif qSPOwner.recordCount GT 0 AND qSPOwner.BusinessID NEQ BusinessID>
|
<cfif qSPOwner.recordCount GT 0 AND qSPOwner.BusinessID NEQ BusinessID>
|
||||||
<!--- SP belongs to another business - check for active grant --->
|
<!--- SP belongs to another business - check if ordering business is a child of SP owner --->
|
||||||
<cfset qGrant = queryTimed(
|
<cfset qParent = queryTimed(
|
||||||
"SELECT ID, OwnerBusinessID, EconomicsType, EconomicsValue, EligibilityScope, TimePolicyType, TimePolicyData
|
"SELECT ParentBusinessID FROM Businesses WHERE ID = ? LIMIT 1",
|
||||||
FROM ServicePointGrants
|
[ { value = BusinessID, cfsqltype = "cf_sql_integer" } ],
|
||||||
WHERE GuestBusinessID = ? AND ServicePointID = ? AND StatusID = 1
|
|
||||||
LIMIT 1",
|
|
||||||
[
|
|
||||||
{ value = BusinessID, cfsqltype = "cf_sql_integer" },
|
|
||||||
{ value = ServicePointID, cfsqltype = "cf_sql_integer" }
|
|
||||||
],
|
|
||||||
{ datasource = "payfrit" }
|
{ datasource = "payfrit" }
|
||||||
)>
|
)>
|
||||||
<cfif qGrant.recordCount EQ 0>
|
<cfset isChildOfSPOwner = qParent.recordCount GT 0 AND val(qParent.ParentBusinessID) EQ qSPOwner.BusinessID>
|
||||||
<cfset apiAbort({ "OK": false, "ERROR": "sp_not_accessible", "MESSAGE": "Service point is not accessible to your business.", "DETAIL": "" })>
|
|
||||||
|
<cfif NOT isChildOfSPOwner>
|
||||||
|
<!--- Not a child business - check for active grant --->
|
||||||
|
<cfset qGrant = queryTimed(
|
||||||
|
"SELECT ID, OwnerBusinessID, EconomicsType, EconomicsValue, EligibilityScope, TimePolicyType, TimePolicyData
|
||||||
|
FROM ServicePointGrants
|
||||||
|
WHERE GuestBusinessID = ? AND ServicePointID = ? AND StatusID = 1
|
||||||
|
LIMIT 1",
|
||||||
|
[
|
||||||
|
{ value = BusinessID, cfsqltype = "cf_sql_integer" },
|
||||||
|
{ value = ServicePointID, cfsqltype = "cf_sql_integer" }
|
||||||
|
],
|
||||||
|
{ datasource = "payfrit" }
|
||||||
|
)>
|
||||||
|
<cfif qGrant.recordCount EQ 0>
|
||||||
|
<cfset apiAbort({ "OK": false, "ERROR": "sp_not_accessible", "MESSAGE": "Service point is not accessible to your business.", "DETAIL": "" })>
|
||||||
|
</cfif>
|
||||||
|
<!--- Validate time policy --->
|
||||||
|
<cfif NOT isGrantTimeActive(qGrant.TimePolicyType, qGrant.TimePolicyData)>
|
||||||
|
<cfset apiAbort({ "OK": false, "ERROR": "grant_time_inactive", "MESSAGE": "Service point access is not available at this time.", "DETAIL": "" })>
|
||||||
|
</cfif>
|
||||||
|
<!--- Validate eligibility --->
|
||||||
|
<cfif NOT checkGrantEligibility(qGrant.EligibilityScope, UserID, qGrant.OwnerBusinessID, BusinessID)>
|
||||||
|
<cfset apiAbort({ "OK": false, "ERROR": "grant_eligibility_failed", "MESSAGE": "You are not eligible to order at this service point.", "DETAIL": "" })>
|
||||||
|
</cfif>
|
||||||
|
<cfset grantID = qGrant.ID>
|
||||||
|
<cfset grantOwnerBusinessID = qGrant.OwnerBusinessID>
|
||||||
|
<cfset grantEconomicsType = qGrant.EconomicsType>
|
||||||
|
<cfset grantEconomicsValue = qGrant.EconomicsValue>
|
||||||
</cfif>
|
</cfif>
|
||||||
<!--- Validate time policy --->
|
<!--- If isChildOfSPOwner is true, no grant needed - child can use parent's service points --->
|
||||||
<cfif NOT isGrantTimeActive(qGrant.TimePolicyType, qGrant.TimePolicyData)>
|
|
||||||
<cfset apiAbort({ "OK": false, "ERROR": "grant_time_inactive", "MESSAGE": "Service point access is not available at this time.", "DETAIL": "" })>
|
|
||||||
</cfif>
|
|
||||||
<!--- Validate eligibility --->
|
|
||||||
<cfif NOT checkGrantEligibility(qGrant.EligibilityScope, UserID, qGrant.OwnerBusinessID, BusinessID)>
|
|
||||||
<cfset apiAbort({ "OK": false, "ERROR": "grant_eligibility_failed", "MESSAGE": "You are not eligible to order at this service point.", "DETAIL": "" })>
|
|
||||||
</cfif>
|
|
||||||
<cfset grantID = qGrant.ID>
|
|
||||||
<cfset grantOwnerBusinessID = qGrant.OwnerBusinessID>
|
|
||||||
<cfset grantEconomicsType = qGrant.EconomicsType>
|
|
||||||
<cfset grantEconomicsValue = qGrant.EconomicsValue>
|
|
||||||
</cfif>
|
</cfif>
|
||||||
</cfif>
|
</cfif>
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue