From 71fd56fa9509d67449ef863d6fa2ce1d139259d1 Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Fri, 2 Jul 2010 11:23:09 +0000 Subject: [PATCH] All layers except normal are hidden from guests --- Builder/IISMainHandler/build.txt | 2 +- Builder/IISUploadHandler/build.txt | 2 +- Common/UserContext.cs | 6 ++-- Common/dataobjects/AccountSettings.cs | 7 +++++ Common/dataobjects/AnonymousUserSettings.cs | 6 ++++ Common/dataobjects/IUserSettings.cs | 2 ++ Common/dataobjects/Post.cs | 8 +---- Common/dataobjects/Thread.cs | 3 ++ IISMainHandler/WebContext.cs | 21 +++++++++----- .../request/MarkThreadAsReadHandler.cs | 29 +++++++++++++++++++ .../handlers/request/ReturnPostHandler.cs | 24 +++++++++++++++ 11 files changed, 89 insertions(+), 21 deletions(-) create mode 100644 IISMainHandler/handlers/request/MarkThreadAsReadHandler.cs create mode 100644 IISMainHandler/handlers/request/ReturnPostHandler.cs diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 02416eb..4c9bbbf 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -467 \ No newline at end of file +468 \ No newline at end of file diff --git a/Builder/IISUploadHandler/build.txt b/Builder/IISUploadHandler/build.txt index 5e78f1e..cbd6012 100644 --- a/Builder/IISUploadHandler/build.txt +++ b/Builder/IISUploadHandler/build.txt @@ -1 +1 @@ -203 \ No newline at end of file +204 \ No newline at end of file diff --git a/Common/UserContext.cs b/Common/UserContext.cs index 78f8ba2..17cdbad 100644 --- a/Common/UserContext.cs +++ b/Common/UserContext.cs @@ -17,10 +17,6 @@ namespace FLocal.Common { get; } - abstract public dataobjects.IUserSettings userSettings { - get; - } - abstract public string formatDateTime(DateTime dateTime); abstract public XElement formatTotalPosts(long posts); @@ -32,6 +28,8 @@ namespace FLocal.Common { get; } + abstract public bool isPostVisible(dataobjects.Post post); + } public static class UserContext_Extensions { diff --git a/Common/dataobjects/AccountSettings.cs b/Common/dataobjects/AccountSettings.cs index cb50255..9864dc8 100644 --- a/Common/dataobjects/AccountSettings.cs +++ b/Common/dataobjects/AccountSettings.cs @@ -89,6 +89,13 @@ namespace FLocal.Common.dataobjects { } } + public bool isPostVisible(Post post) { + if(post.poster.showPostsToUsers == User.ENUM_SHOWPOSTSTOUSERS_NONE) return false; + if(post.poster.showPostsToUsers == User.ENUM_SHOWPOSTSTOUSERS_PRIVELEGED) return false; + if(post.layer.name == PostLayer.NAME_HIDDEN) return false; + return true; + } + protected override void doFromHash(Dictionary data) { this._accountId = int.Parse(data[TableSpec.FIELD_ACCOUNTID]); this._postsPerPage = int.Parse(data[TableSpec.FIELD_POSTSPERPAGE]); diff --git a/Common/dataobjects/AnonymousUserSettings.cs b/Common/dataobjects/AnonymousUserSettings.cs index 15f9a6d..3f30fcb 100644 --- a/Common/dataobjects/AnonymousUserSettings.cs +++ b/Common/dataobjects/AnonymousUserSettings.cs @@ -43,5 +43,11 @@ namespace FLocal.Common.dataobjects { } } + public bool isPostVisible(Post post) { + if(post.poster.showPostsToUsers != User.ENUM_SHOWPOSTSTOUSERS_ALL) return false; + if(post.layer.name != PostLayer.NAME_NORMAL) return false; + return true; + } + } } diff --git a/Common/dataobjects/IUserSettings.cs b/Common/dataobjects/IUserSettings.cs index 6daf333..fe83bed 100644 --- a/Common/dataobjects/IUserSettings.cs +++ b/Common/dataobjects/IUserSettings.cs @@ -27,6 +27,8 @@ namespace FLocal.Common.dataobjects { get; } + bool isPostVisible(Post post); + } public static class IUserSettings_Extension { diff --git a/Common/dataobjects/Post.cs b/Common/dataobjects/Post.cs index a8245b5..660b4cb 100644 --- a/Common/dataobjects/Post.cs +++ b/Common/dataobjects/Post.cs @@ -165,13 +165,7 @@ namespace FLocal.Common.dataobjects { public XElement exportToXmlWithoutThread(UserContext context, bool includeParentPost, params XElement[] additional) { - if(context.account == null && this.poster.showPostsToUsers != User.ENUM_SHOWPOSTSTOUSERS_ALL) { - return null; - } - - if(this.poster.showPostsToUsers == User.ENUM_SHOWPOSTSTOUSERS_NONE) { - return null; - } + if(!context.isPostVisible(this)) return null; XElement result = new XElement("post", new XElement("id", this.id), diff --git a/Common/dataobjects/Thread.cs b/Common/dataobjects/Thread.cs index 263ec4a..d6c0723 100644 --- a/Common/dataobjects/Thread.cs +++ b/Common/dataobjects/Thread.cs @@ -182,6 +182,9 @@ namespace FLocal.Common.dataobjects { } public XElement exportToXml(UserContext context, bool includeFirstPost, params XElement[] additional) { + + if(!context.isPostVisible(this.firstPost)) return null; + XElement result = new XElement("thread", new XElement("id", this.id), new XElement("firstPostId", this.firstPostId), diff --git a/IISMainHandler/WebContext.cs b/IISMainHandler/WebContext.cs index 2ba11e7..3b64582 100644 --- a/IISMainHandler/WebContext.cs +++ b/IISMainHandler/WebContext.cs @@ -32,11 +32,9 @@ namespace FLocal.IISHandler { } } - private IUserSettings _userSettings; - public override IUserSettings userSettings { - get { - return this._userSettings; - } + public IUserSettings userSettings { + get; + private set; } public override Common.IOutputParams outputParams { @@ -59,7 +57,10 @@ namespace FLocal.IISHandler { return PageOuter.create(this.userSettings.postsPerPage, posts).exportToXml(2, 0, 2); } - public DateTime requestTime; + public DateTime requestTime { + get; + private set; + } public Session session; @@ -72,6 +73,10 @@ namespace FLocal.IISHandler { } } + public override bool isPostVisible(Post post) { + return this.userSettings.isPostVisible(post); + } + public WebContext(HttpContext httpcontext) { this.httpcontext = httpcontext; this.requestTime = DateTime.Now; @@ -90,9 +95,9 @@ namespace FLocal.IISHandler { } } if(this.session != null) { - this._userSettings = AccountSettings.LoadByAccount(this.session.account); + this.userSettings = AccountSettings.LoadByAccount(this.session.account); } else { - this._userSettings = new AnonymousUserSettings(); + this.userSettings = new AnonymousUserSettings(); } } diff --git a/IISMainHandler/handlers/request/MarkThreadAsReadHandler.cs b/IISMainHandler/handlers/request/MarkThreadAsReadHandler.cs new file mode 100644 index 0000000..129db4e --- /dev/null +++ b/IISMainHandler/handlers/request/MarkThreadAsReadHandler.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml.Linq; +using FLocal.Common.dataobjects; +using FLocal.Importer; +using System.Text.RegularExpressions; +using FLocal.Core; +using FLocal.Common; +using FLocal.Common.actions; +using System.Web; + +namespace FLocal.IISHandler.handlers.request { + class MarkThreadAsReadHandler : ReturnPostHandler { + + protected override void _Do(WebContext context) { + Account account = context.session.account; + Thread thread = Thread.LoadById(int.Parse(context.requestParts[2])); + if(!context.requestParts[3].StartsWith("p")) throw new CriticalException("wrong url"); + Post post = Post.LoadById(int.Parse(context.requestParts[3].PHPSubstring(1))); + + if(post.thread.id != thread.id) throw new CriticalException("id mismatch"); + + thread.forceMarkAsRead(account, post); + } + + } +} diff --git a/IISMainHandler/handlers/request/ReturnPostHandler.cs b/IISMainHandler/handlers/request/ReturnPostHandler.cs new file mode 100644 index 0000000..a545d7d --- /dev/null +++ b/IISMainHandler/handlers/request/ReturnPostHandler.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml.Linq; + +namespace FLocal.IISHandler.handlers.request { + abstract class ReturnPostHandler : AbstractPostHandler { + + protected override string templateName { + get { + return null; + } + } + + abstract protected void _Do(WebContext context); + + protected override XElement[] Do(WebContext context) { + this._Do(context); + throw new RedirectException(context.httprequest.UrlReferrer.ToString()); + } + + } +}