/// <summary> /// Returns true if the contact is in any/all of the specified community groups (i.e. if any of the user assigned to the contact is in any/all specified community groups). /// </summary> /// <param name="contact">Contact which should be checked</param> /// <param name="groupNames">Name of the groups separated with semicolon</param> /// <param name="allGroups">If true, contact has to in all specified groups. If false, it is sufficient if the contact is at least in one of the groups.</param> public static bool IsInCommunityGroup(object contact, string groupNames, bool allGroups) { ContactInfo ci = contact as ContactInfo; if (ci == null) { return(false); } if (!string.IsNullOrEmpty(groupNames)) { string[] groups = groupNames.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string groupName in groups) { bool isInGroup = false; foreach (UserInfo user in ci.Users) { BaseInfo group = ModuleCommands.CommunityGetGroupInfoByName(groupName, CMSContext.CurrentSiteName); if (group != null) { isInGroup = ModuleCommands.CommunityIsMemberOfGroup(user.UserID, group.Generalized.ObjectID); if (isInGroup && !allGroups) { // In role and it is sufficient if at least one matches => true return(true); } } } if (!isInGroup && allGroups) { // Not in role, but should be in all roles return(false); } } } if (allGroups) { // It means either no roles were specified or contact is in all roles return(true); } else { return(false); } }
/// <summary> /// Initializes control properties. /// </summary> protected void SetupControl() { if (StopProcessing) { // Do nothing } else { srcPosts.SiteName = SiteName; srcPosts.ForumName = ForumName; srcPosts.WhereCondition = WhereCondition; srcPosts.OrderBy = OrderBy; srcPosts.TopN = SelectTopN; srcPosts.FilterName = ValidationHelper.GetString(GetValue("WebPartControlID"), ID); srcPosts.SourceFilterName = FilterName; srcPosts.CacheItemName = CacheItemName; srcPosts.CacheDependencies = CacheDependencies; srcPosts.CacheMinutes = CacheMinutes; srcPosts.SelectOnlyApproved = SelectOnlyApproved; srcPosts.CheckPermissions = CheckPermissions; srcPosts.SelectedColumns = Columns; srcPosts.ShowGroupPosts = ShowGroupPosts && String.IsNullOrEmpty(ForumName); // Set data source groupid according to group name if (!String.IsNullOrEmpty(GroupName)) { if (GroupName == PredefinedObjectType.COMMUNITY_CURRENT_GROUP) { srcPosts.GroupID = ModuleCommands.CommunityGetCurrentGroupID(); } else { GeneralizedInfo gi = ModuleCommands.CommunityGetGroupInfoByName(GroupName, SiteName); if (gi != null) { srcPosts.GroupID = ValidationHelper.GetInteger(gi.GetValue("GroupID"), 0); } else { srcPosts.StopProcessing = true; } } } } }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (this.StopProcessing) { // Do nothing } else { if (!String.IsNullOrEmpty(this.TransformationName)) { this.repMostActiveThread.ItemTemplate = CMSDataProperties.LoadTransformation(this, this.TransformationName, false); this.repMostActiveThread.HideControlForZeroRows = this.HideControlForZeroRows; this.repMostActiveThread.ZeroRowsText = this.ZeroRowsText; // Set data source groupid according to group name if (!String.IsNullOrEmpty(this.GroupName)) { if (this.GroupName == CMSConstants.COMMUNITY_CURRENT_GROUP) { this.forumDataSource.GroupID = ModuleCommands.CommunityGetCurrentGroupID(); } else { GeneralizedInfo gi = ModuleCommands.CommunityGetGroupInfoByName(this.GroupName, this.SiteName); if (gi != null) { this.forumDataSource.GroupID = ValidationHelper.GetInteger(gi.GetValue("GroupID"), 0); } else { forumDataSource.StopProcessing = true; } } } if (!forumDataSource.StopProcessing) { this.forumDataSource.TopN = this.SelectTopN; this.forumDataSource.OrderBy = "PostThreadPosts DESC"; this.forumDataSource.CacheItemName = this.CacheItemName; this.forumDataSource.CacheDependencies = this.CacheDependencies; this.forumDataSource.CacheMinutes = this.CacheMinutes; this.forumDataSource.FilterName = ValidationHelper.GetString(this.GetValue("WebPartControlID"), this.ClientID); this.forumDataSource.SelectOnlyApproved = false; this.forumDataSource.SiteName = this.SiteName; this.forumDataSource.ShowGroupPosts = this.ShowGroupPosts && String.IsNullOrEmpty(ForumGroups); #region "Complete where condition" string where = ""; // Get groups part of where condition string[] groups = this.ForumGroups.Split(';'); foreach (string group in groups) { if (group != "") { if (where != "") { where += " OR "; } where += "(GroupName = N'" + SqlHelperClass.GetSafeQueryString(group, false) + "')"; } } where = "(" + (where == "" ? "(GroupName NOT LIKE 'AdHoc%')" : "(" + where + ")") + " AND (PostLevel = 0))"; // Append where condition and set PostLevel to 0 (only threads are needed) // and filter out AdHoc forums if (!String.IsNullOrEmpty(this.WhereCondition)) { where += " AND (" + this.WhereCondition + ")"; } #endregion this.forumDataSource.WhereCondition = where; this.forumDataSource.CheckPermissions = true; this.repMostActiveThread.DataSource = this.forumDataSource.DataSource; if (!DataHelper.DataSourceIsEmpty(this.repMostActiveThread.DataSource)) { this.repMostActiveThread.DataBind(); } } } } }