project BLF > class BUserRole > method ValidateComponentDefaultRole
Description
A user should have a default role
A user can only have 1 default role
This role needs to be active
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
BLF
program code (program1/buserrole.p)
<Q-43 run UserRoleByUserRole
(Start) in BUserRole >
for each t_sUsrRole
break by t_sUsrRole.Usr_ID:
if first-of (t_sUsrRole.Usr_ID)
then do:
/*get all default roles from the db for this user */
/*if all data is correct you should only get 1 record or nothing for a usr which is not linked to any role yet*/
<Q-42 run UserRoleByUserRole (all) (Read) (NoCache)
(input t_sUsrRole.Usr_ID, (UsrID)
input ?, (RoleID)
input true, (UsrRoleIsDefaultRole)
input ?, (RoleName)
input ?, (UsrLogin)
input ?, (UsrName)
output dataset tqUserRoleByUserRole) in BUserRole >
find tqUserRoleByUserRole where
tqUserRoleByUserRole.tiUsr_ID = t_sUsrRole.Usr_ID no-error.
if available tqUserRoleByUserRole /*1 and only 1 default role found in the db*/
then do:
/*check if this default role is loaded in the instance*/
find bUsrRole where
bUsrRole.Usr_ID = t_sUsrRole.Usr_ID and
bUsrRole.Role_ID = tqUserRoleByUserRole.tiRole_ID no-error.
if available bUsrRole
then do: /*the default role is loaded in the instance*/
if bUsrRole.UsrRoleIsDefaultRole = false or
bUsrRole.tc_Status = 'D':U
then do: /*this default role is not the default role anymore*/
/*check if a default role is defined*/
find first bUsrRole2 where
bUsrRole2.Usr_ID = t_sUsrRole.Usr_ID and
bUsrRole2.UsrRoleIsDefaultRole = true and
bUsrRole2.Role_ID <> bUsrRole.Role_ID and
bUsrRole2.tc_Status <> 'D':U no-error.
if available bUsrRole2 /*adefault role defined*/
then do:
assign vlDefRoleFound = true.
end. /*if available bUsrRole2*/
if vlDefRoleFound = true
then do:
/*check if 1 and only 1 default role can be found*/
find bUsrRole2 where
bUsrRole2.Usr_ID = t_sUsrRole.Usr_ID and
bUsrRole2.UsrRoleIsDefaultRole = true and
bUsrRole2.Role_ID <> bUsrRole.Role_ID and
bUsrRole2.tc_Status <> 'D':U no-error.
if not available bUsrRole2 /*more then one new default roles defined*/
then do:
assign vcMessage = trim(#T-50'A user can only have a single default role. User: $1':255(8991)T-50#)
oiReturnStatus = -1.
<M-48 run SetMessage
(input vcMessage (icMessage),
input t_sUsrRole.tcUsrLogin (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-244':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BUserRole>
<Q-49 run UserRoleByUserRole
(Stop) in BUserRole >
return.
end. /*if not available bUsrRole2*/
end. /* if vlDefRoleFound = true */
end.
else do: /*this default role is still the default role*/
/*check if an other default role is defined*/
find first bUsrRole2 where
bUsrRole2.Usr_ID = t_sUsrRole.Usr_ID and
bUsrRole2.UsrRoleIsDefaultRole = true and
bUsrRole2.Role_ID <> bUsrRole.Role_ID and
bUsrRole2.tc_Status <> 'D':U no-error.
if available bUsrRole2 /*another default role is defined*/
then do:
assign vcMessage = trim(#T-53'A user can only have a single default role. User: $1':255(8991)T-53#)
oiReturnStatus = -1.
<M-51 run SetMessage
(input vcMessage (icMessage),
input t_sUsrRole.tcUsrLogin (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-245':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BUserRole>
<Q-52 run UserRoleByUserRole
(Stop) in BUserRole >
return.
end. /*if not available bUsrRole2*/
end.
end. /*if available bUsrRole*/
else do: /*the default role is not loaded in the instance*/
/*check if an other default role is defined*/
find first bUsrRole2 where
bUsrRole2.Usr_ID = t_sUsrRole.Usr_ID and
bUsrRole2.UsrRoleIsDefaultRole = true and
bUsrRole2.Role_ID <> tqUserRoleByUserRole.tiRole_ID and
bUsrRole2.tc_Status <> 'D':U no-error.
if available bUsrRole2 /*another default role is defined*/
then do:
assign vcMessage = trim(#T-56'A user can only have a single default role. User: $1':255(8991)T-56#)
oiReturnStatus = -1.
<M-54 run SetMessage
(input vcMessage (icMessage),
input t_sUsrRole.tcUsrLogin (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-423':U:U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BUserRole>
<Q-55 run UserRoleByUserRole
(Stop) in BUserRole >
return.
end. /*if not available bUsrRole2*/
end.
end. /*if available tqUserRoleByUserRole*/
else do: /*no default role is found in the DB or more then 1 default role is found in the DB*/
/*check if there is more then 1 default role in the db*/
/*because the find tqUserRoleByUserRole where .. failed and the
find first tqUserRoleByUserRole where ... succeeds we can conclude
that there are more defautl roles defined*/
find first tqUserRoleByUserRole where
tqUserRoleByUserRole.tiUsr_ID = t_sUsrRole.Usr_ID no-error.
if available tqUserRoleByUserRole
then do: /*more then 1 default role for this user in the DB*/
assign vcMessage = trim(#T-59'A user can only have a single default role. User: $1':255(8991)T-59#)
oiReturnStatus = -1.
<M-57 run SetMessage
(input vcMessage (icMessage),
input t_sUsrRole.tcUsrLogin (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-424':U:U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BUserRole>
<Q-58 run UserRoleByUserRole
(Stop) in BUserRole >
return.
end.
/*check if there is more then 1 default rol*/
if not can-find (bUsrRole where
bUsrRole.Usr_ID = t_sUsrRole.Usr_ID and
bUsrRole.UsrRoleIsDefaultRole = true and
bUsrRole.tc_Status <> 'D':U) and
can-find (first bUsrRole where
bUsrRole.Usr_ID = t_sUsrRole.Usr_ID and
bUsrRole.UsrRoleIsDefaultRole = true and
bUsrRole.tc_Status <> 'D':U)
then do: /*no or more then 1 default role for this user*/
assign vcMessage = trim(#T-63'A user can only have a single default role. User: $1':255(8991)T-63#)
oiReturnStatus = -1.
<M-60 run SetMessage
(input vcMessage (icMessage),
input t_sUsrRole.tcUsrLogin (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-425':U:U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BUserRole>
<Q-61 run UserRoleByUserRole
(Stop) in BUserRole >
return.
end.
end.
end. /*if first-of (t_sUsrRole.Usr_ID)*/
end. /*for each t_sUsrRole*/
<Q-44 run UserRoleByUserRole
(Stop) in BUserRole >
/* ======================================================================================= */
/* RoleScope records can only exist for Roles where BusComponent_ID is filled */
/* AT least 1 RoleScopeValue record should exist for Roles where BusComponent_ID is filled */
/* ======================================================================================= */
for each t_sUsrRole where
t_sUsrRole.tc_Status <> "D":U :
<Q-25 run RoleByNameActiveDescr (all) (Read) (NoCache) (input ?, (RoleDescription)
input ?, (RoleIsActive)
input t_sUsrRole.tcRoleName, (RoleName)
output dataset tqRoleByNameActiveDescr) in BRole >
Find First tqRoleByNameActiveDescr No-error.
If Available tqRoleByNameActiveDescr And
(tqRoleByNameActiveDescr.tiBusComponent_ID = 0 Or
tqRoleByNameActiveDescr.tiBusComponent_ID = ? ) And
can-find (first t_sUsrRoleScope where
t_sUsrRoleScope.tc_ParentRowid = t_sUsrRole.tc_Rowid and
t_sUsrRoleScope.tc_Status <> "D":U)
then do :
assign vcMessage = trim(substitute(#T-9'Role scope values can only be defined on user roles where the role scope class of the role is defined (role: &1, user: &2).':255(539)T-9#,t_sUsrRole.tcRoleName,t_sUsrRole.tcUsrLogin)).
assign oiReturnStatus = -1.
<M-26 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input 'tRole.tcBusComponentLabel':U (icFieldName),
input tqRoleByNameActiveDescr.tcBusComponentLabel (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sUsrRole.tc_Rowid (icRowid),
input 'BLF-242':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BUserRole>
end. /* if can-find */
end. /* for each t_sUsrRole */
for each t_sUsrRole where
t_sUsrRole.tc_Status <> "D":U :
<Q-31 run RoleByNameActiveDescr (all) (Read) (NoCache) (input ?, (RoleDescription)
input ?, (RoleIsActive)
input t_sUsrRole.tcRoleName, (RoleName)
output dataset tqRoleByNameActiveDescr) in BRole >
Find First tqRoleByNameActiveDescr No-error.
If Available tqRoleByNameActiveDescr And
tqRoleByNameActiveDescr.tiBusComponent_ID <> 0 And
tqRoleByNameActiveDescr.tiBusComponent_ID <> ? And
Not can-find (first t_sUsrRoleScope where
t_sUsrRoleScope.tc_ParentRowid = t_sUsrRole.tc_Rowid and
t_sUsrRoleScope.tc_Status <> "D":U)
then do :
assign vcMessage = trim(substitute(#T-30'At least one role scope value must be specified for roles with a role scope class (role: &1).':255(540)T-30#,t_sUsrRole.tcRoleName))
oiReturnStatus = -1.
<M-29 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input 'tRole.tcBusComponentLabel':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sUsrRole.tc_Rowid (icRowid),
input 'BLF-243':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BUserRole>
end. /* if can find */
end. /* for each t_sUsrRole */