Filter GroupList Based on Permissions of a Role

In a past project i was asked to build a Grouplist like widget for Community Server. This Grouplist widget was different from the existing because the data should be filtered by the permissions of a role (in my case Members). i have searched for a standard way to do this with the existing controls but eventually i had to write my own  <CSControl:CustomCondition />. i implemented the widget as follows (staying closely to the existing widget implementation in CS 5.5).

<%@ Control Language=”C#” AutoEventWireup=”true” %>

<%@ Import Namespace=”System.Collections.Generic” %>
<%@ Import Namespace=”System.Collections.ObjectModel” %>

<script runat=”server” language=”C#”>

    public bool IsApproved(CommunityServer.Components.Group group)
     CommunityServer.Components.ISecurityService securityService = Telligent.Common.Services.Get<CommunityServer.Components.ISecurityService>();
     CommunityServer.Components.IRoleService roleService = Telligent.Common.Services.Get<CommunityServer.Components.IRoleService>();

        IEnumerable<CommunityServer.Components.Role> roles = roleService.GetRolesForGroup(group.ID);
     CommunityServer.Components.Role member = null;
     foreach(CommunityServer.Components.Role role in roles)
      if(role.Name == “Members”)
       member = role;
     if(member != null)
      CommunityServer.Components.PermissionList p = securityService.GetImmediatePermissions(group.NodeId);
      foreach(CommunityServer.Components.PermissionEntry m in p)
       if(m.Name == “Community – Create New Communities” && m.RoleId == member.Id && m.IsAllowed)
        return true;
        return false;

<CSControl:GroupData runat=”server” CssClass=”content-item simple” Tag=”Li”>
 <DisplayConditions Operator=”And”>
     CustomResult=”<%# IsApproved(CSControlUtility.Instance().GetCurrentGroup(Container)) %>” 
     runat=”server” />
        <CSControl:GroupData runat=”server” 
           LinkTo=”HomePage” />



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: