/// <summary>
/// To check if user can get access to the Parameter form
/// </summary>
class SAN_ParamFormsAccessCtrl
{
protected void new()
{
super();
}
static SAN_ParamFormsAccessCtrl construct()
{
return new SAN_ParamFormsAccessCtrl();
}
public boolean validateUserRoleAccess()
{
#characters
UserId userId = curUserId();
container tmpValues;
SecurityRole securityRole;
SecurityUserRole securityUserRole;
int idx;
boolean isValidated = false;
Str secRoleList;
//Created new custom parameter to have which roles alone should have EDIT access, apart from this any roles would have only READ access even System admin
secRoleList = SAN_IntegrationParameters::find().ParametersAccessSecurityRole;
if(secRoleList)
{
tmpValues = str2con(secRoleList, #semicolon);
for(idx=1; idx<=conLen(tmpValues); idx++)
{
securityRole.clear();
select firstonly securityRole
where securityRole.Name == conPeek(tmpValues, idx);
if(securityRole.RecId && !isValidated)
{
securityUserRole.clear();
select firstonly RecId from securityUserRole
where securityUserRole.User == userId
&& securityUserRole.SecurityRole == securityRole.RecId;
if (securityUserRole.RecId)
{
isValidated = true;
}
}
}
}
return isValidated;
}
public void disableFormDataSources(FormRun _callingForm)
{
FormBuildDataSource frmBuildDS;
int i;
for(i = 1; i<= _callingForm.form().dataSourceCount(); i++)
{
frmBuildDS = _callingForm.form().dataSource(i);
frmBuildDS.allowEdit(false);
}
}
public boolean checkRoleCtrlAccess(FormRun _callingForm)
{
boolean userHasAccess = this.validateUserRoleAccess();
if(!userHasAccess)
{
this.disableFormDataSources(_callingForm);
}
return userHasAccess;
}
}
[ExtensionOf(formStr(LedgerParameters))]
final class LedgerParametersFrm_SAN_Extension
{
public void init()
{
next init();
SAN_ParamFormsAccessCtrl paramFormsAccessCtrl;
paramFormsAccessCtrl = SAN_ParamFormsAccessCtrl::construct();
if(!paramFormsAccessCtrl.checkRoleCtrlAccess(this))
{
this.san_lockControls();
}
}
void san_lockControls()
{
FormBuildControl formBuildControl;
int i;
for (i=1;i<=this.form().design().controlCount(); i++)
{
formBuildControl = this.form().design().controlNum(i);
this.control(formBuildControl.id()).enabled(false);
}
}
}
No comments:
Post a Comment