Rank: Member Groups: Member
Joined: 7/29/2011 Posts: 14
|
This is not a problem, but a solution to a problem that I had that I thought others might want for reference.
Issue: I have a treeview populated via an xml file that shows the entire menuing. I have parent-node 'groups' like reports, but under it, I might have several sub-group childnodes that I want to display or not depending on the users login role(s).
Say a person has two roles: ahsaa, officials. Both have reporting needs, but they may not be inclusive. ahsaa role might be the parent-parent role that has everything displayed, but it makes/made no sense to duplicate menu options multiple times siply due to that issue.
So, xmlfile section:
<folder name="Reports" id="Reports"> <folder name="AHSAA" id="AHSAA"> <demo name="Sports Clinic"></demo> </folder> <folder name="Officials" id="Officials"> <demo name="Sports Clinic"></demo> </folder> <folder name="Coaches" id="Coaches"> <demo name="Sports Clinic"></demo> </folder> </folder>
Has parent of 'Reports' and several childnodes (ahsaa, officials, coaches)
In my situation, if I do nothing all three childnodes are displayed. However, the reports avaialble to the official might not be valid for the coaches, whom are sub-set of officials in certain functions. So, in order to display officials reporting needs, but not display coaches, the code I found that worked is:
If Roles.IsUserInRole(memUser.UserName.ToString, "REPORTS_OFFICIALS") Then For Each node2 As EO.Web.TreeNode In tvOption.Nodes If node2.Text = "Reports" Then tvOption.Nodes(node2.Index).Visible = True
'get childnodes and filter based on roles type For Each cnode As EO.Web.TreeNode In node2.ChildNodes
' we need to check to see if user also has report roles for other sections, like Officials, Coaches, etc.
'Role - AHSAA If Not Roles.IsUserInRole(memUser.UserName.ToString, "REPORTS_AHSAA") Then 'user not in AHSAA role, so remove If node2.ChildNodes.Item(cnode.Index).Text = "AHSAA" Then node2.ChildNodes.Item(cnode.Index).Visible = False End If End If
'Role - Coaches If Not Roles.IsUserInRole(memUser.UserName.ToString, "REPORTS_COACHES") Then ' user not in Coaches role, so remove If node2.ChildNodes.Item(cnode.Index).Text = "Coaches" Then node2.ChildNodes.Item(cnode.Index).Visible = False End If End If Next Exit For End If Next End If End If
so, based on this, I can have a user in multiple 'report' roles, and then check on design time what if anything I need to display/not. Yes, I know there is somewhat duplication on checking if user is in other roles for the 'parent role', but unless I limit them to a single report-role, the sysadmin type could check multiple checkboxes that represent roles.
Anyway, thought I throw this out in case anyone was having similar 'concept' issues like I did/had until Jack put me on the right path (e.g., figure it out yourself!!! and look at examples in code/forum). Really Jack, thanks. your comments helped me think clearer on functionality vs.coding.
|