/// <summary> /// Checks if the user is a member of the given group or is a member /// of a group that has higher priviliges than the given group. /// </summary> /// <param name="p">The principal</param> /// <param name="groupid">The group</param> /// <returns>If the user is a member</returns> public static bool IsMember(this IPrincipal p, Guid groupid) { if (Piranha.Application.Current.UserProvider.IsAuthenticated) { if (groupid != Guid.Empty) { SysGroup g = SysGroup.GetStructure().GetGroupById(p.GetProfile().GroupId) ; return g.Id == groupid || g.HasChild(groupid) ; } return true ; } return false ; }
/// <summary> /// Checks if the current user has access to the function. /// </summary> /// <param name="p">The principal</param> /// <param name="function">The function to check</param> /// <returns>If the user has access</returns> public static bool HasAccess(this IPrincipal p, string function) { if (Piranha.Application.Current.UserProvider.IsAuthenticated) { Dictionary<string, SysAccess> access = SysAccess.GetAccessList() ; if (access.ContainsKey(function)) { SysGroup group = SysGroup.GetStructure().GetGroupById(p.GetProfile().GroupId) ; return group != null && (group.Id == access[function].GroupId || group.HasChild(access[function].GroupId)) ; } } return false ; }
/// <summary> /// Checks if the user is a member of the given group or is a member /// of a group that has higher priviliges than the given group. /// </summary> /// <param name="p">The principal</param> /// <param name="groupid">The group</param> /// <returns>Weather the user is a member</returns> public static bool IsMember(this IPrincipal p, Guid groupid) { if (p.Identity.IsAuthenticated) { if (groupid != Guid.Empty) { SysGroup g = SysGroup.GetStructure().GetGroupById(p.GetProfile().GroupId); return(g.Id == groupid || g.HasChild(groupid)); } return(true); } return(false); }