Page 1 of 1

current user Group assignments

Posted: Thu Jan 07, 2016 6:52 pm
by sfeher
Trying to find the appropriate reference for updating the navigation elements.
We want to allow some menu items to display only for specific group members, but I'm unsure how to call the current users' group membership in the code.

Seems like the AbleContext.Current.User should contain the GroupId, but efforts to call this continually fail.

The Admin link in the navigation simply calls the visibility based on the following code in StoreHeader.ascx:

Code: Select all

 AdminLink.Visible = AbleContext.Current.User.IsAdmin;
I'd like to make other menu items comply with similar code

Code: Select all

 GroupLink.Visible = AbleContext.Current.User.GroupId = 14;
Any recommendations?

Thanks!

Re: current user Group assignments

Posted: Thu Jan 07, 2016 11:23 pm
by jmestep
You can use a variation of
if (user.IsInGroup(14))

Re: current user Group assignments

Posted: Fri Jan 08, 2016 4:08 am
by sfeher
Thanks Judy ---
I couldn't see the "IsInGroup" property and wasn't sure how to use it.
I appreciate the response!

Final code for those working on this:

Code: Select all

ForGroupsOnlyLink.Visible = AbleContext.Current.User.IsInGroup(X);
Where "ForGroupsOnly" is the ID and X is your group ID number.....

Works like a champ.

Re: current user Group assignments

Posted: Fri Jan 08, 2016 4:08 am
by sfeher
Thanks Judy ---
I couldn't see the "IsInGroup" property and wasn't sure how to use it.
I appreciate the response!

Final code for those working on this:

Code: Select all

ForGroupsOnlyLink.Visible = AbleContext.Current.User.IsInGroup(X);
Where "ForGroupsOnly" is the ID and X is your group ID number.....

Works like a champ.