using System;
using System.Data;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CMS.CMSHelper;
using CMS.Forums;
using CMS.GlobalHelper;
using CMS.LicenseProvider;
using CMS.SettingsProvider;
using CMS.SiteProvider;
using CMS.UIControls;
public partial class CMSModules_Groups_CMSPages_LiveForumPostApprove : CMSLiveModalPage
{
#region "Variables"
private int postId = 0;
private int groupId = 0;
#endregion
#region "Page events"
///
/// Page OnInit event.
///
/// Event args
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
// Check forums availability
if (!ResourceSiteInfoProvider.IsResourceOnSite("CMS.Forums", CMSContext.CurrentSiteName))
{
RedirectToResourceNotAvailableOnSite("CMS.Forums");
}
// Check groups availability
if (!ResourceSiteInfoProvider.IsResourceOnSite("CMS.Groups", CMSContext.CurrentSiteName))
{
RedirectToResourceNotAvailableOnSite("CMS.Groups");
}
// Check the license
if (DataHelper.GetNotEmpty(URLHelper.GetCurrentDomain(), "") != "")
{
LicenseHelper.CheckFeatureAndRedirect(URLHelper.GetCurrentDomain(), FeatureEnum.Groups);
}
}
///
/// Handles the Load event of the Page control.
///
protected void Page_Load(object sender, EventArgs e)
{
// Get postId, groupId
postId = QueryHelper.GetInteger("postid", 0);
groupId = 0;
ForumPostInfo fpi = ForumPostInfoProvider.GetForumPostInfo(postId);
if (fpi != null)
{
ForumInfo fi = ForumInfoProvider.GetForumInfo(fpi.PostForumID);
if (fi != null)
{
ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(fi.ForumGroupID);
if (fgi != null)
{
groupId = fgi.GroupGroupID;
}
}
}
// Check permissions
CheckGroupPermissions(groupId, "Read");
if (groupId > 0)
{
// Set the post ID
PostApprove.PostID = postId;
PostApproveFooter.PostID = postId;
// Set methods which check the permissions
PostApprove.OnCheckPermissions += new CMSAdminControl.CheckPermissionsEventHandler(PostApprove_OnCheckPermissions);
PostApproveFooter.OnCheckPermissions += new CMSAdminControl.CheckPermissionsEventHandler(PostApprove_OnCheckPermissions);
// Page title
CurrentMaster.Title.TitleText = GetString("forums_forumnewpost_header.preview");
CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Forums_ForumPost/object.png");
}
}
///
/// Check whether user is group administrator or has manage permission.
///
/// Comunnity group ID
/// Permission name
protected void PostApprove_OnCheckPermissions(string permissionType, CMSAdminControl sender)
{
if (permissionType.EqualsCSafe("modify", true))
{
permissionType = "Manage";
}
// Check permissions
CheckGroupPermissions(groupId, permissionType);
}
///
/// Check whether user is group administrator or has manage permission.
///
/// Comunnity group ID
/// Permission name
private static void CheckGroupPermissions(int groupId, string permissionName)
{
// Get current group
GeneralizedInfo group = ModuleCommands.CommunityGetGroupInfo(groupId);
if (group != null)
{
// Check if group is placed on current site
int groupSiteID = ValidationHelper.GetInteger(group.GetProperty("GroupSiteID"), 0);
if (groupSiteID != CMSContext.CurrentSiteID)
{
RedirectToAccessDenied(CMSDESK_ACCESSDENIED, null, null, null, ResHelper.GetString("community.group.notassigned"));
}
}
if (!CMSContext.CurrentUser.IsGroupAdministrator(groupId))
{
// Check permissions
if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Groups", permissionName))
{
RedirectToCMSDeskAccessDenied("CMS.Groups", permissionName);
}
}
}
#endregion
}