Ian Houghton
02/05/2025, 9:41 AMpublic bool IsEngineer(string objectIdentifier)
{
var member = _memberService.GetByUsername(objectIdentifier);
if (member != null)
{
return _memberService.GetAllRoles(objectIdentifier).Any(r => r.Equals(Constants.MemberGroups.Engineer));
}
return false;
}
looking at the Umbraco source code, this seems to be hitting the database everytime, so I'm thinking this is the wrong way of doing it? Ideas?Matt Wise
02/05/2025, 9:52 AMMatt Wise
02/05/2025, 9:52 AMAmbert
02/05/2025, 9:52 AMawait memberManager.GetCurrentMemberAsync();
Ambert
02/05/2025, 9:55 AMvar member = await memberManager.GetCurrentMemberAsync();
returns a MemberIdentityUser, but member.Roles contains no Roles...
So you need to use
var memberGroups = await memberManager.GetRolesAsync(member);
but this gets a list of string
. No objects with a name and an ID
So if you somewhere else use a memberGroup picker, that value is stored as an Id
.. So you then need to get
var memberGroups = memberGroupService.GetByIds(memberGroupsIds).Select(group => group.Name);
to match them again xDMatt Wise
02/05/2025, 9:57 AMMatt Wise
02/05/2025, 9:58 AMAmbert
02/05/2025, 9:59 AMIan Houghton
02/05/2025, 10:42 AM