From 27fb79d4d5d85b2a975371e1bf137c7e2b789338 Mon Sep 17 00:00:00 2001 From: Azareal Date: Thu, 29 Nov 2018 17:27:17 +1000 Subject: [PATCH] Fixed a bug where forums inheriting from the group didn't appear on the forum list and the topic list. Cleaned up the logic in preRoute slightly. Reordered the logic in preRoute so that the CSP is set for the PreError too. Clear a user's cached data when their IP changes. Hide the comment header when there aren't any comments. --- common/forum_perms_store.go | 6 ++++++ common/pages.go | 9 ++++++--- common/routes_common.go | 19 ++++++++----------- common/user.go | 7 +++++++ extend/guilds/lib/guilds.go | 37 +++++++++++++++++-------------------- routes/panel/forums.go | 4 ++-- templates/profile.html | 8 ++++---- 7 files changed, 50 insertions(+), 40 deletions(-) diff --git a/common/forum_perms_store.go b/common/forum_perms_store.go index f27de96a..0366ca53 100644 --- a/common/forum_perms_store.go +++ b/common/forum_perms_store.go @@ -90,10 +90,13 @@ func (fps *MemoryForumPermsStore) Reload(fid int) error { return err } + DebugLog("gid: ", gid) + DebugLogf("perms: %+v\n", perms) pperms, err := fps.parseForumPerm(perms) if err != nil { return err } + DebugLogf("pperms: %+v\n", pperms) forumPerms[gid] = pperms } DebugLogf("forumPerms: %+v\n", forumPerms) @@ -139,6 +142,9 @@ func (fps *MemoryForumPermsStore) Reload(fid int) error { } forumPerm, ok = forumPerms[group.ID] if !ok { + if group.Perms.ViewTopic { + group.CanSee = append(group.CanSee, fid) + } continue } diff --git a/common/pages.go b/common/pages.go index 354e7472..63e3a83c 100644 --- a/common/pages.go +++ b/common/pages.go @@ -13,7 +13,8 @@ import ( // TODO: Allow resources in spots other than /static/ and possibly even external domains (e.g. CDNs) // TODO: Preload Trumboyg on Cosora on the forum list type Header struct { - Title string + Title string + //Title []byte // Experimenting with []byte for increased efficiency, let's avoid converting too many things to []byte, as it involves a lot of extra boilerplate NoticeList []string Scripts []string //Preload []string @@ -30,6 +31,7 @@ type Header struct { Path string MetaDesc string StartedAt time.Time + Elapsed1 string Writer http.ResponseWriter ExtData ExtData } @@ -348,8 +350,9 @@ type PanelEditGroupPage struct { } type GroupForumPermPreset struct { - Group *Group - Preset string + Group *Group + Preset string + DefaultPreset bool } type PanelEditForumPage struct { diff --git a/common/routes_common.go b/common/routes_common.go index bd057a15..56cbfba9 100644 --- a/common/routes_common.go +++ b/common/routes_common.go @@ -234,6 +234,12 @@ func preRoute(w http.ResponseWriter, r *http.Request) (User, bool) { *usercpy = *userptr usercpy.Init() // TODO: Can we reduce the amount of work we do here? + // TODO: Add a config setting to disable this header + // TODO: Have this header cover more things + if Site.EnableSsl { + w.Header().Set("Content-Security-Policy", "upgrade-insecure-requests") + } + // TODO: WIP. Refactor this to eliminate the unnecessary query // TODO: Better take proxies into consideration host, _, err := net.SplitHostPort(r.RemoteAddr) @@ -253,23 +259,14 @@ func preRoute(w http.ResponseWriter, r *http.Request) (User, bool) { } } - // TODO: Add a config setting to disable this header - // TODO: Have this header cover more things - if Site.EnableSsl { - w.Header().Set("Content-Security-Policy", "upgrade-insecure-requests") - } + usercpy.LastIP = host - if userptr == &GuestUser { - usercpy.LastIP = host - return *usercpy, true - } - if host != usercpy.LastIP { + if usercpy.Loggedin && host != usercpy.LastIP { err = usercpy.UpdateIP(host) if err != nil { InternalError(err, w, r) return *usercpy, false } - usercpy.LastIP = host } return *usercpy, true diff --git a/common/user.go b/common/user.go index f074635a..5948a288 100644 --- a/common/user.go +++ b/common/user.go @@ -333,6 +333,10 @@ func (user *User) ChangeGroup(group int) (err error) { // ! Only updates the database not the *User for safety reasons func (user *User) UpdateIP(host string) error { _, err := userStmts.updateLastIP.Exec(host, user.ID) + ucache := Users.GetCache() + if ucache != nil { + ucache.Remove(user.ID) + } return err } @@ -429,6 +433,9 @@ func (user *User) InitPerms() { user.Perms = group.Perms user.PluginPerms = group.PluginPerms } + /*if len(group.CanSee) == 0 { + panic("should not be zero") + }*/ user.IsAdmin = user.IsSuperAdmin || group.IsAdmin user.IsSuperMod = user.IsAdmin || group.IsMod diff --git a/extend/guilds/lib/guilds.go b/extend/guilds/lib/guilds.go index d0b63f5d..964d1782 100644 --- a/extend/guilds/lib/guilds.go +++ b/extend/guilds/lib/guilds.go @@ -49,32 +49,29 @@ type Guild struct { } type Page struct { - Title string - CurrentUser common.User - Header *common.Header - ItemList []*common.TopicsRow - Forum *common.Forum - Guild *Guild - Page int - LastPage int + Title string + Header *common.Header + ItemList []*common.TopicsRow + Forum *common.Forum + Guild *Guild + Page int + LastPage int } // ListPage is a page struct for constructing a list of every guild type ListPage struct { - Title string - CurrentUser common.User - Header *common.Header - GuildList []*Guild + Title string + Header *common.Header + GuildList []*Guild } type MemberListPage struct { - Title string - CurrentUser common.User - Header *common.Header - ItemList []Member - Guild *Guild - Page int - LastPage int + Title string + Header *common.Header + ItemList []Member + Guild *Guild + Page int + LastPage int } // Member is a struct representing a specific member of a guild, not to be confused with the global User struct. @@ -386,7 +383,7 @@ func PreRenderViewForum(w http.ResponseWriter, r *http.Request, user *common.Use if guildData, ok := pi.Header.ExtData.Items["guilds_current_group"]; ok { guildItem := guildData.(*Guild) - guildpi := Page{pi.Title, pi.CurrentUser, pi.Header, pi.ItemList, pi.Forum, guildItem, pi.Page, pi.LastPage} + guildpi := Page{pi.Title, pi.Header, pi.ItemList, pi.Forum, guildItem, pi.Page, pi.LastPage} err := common.Templates.ExecuteTemplate(w, "guilds_view_guild.html", guildpi) if err != nil { common.LogError(err) diff --git a/routes/panel/forums.go b/routes/panel/forums.go index c17ba28c..80baca19 100644 --- a/routes/panel/forums.go +++ b/routes/panel/forums.go @@ -124,7 +124,6 @@ func ForumsDeleteSubmit(w http.ResponseWriter, r *http.Request, user common.User if err != nil { return common.LocalError("The provided Forum ID is not a valid number.", w, r, user) } - err = common.Forums.Delete(fid) if err == sql.ErrNoRows { return common.LocalError("The forum you're trying to delete doesn't exist.", w, r, user) @@ -176,7 +175,8 @@ func ForumsEdit(w http.ResponseWriter, r *http.Request, user common.User, sfid s } else if err != nil { return common.InternalError(err, w, r) } - gplist = append(gplist, common.GroupForumPermPreset{group, common.ForumPermsToGroupForumPreset(forumPerms)}) + preset := common.ForumPermsToGroupForumPreset(forumPerms) + gplist = append(gplist, common.GroupForumPermPreset{group, preset, preset == "default"}) } if r.FormValue("updated") == "1" { diff --git a/templates/profile.html b/templates/profile.html index 8dc22a4d..dea88360 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -71,10 +71,10 @@ - + -->**/}}
@@ -82,9 +82,9 @@ {{end}} -
+ {{if .ItemList}} +
{{end}}
{{template "profile_comments_row.html" . }}
{{if .CurrentUser.Loggedin}}