Example #1
0
 public bool IsPermissionGranted(MemberRole role, Permission permission, ContentThread thread = null)
 {
     if (thread == null)
     {
         return(IsPermissionGranted(role.Id, permission.Name));
     }
     else
     {
         return(IsPermissionGranted(role.Id, permission.Name, thread.Id));
     }
 }
Example #2
0
        //get topics on paging
        public PageListClient <TopicClient> PagingClientTopics(int pageSize, PageTopicFilterClient filter)
        {
            Expression <Func <ContentTopic, bool> > predicate = PredicateBuilder.True <ContentTopic>(); // null; // = x => x.IsVisible == false;

            predicate = predicate.And(x => !x.IsHidden);

            //Ignore it, if there is only one thread in the system
            if (_threadWork.TotalThreadCount > 1)
            {
                ContentThread thread = _threadWork.GetThread(filter.ThreadKey);
                Expression <Func <ContentTopic, bool> > threadPredicate = PredicateBuilder.False <ContentTopic>();
                threadPredicate = threadPredicate.Or(x => x.ThreadId == thread.Id);
                predicate       = predicate.And(threadPredicate.Expand());
            }

            foreach (var tagOption in filter.TagOptions)
            {
                if (string.IsNullOrEmpty(tagOption.IdStrs) || tagOption.IdStrs.Contains(WebConstants.Tag_Specifier_All))
                {
                    continue;
                }
                List <Guid> tagIds = tagOption.ToTagIds();
                if (tagIds.Count > 0)
                {
                    Expression <Func <ContentTopic, bool> > singleTagPredicate = PredicateBuilder.False <ContentTopic>();
                    foreach (var tagId in tagIds)
                    {
                        singleTagPredicate = singleTagPredicate.Or(x => x.Tags.Select(t => t.Id).Contains(tagId));
                    }

                    if (singleTagPredicate != null)
                    {
                        predicate = predicate.And(singleTagPredicate.Expand()); //call expand() to fix not bound error
                    }
                }
            }

            var pageTopic = _topicWork.Paging(filter.PageNumber, pageSize, filter.Sort, predicate, new string[] { "Tags" });
            PageListClient <TopicClient> page = new PageListClient <TopicClient>(pageTopic, pageTopic.Count);

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

            return(page);
        }
Example #3
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);
        }