Esempio n. 1
0
        public async Task <ActionResult> ToggleSubscribe(int id = 0)
        {
            var(result, thread) = await PerformSecurityCheckAsync(id, allowAnonymous : false);

            if (result != null)
            {
                return(Json(new { success = false }));
            }

            var userID       = this.HttpContext.Session.GetUserID();
            var currentState = await UserGuiHelper.CheckIfThreadIsAlreadySubscribedAsync(userID, id);

            if (currentState)
            {
                await UserManager.RemoveSingleSubscriptionAsync(id, userID);
            }
            else
            {
                await UserManager.AddThreadToSubscriptionsAsync(id, userID, null);
            }

            return(Json(new { success = true, newstate = !currentState }));
        }
Esempio n. 2
0
        public async Task <ActionResult> Index(int threadId = 0, int pageNo = 1)
        {
            var(result, thread) = await PerformSecurityCheckAsync(threadId, allowAnonymous : true);

            if (result != null)
            {
                return(result);
            }

            var forum = await _cache.GetForumAsync(thread.ForumID);

            if (forum == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            int pageNoToFetch    = pageNo < 1 ? 1 : pageNo;
            var numberOfMessages = await ThreadGuiHelper.GetTotalNumberOfMessagesInThreadAsync(threadId);

            var numberOfMessagesPerPage = this.HttpContext.Session.GetUserDefaultNumberOfMessagesPerPage();
            var userID     = this.HttpContext.Session.GetUserID();
            var threadData = new ThreadData()
            {
                Thread          = thread,
                ForumName       = forum.ForumName,
                SectionName     = await _cache.GetSectionNameAsync(forum.SectionID),
                PageNo          = pageNo,
                PageSize        = numberOfMessagesPerPage,
                NumberOfPages   = ((numberOfMessages - 1) / numberOfMessagesPerPage) + 1,
                ShowIPAddresses = (this.HttpContext.Session.HasSystemActionRight(ActionRights.SystemManagement) ||
                                   this.HttpContext.Session.HasSystemActionRight(ActionRights.SecurityManagement) ||
                                   this.HttpContext.Session.HasSystemActionRight(ActionRights.UserManagement)),
                ForumMaxNumberOfAttachmentsPerMessage = forum.MaxNoOfAttachmentsPerMessage,
                ThreadStartedByCurrentUser            = thread.StartedByUserID == userID,
                UserMayAddAttachments = this.HttpContext.Session.CanPerformForumActionRight(thread.ForumID, ActionRights.AddAttachment),
                UserCanCreateThreads  = this.HttpContext.Session.CanPerformForumActionRight(thread.ForumID, ActionRights.AddNormalThread) ||
                                        this.HttpContext.Session.CanPerformForumActionRight(thread.ForumID, ActionRights.AddStickyThread),
                UserCanApproveAttachments = this.HttpContext.Session.CanPerformForumActionRight(thread.ForumID, ActionRights.ApproveAttachment),
                UserMayDoForumSpecificThreadManagement = this.HttpContext.Session.CanPerformForumActionRight(thread.ForumID,
                                                                                                             ActionRights.ForumSpecificThreadManagement),
                UserMayDoSystemWideThreadManagement = this.HttpContext.Session.HasSystemActionRight(ActionRights.SystemWideThreadManagement),
                UserMayEditMemo         = this.HttpContext.Session.CanPerformForumActionRight(thread.ForumID, ActionRights.EditThreadMemo),
                UserMayMarkThreadAsDone = (this.HttpContext.Session.CanPerformForumActionRight(thread.ForumID, ActionRights.FlagThreadAsDone) ||
                                           (thread.StartedByUserID == userID)),
                UserMayManageSupportQueueContents  = this.HttpContext.Session.HasSystemActionRight(ActionRights.QueueContentManagement),
                UserMayManageOtherUsersAttachments = this.HttpContext.Session.CanPerformForumActionRight(thread.ForumID, ActionRights.ManageOtherUsersAttachments),
                UserMayDoBasicThreadOperations     = !this.HttpContext.Session.IsAnonymousUser(),
                ThreadIsBookmarked = await UserGuiHelper.CheckIfThreadIsAlreadyBookmarkedAsync(userID, threadId),
                ThreadIsSubscribed = await UserGuiHelper.CheckIfThreadIsAlreadySubscribedAsync(userID, threadId),
                ThreadMessages     = await ThreadGuiHelper.GetAllMessagesInThreadAsDTOsAsync(threadId, pageNoToFetch, numberOfMessagesPerPage),
            };

            if (!thread.IsClosed)
            {
                threadData.UserMayAddNewMessages = this.HttpContext.Session.CanPerformForumActionRight(thread.ForumID, thread.IsSticky
                                                                                                                                                                                                                   ? ActionRights.AddAndEditMessageInSticky
                                                                                                                                                                                                                   : ActionRights.AddAndEditMessage);
                threadData.ShowEditMessageLink = this.HttpContext.Session.CanPerformForumActionRight(thread.ForumID, ActionRights.EditDeleteOtherUsersMessages);
            }

            await FillSupportQueueInformationAsync(threadData);

            FillMemoInformation(threadData);
            return(View(threadData));
        }