예제 #1
0
파일: Authorizer.cs 프로젝트: x1987624/SNS
        /// <summary>
        /// 上传照片/照片采集
        /// </summary>
        /// <remarks>
        /// 相册主人或管理员可以上传指定相册的图片
        /// </remarks>
        public static bool Photo_Create(this Authorizer authorizer, Album album, out string errorMessage)
        {
            IUser currentUser = UserContext.CurrentUser;

            errorMessage = "没有权限上传照片";

            if (currentUser == null)
            {
                errorMessage = "您必须先登录,才能上传照片";
                return(false);
            }

            if (authorizer.IsAdministrator(PhotoConfig.Instance().ApplicationId))
            {
                return(true);
            }

            if (album.UserId == currentUser.UserId && authorizer.AuthorizationService.Check(currentUser, PermissionItemKeys.Instance().Photo_Create()))
            {
                return(true);
            }

            if (currentUser.IsModerated)
            {
                errorMessage = Resources.Resource.Description_ModeratedUser_CreatePhotoDenied;
            }
            return(false);
        }
예제 #2
0
파일: Authorizer.cs 프로젝트: x1987624/SNS
        /// <summary>
        /// 上传照片
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="spaceKey"></param>
        /// <returns></returns>
        public static bool Photo_Upload(this Authorizer authorizer, string spaceKey, out string errorMessage)
        {
            IUser currentUser = UserContext.CurrentUser;

            errorMessage = "没有权限上传照片";

            if (currentUser == null)
            {
                errorMessage = "您必须先登录,才能上传照片";
                return(false);
            }

            if (authorizer.IsAdministrator(PhotoConfig.Instance().ApplicationId))
            {
                return(true);
            }

            if (currentUser.UserName.Equals(spaceKey, StringComparison.CurrentCultureIgnoreCase) && authorizer.AuthorizationService.Check(currentUser, PermissionItemKeys.Instance().Photo_Create()))
            {
                return(true);
            }
            if (currentUser.IsModerated)
            {
                errorMessage = Resources.Resource.Description_ModeratedUser_CreatePhotoDenied;
            }
            return(false);
        }
예제 #3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="name">Searcher名称</param>
 /// <param name="indexPath">索引文件所在路径(支持"~/"及unc路径)</param>
 /// <param name="asQuickSearch">是否作为快捷搜索</param>
 /// <param name="displayOrder">显示顺序</param>
 public PhotoSearcher(string name, string indexPath, bool asQuickSearch, int displayOrder)
 {
     this.Name           = name;
     this.IndexPath      = WebUtility.GetPhysicalFilePath(indexPath);
     this.AsQuickSearch  = asQuickSearch;
     this.DisplayOrder   = displayOrder;
     searchEngine        = SearcherFactory.GetSearchEngine(indexPath);
     publiclyAuditStatus = auditService.GetPubliclyAuditStatus(PhotoConfig.Instance().ApplicationId);
 }
예제 #4
0
파일: Authorizer.cs 프로젝트: x1987624/SNS
        /// <summary>
        /// 编辑相册/删除相册/设置相册封面
        /// </summary>
        /// <remarks>
        /// 相册主人或管理员可以操作
        /// </remarks>
        public static bool Album_Edit(this Authorizer authorizer, Album album)
        {
            IUser currentUser = UserContext.CurrentUser;

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

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

            return(false);
        }
예제 #5
0
파일: Authorizer.cs 프로젝트: x1987624/SNS
        /// <summary>
        /// 照片加精/取消精华/照片推荐/相册推荐
        /// </summary>
        /// <remarks>
        /// 管理员可以操作
        /// </remarks>
        public static bool Photo_Manage(this Authorizer authorizer)
        {
            IUser currentUser = UserContext.CurrentUser;

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

            if (authorizer.IsAdministrator(PhotoConfig.Instance().ApplicationId))
            {
                return(true);
            }

            return(false);
        }
예제 #6
0
파일: Authorizer.cs 프로젝트: x1987624/SNS
        /// <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);
        }
예제 #7
0
파일: Authorizer.cs 프로젝트: x1987624/SNS
        /// <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);
        }
예제 #8
0
파일: Authorizer.cs 프로젝트: x1987624/SNS
        /// <summary>
        /// 删除圈人
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="label">圈人信息</param>
        /// <returns></returns>
        public static bool PhotoLabel_Delete(this Authorizer authorizer, PhotoLabel label)
        {
            if (label == null)
            {
                return(false);
            }

            if (UserContext.CurrentUser == null)
            {
                return(false);
            }

            if (label.UserId == UserContext.CurrentUser.UserId)
            {
                return(true);
            }

            if (label.Photo.UserId == UserContext.CurrentUser.UserId)
            {
                return(true);
            }

            return(authorizer.IsAdministrator(PhotoConfig.Instance().ApplicationId));
        }
예제 #9
0
파일: Authorizer.cs 프로젝트: x1987624/SNS
        /// <summary>
        /// 是否有圈人的权限
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="photo">被圈的照片</param>
        /// <returns></returns>
        public static bool PhotoLabel_Creat(this Authorizer authorizer, Photo photo)
        {
            if (photo == null)
            {
                return(false);
            }

            if (UserContext.CurrentUser == null)
            {
                return(false);
            }

            if (photo.UserId == UserContext.CurrentUser.UserId)
            {
                return(true);
            }

            if (new FollowService().IsMutualFollowed(photo.UserId, UserContext.CurrentUser.UserId))
            {
                return(true);
            }

            return(authorizer.IsAdministrator(PhotoConfig.Instance().ApplicationId));
        }
예제 #10
0
 /// <summary>
 /// 照片数
 /// </summary>
 public static string PhotoCount(this OwnerDataKeys ownerDataKeys)
 {
     return(PhotoConfig.Instance().ApplicationKey + "-ThreadCount");
 }