This commit is contained in:
2022-03-04 18:15:23 +00:00
parent 122056a9da
commit 362aa31e15
68 changed files with 1163 additions and 761 deletions
@@ -129,73 +129,52 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
}
private OrganisationData GetOrganisationForFilter(SysId filterOrganisationId, String filterOrganisationCaption, Sax.OrganisationRole organisationRole)
{
// Check that user is associated with organisations.
SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params();
prmUserOrganisation.UserAccountIdsIncluded.Add(UserAccountId);
prmUserOrganisation.OrganisationStatusCat = SaxOrganisation.StatusCat.ActiveOnly;
prmUserOrganisation.StatusCat = SaxUserOrganisation.StatusCat.ActiveOnly;
if (AccountMgr.GetUserOrganisationCount(prmUserOrganisation) < 1)
return null;
OrganisationData organisationData = null;
// Roles (any) required for organisation list.
List<Sax.OrganisationRole> requiredRoles = new List<Sax.OrganisationRole>() { Sax.OrganisationRole.Admin };
List <Sax.OrganisationRole> requiredRoles = new List<Sax.OrganisationRole>() { Sax.OrganisationRole.Admin };
if (organisationRole > 0)
requiredRoles.Add(organisationRole);
// Retrieve specified organisation.
OrganisationData organisationData = null;
// Filter to identify suitable organisations that user is a member of and has the appropriate rights.
SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params();
prmUserOrganisation.UserAccountIdsIncluded.Add(UserAccountId);
prmUserOrganisation.OrganisationStatusCat = SaxOrganisation.StatusCat.ActiveOnly;
prmUserOrganisation.OrganisationMembersOnly = true;
prmUserOrganisation.OrganisationRolesAny.AddRange(requiredRoles);
prmUserOrganisation.StatusCat = SaxUserOrganisation.StatusCat.ActiveOnly;
// Restrict to specified Organisation.
if (SysId.IsValid(filterOrganisationId))
{
organisationData = new OrganisationData(filterOrganisationId) { Caption = filterOrganisationCaption };
using (SaxOrganisation organisation = AccountMgr.GetOrganisationById(organisationData.Id))
{
// Validate organisation.
if (organisation != null && organisation.IsStatusActive && AccountMgr.UserHasAnyOrganisationRole(UserAccountId, organisation.Id, requiredRoles))
organisationData.Caption = organisation.Name;
else
organisationData = null;
}
// Verify that the specified organisation is valid for the filter conditions.
prmUserOrganisation.OrganisationIdsIncluded.Add(filterOrganisationId);
if (AccountMgr.GetUserOrganisationCount(prmUserOrganisation) < 1)
// Specified organisation is not valid - remove restriction.
prmUserOrganisation.OrganisationIdsIncluded.Clear();
}
if (organisationData == null)
// Pick the first valid Organisation.
ColumnDfn colOrganisationId = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.OrganisationId);
ColumnDfn colOrganisationName = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Name);
prmUserOrganisation.SortColumns.Add(colOrganisationName);
prmUserOrganisation.ResultsPaging.PageLength = 1;
prmUserOrganisation.ResultsPaging.PageNo = 1;
using (DbResultSet resultSet = AccountMgr.ExecuteUserOrganisationQuery(new List<ColumnDfn>() { colOrganisationId, colOrganisationName }, prmUserOrganisation))
{
// Pick the first valid Organisation that the user is a member of.
ColumnDfn colOrganisationId = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.OrganisationId);
ColumnDfn colOrganisationName = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Name);
prmUserOrganisation = new SaxUserOrganisation.Params();
prmUserOrganisation.UserAccountIdsIncluded.Add(UserAccountId);
if (organisationData != null && SysId.IsValid(organisationData.Id))
prmUserOrganisation.OrganisationIdsIncluded.Add(organisationData.Id);
prmUserOrganisation.OrganisationStatusCat = SaxOrganisation.StatusCat.ActiveOnly;
prmUserOrganisation.OrganisationMembersOnly = true;
prmUserOrganisation.StatusCat = SaxUserOrganisation.StatusCat.ActiveOnly;
prmUserOrganisation.SortColumns.Add(colOrganisationName);
prmUserOrganisation.ResultsPaging.PageLength = 1;
prmUserOrganisation.ResultsPaging.PageNo = 1;
using (DbResultSet resultSet = AccountMgr.ExecuteUserOrganisationQuery(new List<ColumnDfn>() { colOrganisationId, colOrganisationName }, prmUserOrganisation))
if (resultSet != null && resultSet.HasRows && resultSet.NextRecord())
{
while (resultSet != null && resultSet.HasRows && resultSet.NextRecord())
NamedValue.Map values = resultSet.GetRecordValues();
SysId organisationId = new SysId(values.GetLong(colOrganisationId.DataName));
if (SysId.IsValid(organisationId))
{
NamedValue.Map values = resultSet.GetRecordValues();
SysId organisationId = new SysId(values.GetLong(colOrganisationId.DataName));
if (SysId.IsValid(organisationId))
organisationData = new OrganisationData(organisationId)
{
organisationData = new OrganisationData(organisationId);
organisationData.Caption = values.GetString(colOrganisationName.DataName);
break;
}
Caption = values.GetString(colOrganisationName.DataName)
};
}
}
}
if (SysId.IsValid(organisationData.Id) && StringUtil.IsEmpty(organisationData.Caption))
{
// Organisation has been identified but no caption available as yet.
using (SaxOrganisation organisation = AccountMgr.GetOrganisationById(organisationData.Id))
{
if (organisation != null)
organisationData.Caption = organisation.Name;
}
}
return organisationData;
}