/// <summary>
    /// Processes the specified file.
    /// </summary>
    /// <param name="fileGuid">File guid</param>
    protected void ProcessFile(Guid fileGuid)
    {
        // Get the file
        ForumAttachmentInfo fileInfo = ForumAttachmentInfoProvider.GetForumAttachmentInfoWithoutBinary(fileGuid, CMSContext.CurrentSiteName);

        if (fileInfo != null)
        {
            #region "Security"

            // Indicates whether current user is granted to see this attachment
            bool attachmentAllowed = false;

            // Get forum
            ForumInfo fi = ForumInfoProvider.GetForumInfo(fileInfo.AttachmentForumID);
            if (fi != null)
            {
                // Check acess
                if (ForumViewer.CheckPermission("AccessToForum", SecurityHelper.GetSecurityAccessEnum(fi.ForumAccess, 6), fi.ForumGroupID, fi.ForumID))
                {
                    attachmentAllowed = true;
                }
            }

            // If attachment is not allowed for current user, redirect to the access denied page
            if (!attachmentAllowed)
            {
                URLHelper.Redirect(URLRewriter.AccessDeniedPageURL(CurrentSiteName));
            }

            #endregion


            bool resizeImage = (ImageHelper.IsMimeImage(fileInfo.AttachmentMimeType) &&
                                ForumAttachmentInfoProvider.CanResizeImage(fileInfo, Width, Height, MaxSideSize));

            // Get the data
            if ((outputFile == null) || (outputFile.ForumAttachment == null))
            {
                outputFile             = new CMSOutputForumAttachment(fileInfo, fileInfo.AttachmentBinary);
                outputFile.Width       = Width;
                outputFile.Height      = Height;
                outputFile.MaxSideSize = MaxSideSize;
                outputFile.Resized     = resizeImage;
            }
        }
    }
    /// <summary>
    /// Processes the file.
    /// </summary>
    protected void ProcessFile()
    {
        if (fileGuid == Guid.Empty)
        {
            return;
        }

        // Get the file
        ForumAttachmentInfo fileInfo = ForumAttachmentInfoProvider.GetForumAttachmentInfoWithoutBinary(fileGuid, SiteContext.CurrentSiteName);

        if (fileInfo == null)
        {
            return;
        }

        // Check forum access
        var forum = ForumInfoProvider.GetForumInfo(fileInfo.AttachmentForumID);

        if ((forum == null) || !ForumViewer.CheckPermission("AccessToForum", SecurityHelper.GetSecurityAccessEnum(forum.ForumAccess, 6), forum.ForumGroupID, forum.ForumID, CurrentUser))
        {
            // If attachment is not allowed for current user, redirect to the access denied page
            URLHelper.Redirect(PageSecurityHelper.AccessDeniedPageURL(CurrentSiteName));
        }

        bool resizeImage = (ImageHelper.IsMimeImage(fileInfo.AttachmentMimeType) && ForumAttachmentInfoProvider.CanResizeImage(fileInfo, Width, Height, MaxSideSize));

        // Get the data
        if ((outputFile == null) || (outputFile.ForumAttachment == null))
        {
            outputFile             = new CMSOutputForumAttachment(fileInfo, fileInfo.AttachmentBinary);
            outputFile.Width       = Width;
            outputFile.Height      = Height;
            outputFile.MaxSideSize = MaxSideSize;
            outputFile.Resized     = resizeImage;
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Check permissions.
    /// </summary>
    /// <param name="state">Current state</param>
    public ForumStateEnum CheckPermissions(ForumStateEnum state)
    {
        // Return original state for selected types
        if ((state == ForumStateEnum.Forums) || (state == ForumStateEnum.Unknown) || (state == ForumStateEnum.Search))
        {
            return(state);
        }

        // If forum doesn't exist display default
        if (ForumContext.CurrentForum == null)
        {
            return(ForumStateEnum.Forums);
        }

        // If forum is closed => hide
        if ((!IsAdHocForum) && (!ForumContext.CurrentForum.ForumOpen))
        {
            return(ForumStateEnum.Forums);
        }

        // Sets threads state for every action if forum is locked
        if (ForumContext.CurrentForum.ForumIsLocked)
        {
            switch (state)
            {
            case ForumStateEnum.NewSubscription:
            case ForumStateEnum.NewThread:
            case ForumStateEnum.ReplyToPost:
            case ForumStateEnum.SubscribeToPost:
            case ForumStateEnum.Attachments:
                return(ForumStateEnum.Threads);
            }
        }

        // If user is global admin, forum admin, community admin or modrator
        if (ForumContext.UserIsModerator(ForumContext.CurrentForum.ForumID, this.CommunityGroupID))
        {
            return(state);
        }

        // Sets thread state for locked post
        if ((ForumContext.CurrentThread != null) && (ForumContext.CurrentThread.PostIsLocked))
        {
            if (!ForumContext.UserIsModerator(ForumContext.CurrentForum.ForumID, this.CommunityGroupID))
            {
                switch (state)
                {
                case ForumStateEnum.NewSubscription:
                case ForumStateEnum.SubscribeToPost:
                case ForumStateEnum.NewThread:
                case ForumStateEnum.ReplyToPost:
                case ForumStateEnum.Attachments:
                    return(ForumStateEnum.Thread);
                }
            }
        }

        bool hasPermissions = true;

        // Check permissions for action
        switch (state)
        {
        case ForumStateEnum.ReplyToPost:
            hasPermissions = ForumViewer.CheckPermission("Reply", ForumContext.CurrentForum.AllowReply, ForumContext.CurrentForum.ForumGroupID, ForumContext.CurrentForum.ForumID);
            break;

        case ForumStateEnum.NewThread:
            hasPermissions = ForumViewer.CheckPermission("Post", ForumContext.CurrentForum.AllowPost, ForumContext.CurrentForum.ForumGroupID, ForumContext.CurrentForum.ForumID);
            break;

        case ForumStateEnum.Attachments:
            hasPermissions = ForumViewer.CheckPermission("AttachFiles", ForumContext.CurrentForum.AllowAttachFiles, ForumContext.CurrentForum.ForumGroupID, ForumContext.CurrentForum.ForumID);
            break;

        case ForumStateEnum.TopicMove:
            hasPermissions = ForumContext.UserIsModerator(ForumContext.CurrentForum.ForumID, this.CommunityGroupID);
            break;

        case ForumStateEnum.SubscribeToPost:
        case ForumStateEnum.NewSubscription:
            hasPermissions = ForumViewer.CheckPermission("Subscribe", ForumContext.CurrentForum.AllowSubscribe, ForumContext.CurrentForum.ForumGroupID, ForumContext.CurrentForum.ForumID) && this.EnableSubscription;
            break;

        case ForumStateEnum.EditPost:
            hasPermissions = ForumContext.UserIsModerator(ForumContext.CurrentForum.ForumID, this.CommunityGroupID) || (ForumContext.CurrentForum.ForumAuthorEdit && (ForumContext.CurrentPost != null && !CMSContext.CurrentUser.IsPublic() && (ForumContext.CurrentPost.PostUserID == CMSContext.CurrentUser.UserID)));
            break;
        }

        // Check ForumAccess permission
        if (ForumContext.CurrentForum != null)
        {
            hasPermissions = hasPermissions && ForumViewer.CheckPermission("AccessToForum", ForumContext.CurrentForum.AllowAccess, ForumContext.CurrentForum.ForumGroupID, ForumContext.CurrentForum.ForumID);
        }

        // Check whether user has permissions for selected state
        if (!hasPermissions)
        {
            // Check whether public user should be redirected to logon page
            if (this.RedirectUnauthorized && CMSContext.CurrentUser.IsPublic())
            {
                URLHelper.Redirect(URLHelper.AddParameterToUrl(ResolveUrl(this.LogonPageURL), "returnurl", HttpUtility.UrlEncode(URLHelper.CurrentURL)));
            }
            else if (!String.IsNullOrEmpty(this.AccessDeniedPageURL))
            {
                URLHelper.Redirect(URLHelper.AddParameterToUrl(ResolveUrl(this.AccessDeniedPageURL), "returnurl", HttpUtility.UrlEncode(URLHelper.CurrentURL)));
            }
            // Sets state with dependence on current settings
            else
            {
                if (startingMode == 0)
                {
                    return(ForumStateEnum.Forums);
                }
                else
                {
                    return(ForumStateEnum.AccessDenied);
                }
            }
        }

        return(state);
    }