Пример #1
0
        /// <summary>
        /// 查看日志
        /// 仅自己可见的只能是日志作者或管理员可以查看
        /// 部分可见的只能是日志作者、指定可见的用户或管理员可以查看
        /// </summary>
        public static bool BlogThread_View(this Authorizer authorizer, BlogThread blogThread)
        {
            if (blogThread.PrivacyStatus == PrivacyStatus.Public)
            {
                return(true);
            }

            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }

            if (blogThread.UserId == currentUser.UserId || authorizer.IsAdministrator(BlogConfig.Instance().ApplicationId))
            {
                return(true);
            }

            if (blogThread.PrivacyStatus == PrivacyStatus.Private)
            {
                return(false);
            }

            ContentPrivacyService contentPrivacyService = new ContentPrivacyService();

            if (contentPrivacyService.Validate(blogThread, currentUser.UserId))
            {
                return(true);
            }

            return(false);
        }
Пример #2
0
        /// <summary>
        /// 查看搜索
        /// 仅自己可见的只能是相册作者或管理员可以查看
        /// 部分可见的只能是相册作者、指定可见的用户或管理员可以查看
        /// </summary>
        public static bool Photo_Search(this Authorizer authorizer, Album album)
        {
            if (album == null)
            {
                return(false);
            }
            if (album.PrivacyStatus == PrivacyStatus.Public)
            {
                return(true);
            }

            IUser currentUser = UserContext.CurrentUser;

            if (currentUser != null)
            {
                if (album.UserId == currentUser.UserId || authorizer.IsAdministrator(PhotoConfig.Instance().ApplicationId))
                {
                    return(true);
                }
            }

            if (album.PrivacyStatus == PrivacyStatus.Private)
            {
                return(false);
            }

            ContentPrivacyService contentPrivacyService = new ContentPrivacyService();

            if (currentUser != null)
            {
                if (contentPrivacyService.Validate(album, currentUser.UserId))
                {
                    return(true);
                }
            }
            if (currentUser == null && album.PrivacyStatus == PrivacyStatus.Part)
            {
                return(false);
            }
            return(false);
        }
Пример #3
0
        /// <summary>
        /// 查看照片
        /// </summary>
        /// <remarks>
        /// 符合照片隐私设置(所属相册的隐私设置)的人或管理员可以查看照片
        /// </remarks>
        public static bool Photo_View(this Authorizer authorizer, Photo photo)
        {
            PhotoService photoService = new PhotoService();
            Album        album        = photoService.GetAlbum(photo.AlbumId);

            if (album == null)
            {
                return(false);
            }
            if (album.PrivacyStatus == PrivacyStatus.Public)
            {
                return(true);
            }

            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }

            if (album.UserId == currentUser.UserId || authorizer.IsAdministrator(PhotoConfig.Instance().ApplicationId))
            {
                return(true);
            }

            if (album.PrivacyStatus == PrivacyStatus.Private)
            {
                return(false);
            }

            ContentPrivacyService contentPrivacyService = new ContentPrivacyService();

            if (contentPrivacyService.Validate(album, currentUser.UserId))
            {
                return(true);
            }

            return(false);
        }