⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 weblogpermission.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using CommunityServer.Components;

namespace CommunityServer.Blogs.Components
{
	/// <summary>
	/// Summary description for BlogPermission.
	/// </summary>
	public class WeblogPermission : PermissionBase
	{
		public WeblogPermission()
		{
		}

        #region Public Properties
        /// <summary>
        /// Can the current User View the Blog
        /// </summary>
        public virtual bool View 
        {
            get{ return GetBit( Permission.View ); }
        }

        /// <summary>
        /// Can the current User edit the Blogs Content
        /// </summary>
        public virtual bool Post 
        {
            get{ return GetBit( Permission.Post ); }
        }

        /// <summary>
        /// Can the current User post comments
        /// </summary>
        public virtual bool Reply 
        {
            get{ return GetBit( Permission.Reply ); }
        }

        /// <summary>
        /// Can the current User add attachments to posts
        /// </summary>
        public virtual bool Attachment 
        {
            get{ return GetBit( Permission.Attachment ); }
        }

        /// <summary>
        /// Can the current User administer their own blog settings
        /// </summary>
        public virtual bool Administer 
        {
            get{ return GetBit( Permission.Administer ); }
        }

        /// <summary>
        /// Can the current User mark posts as sticky
        /// </summary>
        public virtual bool Sticky 
        {
            get{ return GetBit( Permission.Sticky ); }
        }

        /// <summary>
        /// Can the current User/Role delete posts
        /// </summary>
        public virtual bool Delete 
        {
            get{ return GetBit( Permission.Delete ); }
        }
        #endregion

        #region Validate
        public static bool Validate(Section section, Permission permission, User user, Post p)
        {

			if(user.IsBlogAdministrator)
				return true;

            if(section == null || section.PermissionSet == null || user == null )
                return false;

            bool bReturn = true;
            WeblogPermission fpFinal = section.ResolvePermission(user) as WeblogPermission;

            if((permission == (permission | Permission.Administer)) && bReturn )
                bReturn &= fpFinal.Administer;

            if((permission == (permission | Permission.Attachment)) && bReturn )
                bReturn &= fpFinal.Attachment;

            if((permission == (permission | Permission.Delete)) && bReturn ) 
                bReturn &= fpFinal.Delete;

            if((permission == (permission | Permission.Post)) && bReturn )
                bReturn &= fpFinal.Post;

            if((permission == (permission | Permission.Reply)) && bReturn )
                bReturn &= fpFinal.Reply;

            if((permission == (permission | Permission.Sticky)) && bReturn )
                bReturn &= fpFinal.Sticky;

            if((permission == (permission | Permission.View)) && bReturn )
                bReturn &= fpFinal.View;

            return bReturn;
        }
        #endregion

        #region AccessCheck
        public static void AccessCheck(Section section, Permission permission, User user, Post post)
        {
            if (user.IsBlogAdministrator)
                return;

                        CSContext csContext = CSContext.Current;

            WeblogPermission fp = section.ResolvePermission( user ) as WeblogPermission;
            long lValue = (long)permission;
            switch (lValue) 
            {
//                 case (long)Permission.Attachment:
//                    // TODO may need to add configuration value to allow anonymous attachments
//                    if (!csContext.Context.Request.IsAuthenticated)
//                        throw new CSException(CSExceptionType.AccessDenied);
//
//                    if(!fp.Attachment)
//                        throw new CSException(CSExceptionType.PostAttachmentsNotAllowed);
//                    break;
                case (long)Permission.Post:
                    if (!fp.Post)
                    {   
                        RedirectOrExcpetion(CSExceptionType.PostAccessDenied, section.Name);
                    }
                    break;

                case (long)Permission.Reply:
					
                    if ((csContext.User.IsAnonymous) && ((!section.EnableAnonymousPosting) || (!csContext.SiteSettings.EnableAnonymousUserPosting)))
                            RedirectOrExcpetion(CSExceptionType.PostReplyAccessDenied);

                    if (!fp.Reply) 
                        RedirectOrExcpetion(CSExceptionType.PostReplyAccessDenied);
					
                    break;
                case (long)Permission.View:
                    if(!fp.View)
                        RedirectOrExcpetion(CSExceptionType.SectionNotFound, "Weblog does not exists or View Permission is denied on " + section.Name);
                    break;
                 default:
                    RedirectOrExcpetion(CSExceptionType.AccessDenied);
                    break;
            }
        }
        #endregion



	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -