Beispiel #1
0
        public override CommentClient ToClient(ContentComment entity, CommentClient c = null, string[] excludeProperties = null, bool serverStatus = true)
        {
            if (entity == null)
            {
                return(null);
            }

            CommentClient commentClient = base.ToClient(entity, c, excludeProperties, serverStatus);

            commentClient.Content        = entity.Content;
            commentClient.TopicId        = entity.TopicId;
            commentClient.CreateTime     = entity.CreateTime;
            commentClient.LastUpdateTime = entity.LastUpdateTime;
            commentClient.IsLocked       = entity.IsLocked || entity.IsHidden;

            if (excludeProperties == null || !excludeProperties.Contains("Vote"))
            {
                if (commentClient.Vote == null)
                {
                    commentClient.Vote = new VoteClient();
                }

                commentClient.Vote.UserName      = entity.UserName;
                commentClient.Vote.VoteUpCount   = entity.VoteUpCount;
                commentClient.Vote.VoteDownCount = entity.VoteDownCount;
                commentClient.Vote.CommentId     = entity.Id;
            }

            if (excludeProperties == null || !excludeProperties.Contains("UploadPermission"))
            {
                commentClient.CanUploadDocument = HasPermission(EntityPermission.UploadDocument, entity) == OperationStatus.Granted;
                commentClient.CanUploadImage    = HasPermission(EntityPermission.UploadImage, entity) == OperationStatus.Granted;
            }

            if (entity.Topic != null)
            {
                commentClient.ThreadId   = entity.Topic.ThreadId;
                commentClient.TopicTitle = entity.Topic.Title;
                if (excludeProperties == null || !excludeProperties.Contains("Topic.SubTitle"))
                {
                    commentClient.TopicSubTitle = entity.Topic.SubTitle;
                }
                commentClient.TopicThumbnail = entity.Topic.Thumbnail;
                if (entity.Topic.IsLocked || entity.Topic.IsHidden)
                {
                    commentClient.IsLocked = true;
                }
                else
                {
                    if (_threadWordk.GetThread(entity.Topic.ThreadId).IsLocked)
                    {
                        commentClient.IsLocked = true;
                    }
                }
            }


            return(commentClient);
        }
Beispiel #2
0
        public override OperationStatus HasPermission(EntityPermission permission, ContentComment item = null, Guid?threadId = null)
        {
            if (!Security.IsCurrentUserValid())
            {
                return(OperationStatus.NoPermission);
            }
            if (IsCurrentAdminUser())
            {
                return(OperationStatus.Granted);
            }

            if (item != null && permission.IsDataChangePermission())
            {
                var currentThread = _threadWork.GetThread(item.Topic.ThreadId);
                if (item.IsHidden || item.Topic.IsHidden || currentThread.IsHidden || currentThread.IsAbstract)
                {
                    return(OperationStatus.CommentHasHidden);
                }
                if (item.IsLocked || item.Topic.IsLocked || currentThread.IsLocked)
                {
                    return(OperationStatus.CommentHasLocked);
                }
                if (Security.CurrentUser.UserId != item.UserId)
                {
                    return(OperationStatus.NoPermission);
                }
            }

            if (PermissionNameDictionary.ContainsKey(permission))
            {
                Guid?tId = null;
                if (item != null && item.Topic != null)
                {
                    tId = item.Topic.ThreadId;
                }
                else if (threadId.HasValue)
                {
                    tId = threadId;
                }

                if (tId == null)
                {
                    return(PermissionWork.IsPermissionGranted(Security.CurrentUser.RoleId, PermissionNameDictionary[permission]) ?
                           OperationStatus.Granted : OperationStatus.NoPermission);
                }
                else
                {
                    return(PermissionWork.IsPermissionGranted(Security.CurrentUser.RoleId, PermissionNameDictionary[permission], tId) ?
                           OperationStatus.Granted : OperationStatus.NoPermission);
                }
            }

            return(OperationStatus.NoPermission);
        }
Beispiel #3
0
        public ModelListClient <TopicClient> GetStickyTopics(string threadKey)
        {
            Expression <Func <ContentTopic, bool> > predicate = PredicateBuilder.True <ContentTopic>();

            if (_threadWork.TotalThreadCount > 1)
            {
                var currentThread = string.IsNullOrEmpty(threadKey) ? _threadWork.RootThread : _threadWork.GetThread(threadKey);
                predicate = predicate.And(x => x.ThreadId == currentThread.Id);
            }

            predicate = predicate.And(x => x.IsSticky && !x.IsHidden);
            var query = _topicWork.Query(predicate, "CreateTime");
            ModelListClient <TopicClient> modelList = new ModelListClient <TopicClient>();

            foreach (var topic in query)
            {
                modelList.Add(ToClient(topic, excludeProperties: new string[] { "Tags", "FirstComment", "Comments", "UploadPermission" }));
            }

            return(modelList);
        }
Beispiel #4
0
        public bool IsPermissionGranted(Guid roleId, string permissionName, Guid?contentThreadId = null)
        {
            Guid threadId;

            if (contentThreadId.HasValue)
            {
                threadId = contentThreadId.Value;
                while (!PermissionTickets.ContainsKey(threadId))
                {
                    ContentThread thread = _threadWork.GetThread(threadId);
                    if (thread == null || thread.ParentThreadId == null)
                    {
                        break;
                    }
                    threadId = thread.ParentThreadId.Value;
                }
            }
            else
            {
                threadId = _threadWork.RootThread.Id;
            }

            if (PermissionTickets.ContainsKey(threadId))
            {
                var roleDict = PermissionTickets[threadId];
                if (roleDict.ContainsKey(roleId))
                {
                    var permissionDict = roleDict[roleId];
                    if (permissionDict.ContainsKey(permissionName))
                    {
                        return(permissionDict[permissionName]);
                    }
                }
            }

            return(false);
        }
Beispiel #5
0
 public ContentThread GetThreadByKey(string key)
 {
     return(_threadServic.GetThread(key));
 }