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.
This commit is contained in:
parent
2e1916f3c9
commit
27fb79d4d5
|
@ -90,10 +90,13 @@ func (fps *MemoryForumPermsStore) Reload(fid int) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DebugLog("gid: ", gid)
|
||||||
|
DebugLogf("perms: %+v\n", perms)
|
||||||
pperms, err := fps.parseForumPerm(perms)
|
pperms, err := fps.parseForumPerm(perms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
DebugLogf("pperms: %+v\n", pperms)
|
||||||
forumPerms[gid] = pperms
|
forumPerms[gid] = pperms
|
||||||
}
|
}
|
||||||
DebugLogf("forumPerms: %+v\n", forumPerms)
|
DebugLogf("forumPerms: %+v\n", forumPerms)
|
||||||
|
@ -139,6 +142,9 @@ func (fps *MemoryForumPermsStore) Reload(fid int) error {
|
||||||
}
|
}
|
||||||
forumPerm, ok = forumPerms[group.ID]
|
forumPerm, ok = forumPerms[group.ID]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
if group.Perms.ViewTopic {
|
||||||
|
group.CanSee = append(group.CanSee, fid)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,8 @@ import (
|
||||||
// TODO: Allow resources in spots other than /static/ and possibly even external domains (e.g. CDNs)
|
// 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
|
// TODO: Preload Trumboyg on Cosora on the forum list
|
||||||
type Header struct {
|
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
|
NoticeList []string
|
||||||
Scripts []string
|
Scripts []string
|
||||||
//Preload []string
|
//Preload []string
|
||||||
|
@ -30,6 +31,7 @@ type Header struct {
|
||||||
Path string
|
Path string
|
||||||
MetaDesc string
|
MetaDesc string
|
||||||
StartedAt time.Time
|
StartedAt time.Time
|
||||||
|
Elapsed1 string
|
||||||
Writer http.ResponseWriter
|
Writer http.ResponseWriter
|
||||||
ExtData ExtData
|
ExtData ExtData
|
||||||
}
|
}
|
||||||
|
@ -348,8 +350,9 @@ type PanelEditGroupPage struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type GroupForumPermPreset struct {
|
type GroupForumPermPreset struct {
|
||||||
Group *Group
|
Group *Group
|
||||||
Preset string
|
Preset string
|
||||||
|
DefaultPreset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type PanelEditForumPage struct {
|
type PanelEditForumPage struct {
|
||||||
|
|
|
@ -234,6 +234,12 @@ func preRoute(w http.ResponseWriter, r *http.Request) (User, bool) {
|
||||||
*usercpy = *userptr
|
*usercpy = *userptr
|
||||||
usercpy.Init() // TODO: Can we reduce the amount of work we do here?
|
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: WIP. Refactor this to eliminate the unnecessary query
|
||||||
// TODO: Better take proxies into consideration
|
// TODO: Better take proxies into consideration
|
||||||
host, _, err := net.SplitHostPort(r.RemoteAddr)
|
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
|
usercpy.LastIP = host
|
||||||
// TODO: Have this header cover more things
|
|
||||||
if Site.EnableSsl {
|
|
||||||
w.Header().Set("Content-Security-Policy", "upgrade-insecure-requests")
|
|
||||||
}
|
|
||||||
|
|
||||||
if userptr == &GuestUser {
|
if usercpy.Loggedin && host != usercpy.LastIP {
|
||||||
usercpy.LastIP = host
|
|
||||||
return *usercpy, true
|
|
||||||
}
|
|
||||||
if host != usercpy.LastIP {
|
|
||||||
err = usercpy.UpdateIP(host)
|
err = usercpy.UpdateIP(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
InternalError(err, w, r)
|
InternalError(err, w, r)
|
||||||
return *usercpy, false
|
return *usercpy, false
|
||||||
}
|
}
|
||||||
usercpy.LastIP = host
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return *usercpy, true
|
return *usercpy, true
|
||||||
|
|
|
@ -333,6 +333,10 @@ func (user *User) ChangeGroup(group int) (err error) {
|
||||||
// ! Only updates the database not the *User for safety reasons
|
// ! Only updates the database not the *User for safety reasons
|
||||||
func (user *User) UpdateIP(host string) error {
|
func (user *User) UpdateIP(host string) error {
|
||||||
_, err := userStmts.updateLastIP.Exec(host, user.ID)
|
_, err := userStmts.updateLastIP.Exec(host, user.ID)
|
||||||
|
ucache := Users.GetCache()
|
||||||
|
if ucache != nil {
|
||||||
|
ucache.Remove(user.ID)
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,6 +433,9 @@ func (user *User) InitPerms() {
|
||||||
user.Perms = group.Perms
|
user.Perms = group.Perms
|
||||||
user.PluginPerms = group.PluginPerms
|
user.PluginPerms = group.PluginPerms
|
||||||
}
|
}
|
||||||
|
/*if len(group.CanSee) == 0 {
|
||||||
|
panic("should not be zero")
|
||||||
|
}*/
|
||||||
|
|
||||||
user.IsAdmin = user.IsSuperAdmin || group.IsAdmin
|
user.IsAdmin = user.IsSuperAdmin || group.IsAdmin
|
||||||
user.IsSuperMod = user.IsAdmin || group.IsMod
|
user.IsSuperMod = user.IsAdmin || group.IsMod
|
||||||
|
|
|
@ -49,32 +49,29 @@ type Guild struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Page struct {
|
type Page struct {
|
||||||
Title string
|
Title string
|
||||||
CurrentUser common.User
|
Header *common.Header
|
||||||
Header *common.Header
|
ItemList []*common.TopicsRow
|
||||||
ItemList []*common.TopicsRow
|
Forum *common.Forum
|
||||||
Forum *common.Forum
|
Guild *Guild
|
||||||
Guild *Guild
|
Page int
|
||||||
Page int
|
LastPage int
|
||||||
LastPage int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListPage is a page struct for constructing a list of every guild
|
// ListPage is a page struct for constructing a list of every guild
|
||||||
type ListPage struct {
|
type ListPage struct {
|
||||||
Title string
|
Title string
|
||||||
CurrentUser common.User
|
Header *common.Header
|
||||||
Header *common.Header
|
GuildList []*Guild
|
||||||
GuildList []*Guild
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type MemberListPage struct {
|
type MemberListPage struct {
|
||||||
Title string
|
Title string
|
||||||
CurrentUser common.User
|
Header *common.Header
|
||||||
Header *common.Header
|
ItemList []Member
|
||||||
ItemList []Member
|
Guild *Guild
|
||||||
Guild *Guild
|
Page int
|
||||||
Page int
|
LastPage int
|
||||||
LastPage int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Member is a struct representing a specific member of a guild, not to be confused with the global User struct.
|
// 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 {
|
if guildData, ok := pi.Header.ExtData.Items["guilds_current_group"]; ok {
|
||||||
guildItem := guildData.(*Guild)
|
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)
|
err := common.Templates.ExecuteTemplate(w, "guilds_view_guild.html", guildpi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.LogError(err)
|
common.LogError(err)
|
||||||
|
|
|
@ -124,7 +124,6 @@ func ForumsDeleteSubmit(w http.ResponseWriter, r *http.Request, user common.User
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.LocalError("The provided Forum ID is not a valid number.", w, r, user)
|
return common.LocalError("The provided Forum ID is not a valid number.", w, r, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.Forums.Delete(fid)
|
err = common.Forums.Delete(fid)
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return common.LocalError("The forum you're trying to delete doesn't exist.", w, r, user)
|
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 {
|
} else if err != nil {
|
||||||
return common.InternalError(err, w, r)
|
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" {
|
if r.FormValue("updated") == "1" {
|
||||||
|
|
|
@ -71,10 +71,10 @@
|
||||||
<input name="ban-duration-months" type="number" value="0" min="0" />
|
<input name="ban-duration-months" type="number" value="0" min="0" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--<div class="formrow">
|
{{/**<!--<div class="formrow">
|
||||||
<div class="formitem formlabel"><a>{{lang "profile_ban_user_reason"}}</a></div>
|
<div class="formitem formlabel"><a>{{lang "profile_ban_user_reason"}}</a></div>
|
||||||
<div class="formitem"><textarea name="ban-reason" placeholder="A really horrible person" required></textarea></div>
|
<div class="formitem"><textarea name="ban-reason" placeholder="A really horrible person" required></textarea></div>
|
||||||
</div>-->
|
</div>-->**/}}
|
||||||
<div class="formrow">
|
<div class="formrow">
|
||||||
<div class="formitem"><button name="ban-button" class="formbutton form_middle_button">{{lang "profile_ban_user_button"}}</button></div>
|
<div class="formitem"><button name="ban-button" class="formbutton form_middle_button">{{lang "profile_ban_user_button"}}</button></div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -82,9 +82,9 @@
|
||||||
</form>
|
</form>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
<div id="profile_comments_head" class="colstack_item colstack_head hash_hide">
|
{{if .ItemList}}<div id="profile_comments_head" class="colstack_item colstack_head hash_hide">
|
||||||
<div class="rowitem"><h1><a>{{lang "profile_comments_head"}}</a></h1></div>
|
<div class="rowitem"><h1><a>{{lang "profile_comments_head"}}</a></h1></div>
|
||||||
</div>
|
</div>{{end}}
|
||||||
<div id="profile_comments" class="colstack_item hash_hide">{{template "profile_comments_row.html" . }}</div>
|
<div id="profile_comments" class="colstack_item hash_hide">{{template "profile_comments_row.html" . }}</div>
|
||||||
|
|
||||||
{{if .CurrentUser.Loggedin}}
|
{{if .CurrentUser.Loggedin}}
|
||||||
|
|
Loading…
Reference in New Issue