project BLF > class BUserRole > method ValidateComponent
Description
Write here all tests on database update (new / modify / delete) that cannot be coded with a validation mask.
The type of update can be found in tc_status (N/C/D).
If you find incorrect data, you must write an entry in tFcMessages (using SetMessage) and set the return status of this method to either +1 or -1.
Return status +1 = data will still be accepted.
Return status -1 = data will not be accepted.
This method is run from SetPublicTables, before transferring the received data into the class temp-tables.
Parameters
oiReturnStatus | output | integer | |
Internal usage
unused
program code (program/buserrole.p)
<ANCESTOR-CODE>
For Each t_sUsrRole Where
t_sUsrRole.tc_Status <> 'D':U
No-lock:
/*check if the default role is active*/
if t_sUsrRole.UsrRoleIsDefaultRole = true
then do:
<Q-32 run RoleByNameActiveDescr (all) (Read) (NoCache)
(input ?, (RoleDescription)
input ?, (RoleIsActive)
input t_sUsrRole.tcRoleName, (RoleName)
output dataset tqRoleByNameActiveDescr) in BRole >
find first tqRoleByNameActiveDescr where
tqRoleByNameActiveDescr.tcRoleName = t_sUsrRole.tcRoleName no-error.
if available tqRoleByNameActiveDescr and
tqRoleByNameActiveDescr.tlRoleIsActive = false
then do:
assign vcMessage = trim(#T-34'It is not possible to set a not active role as default.':255(8988)T-34#)
oiReturnStatus = -1.
<M-33 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tUsrRole.UsrRoleIsDefaultRole':U (icFieldName),
input t_sUsrRole.UsrRoleIsDefaultRole (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sUsrRole.tc_Rowid (icRowid),
input 'BLF-431':U:U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BUserRole>
end.
end.
If Not Can-find(First t_sUsrRoleDomain Where
t_sUsrRoleDomain.UsrRole_ID = t_sUsrRole.UsrRole_ID And
t_sUsrRoleDomain.tc_Status <> 'D':U)
Then Do:
Assign vcMessage = #T-1'Each User Role combination should be linked to at least one Domain.':255(6728)T-1#
oiReturnStatus = -1.
<M-2 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sUsrRole.tc_Rowid (icRowid),
input 'BLF-428':U:U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BUserRole>
End. /* If Not Can-find(First t_sUsrRoleDomain Where */
For Each t_sUsrRoleDomain Where
t_sUsrRoleDomain.UsrRole_ID = t_sUsrRole.UsrRole_ID And
t_sUsrRoleDomain.tc_Status <> 'D':U
break by t_sUsrRoleDomain.UsrRole_ID
by t_sUsrRoleDomain.tcDomainCode :
/* Check if the combination User/Domain exists in UsrDomain table */
if first-of (t_sUsrRoleDomain.tcDomainCode)
then do :
<Q-30 assign vlFcQueryRecordsAvailable = UsrDomainByUserDomain (NoCache)
(input t_sUsrRole.Usr_ID, (UserId)
input t_sUsrRoleDomain.Domain_ID, (DomainId)
input t_sUsrRole.tcUsrLogin, (UserLogin)
input t_sUsrRoleDomain.tcDomainCode, (DomainCode)) in BUser >
If vlFcQueryRecordsAvailable = False
Then Do:
Assign vcMessage = Trim(Substitute(#T-5'The user (&1) has no access to the domain (&2).':100(6770)T-5#,Trim(t_sUsrRole.tcUsrLogin),Trim(t_sUsrRoleDomain.tcDomainCode)))
oiReturnStatus = -1.
<M-4 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sUsrRoleDomain.tc_Rowid (icRowid),
input 'BLF-429':U:U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BUserRole>
End. /*If vlFcQueryRecordsAvailable = False*/
end. /* if first-of */
/*assign role and user ids*/
assign t_sUsrRoleDomain.Role_ID = t_sUsrRole.Role_ID
t_sUsrRoleDomain.Usr_ID = t_sUsrRole.Usr_ID.
End. /*For Each t_sUsrRoleDomain Where*/
For Each t_sUsrRoleCompany Where
t_sUsrRoleCompany.UsrRole_ID = t_sUsrRole.UsrRole_ID And
t_sUsrRoleCompany.tc_Status <> 'D':U
break by t_sUsrRoleCompany.UsrRole_ID by t_sUsrRoleCompany.tcCompanyCode :
if first-of (t_sUsrRoleCompany.tcCompanyCode)
then do :
<Q-31 assign vlFcQueryRecordsAvailable = UsrCompanyByLoginCompDomain (NoCache)
(input t_sUsrRoleCompany.Company_ID, (CompanyId)
input t_sUsrRole.tcUsrLogin, (UserLogin)
input t_sUsrRoleCompany.tcCompanyCode, (CompanyCode)
input ?, (DomainCode)
input ?, (DomainId)
input t_sUsrRole.Usr_ID, (UserId)) in BUser >
If vlFcQueryRecordsAvailable = False
Then Do:
Assign vcMessage = Trim(Substitute(#T-26'The user (&1) has no access the entity (&2).':100(6773)T-26#,Trim(t_sUsrRole.tcUsrLogin),Trim(t_sUsrRoleCompany.tcCompanyCode)))
oiReturnStatus = -1.
<M-25 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sUsrRoleCompany.tc_Rowid (icRowid),
input 'BLF-430':U:U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BUserRole>
End. /*If vlFcQueryRecordsAvailable = False*/
end. /* if first-of */
/*assign role and user ids*/
assign t_sUsrRoleCompany.Role_ID = t_sUsrRole.Role_ID
t_sUsrRoleCompany.Usr_ID = t_sUsrRole.Usr_ID.
/*assign domain ids*/
IF t_sUsrRoleCompany.Domain_ID = 0 OR t_sUsrRoleCompany.Domain_ID = ?
THEN DO :
<Q-27 run CompanyByCompanyCodeDomainCode (all) (Read) (NoCache)
(input t_sUsrRoleCompany.Company_ID, (CompanyId)
input ?, (CompanyCode)
input ?, (DomainCode)
input ?, (DomainId)
input ?, (CompanyIsActive)
output dataset tqCompanyByCompanyCodeDomainCode) in BCompany>
find first tqCompanyByCompanyCodeDomainCode no-error.
if available tqCompanyByCompanyCodeDomainCode
then assign t_sUsrRoleCompany.Domain_ID = tqCompanyByCompanyCodeDomainCode.tiDomain_ID.
END.
End. /*For Each t_sUsrRoleCompany Where*/
End. /* For Each t_sUsrRole Where */
/* ====================================================================================== */
/* A user should at least be linked to 1 role; go through all removed UsrRoles */
/* records and check for every Usr if there is either: */
/* - a tUsrRole record that is not marked for deletion */
/* - a UsrRole record in the db that is not marked for deletion */
/* ====================================================================================== */
/* ====================================================================================== */
/* A user should have a single default-linked to a role; go through all new, changed or */
/* removed UsrRoles records and check for every Usr if this condition is true. */
/* ====================================================================================== */
<M-38 run ValidateComponentDefaultRole (output viFcReturnSuper (oiReturnStatus)) in BUserRole>
if viFcReturnSuper <> 0
and oiReturnStatus >= 0
then assign oiReturnStatus = viFcReturnSuper.
/* ================================================================= */
/* Check SOD rule 2 */
/* ================================================================= */
if can-find (first t_sUsrRoleCompany where t_sUsrRoleCompany.tc_Status = "N")
and can-find (Syst where Syst.SystSODActive <> false) /* active or activating */
then do:
<M-40 run ValidateComponentSOD (output viFcReturnSuper (oiReturnStatus)) in BUserRole>
if viFcReturnSuper <> 0
and oiReturnStatus >= 0
then assign oiReturnStatus = viFcReturnSuper.
end.