diff --git a/cmd/query_gen/main.go b/cmd/query_gen/main.go
index d36fbc7b..a12d5bb9 100644
--- a/cmd/query_gen/main.go
+++ b/cmd/query_gen/main.go
@@ -25,12 +25,12 @@ func main() {
}()
log.Println("Running the query generator")
- for _, adapter := range qgen.Registry {
- log.Printf("Building the queries for the %s adapter", adapter.GetName())
- qgen.Install.SetAdapterInstance(adapter)
+ for _, a := range qgen.Registry {
+ log.Printf("Building the queries for the %s adapter", a.GetName())
+ qgen.Install.SetAdapterInstance(a)
qgen.Install.AddPlugins(NewPrimaryKeySpitter()) // TODO: Do we really need to fill the spitter for every adapter?
- err := writeStatements(adapter)
+ err := writeStatements(a)
if err != nil {
log.Print(err)
}
@@ -38,7 +38,7 @@ func main() {
if err != nil {
log.Print(err)
}
- err = adapter.Write()
+ err = a.Write()
if err != nil {
log.Print(err)
}
@@ -46,73 +46,31 @@ func main() {
}
// nolint
-func writeStatements(adapter qgen.Adapter) error {
- err := createTables(adapter)
- if err != nil {
- return err
+func writeStatements(a qgen.Adapter) (err error) {
+ e := func(f func(qgen.Adapter) error) {
+ if err != nil {
+ return
+ }
+ err = f(a)
}
-
- err = seedTables(adapter)
- if err != nil {
- return err
- }
-
- err = writeSelects(adapter)
- if err != nil {
- return err
- }
-
- err = writeLeftJoins(adapter)
- if err != nil {
- return err
- }
-
- err = writeInnerJoins(adapter)
- if err != nil {
- return err
- }
-
- err = writeInserts(adapter)
- if err != nil {
- return err
- }
-
- err = writeUpdates(adapter)
- if err != nil {
- return err
- }
-
- err = writeDeletes(adapter)
- if err != nil {
- return err
- }
-
- err = writeSimpleCounts(adapter)
- if err != nil {
- return err
- }
-
- err = writeInsertSelects(adapter)
- if err != nil {
- return err
- }
-
- err = writeInsertLeftJoins(adapter)
- if err != nil {
- return err
- }
-
- err = writeInsertInnerJoins(adapter)
- if err != nil {
- return err
- }
-
- return nil
+ e(createTables)
+ e(seedTables)
+ e(writeSelects)
+ e(writeLeftJoins)
+ e(writeInnerJoins)
+ e(writeInserts)
+ e(writeUpdates)
+ e(writeDeletes)
+ e(writeSimpleCounts)
+ e(writeInsertSelects)
+ e(writeInsertLeftJoins)
+ e(writeInsertInnerJoins)
+ return err
}
type si = map[string]interface{}
-func seedTables(adapter qgen.Adapter) error {
+func seedTables(a qgen.Adapter) error {
qgen.Install.AddIndex("topics", "parentID", "parentID")
qgen.Install.AddIndex("replies", "tid", "tid")
qgen.Install.AddIndex("polls", "parentID", "parentID")
diff --git a/common/phrases/phrases.go b/common/phrases/phrases.go
index c03a2b3b..96e52141 100644
--- a/common/phrases/phrases.go
+++ b/common/phrases/phrases.go
@@ -43,8 +43,7 @@ type LanguagePack struct {
// Should we use a sync map or a struct for these? It would be nice, if we could keep all the phrases consistent.
Levels LevelPhrases
- GlobalPerms map[string]string
- LocalPerms map[string]string
+ Perms map[string]string
SettingPhrases map[string]string
PermPresets map[string]string
Accounts map[string]string // TODO: Apply these phrases in the software proper
@@ -184,16 +183,8 @@ func GetLevelPhrase(level int) string {
return strings.Replace(levelPhrases.Level, "{0}", strconv.Itoa(level), -1)
}
-// TODO: Merge these two maps?
-func GetGlobalPermPhrase(name string) string {
- res, ok := currentLangPack.Load().(*LanguagePack).GlobalPerms[name]
- if !ok {
- return getPlaceholder("perms", name)
- }
- return res
-}
-func GetLocalPermPhrase(name string) string {
- res, ok := currentLangPack.Load().(*LanguagePack).LocalPerms[name]
+func GetPermPhrase(name string) string {
+ res, ok := currentLangPack.Load().(*LanguagePack).Perms[name]
if !ok {
return getPlaceholder("perms", name)
}
diff --git a/common/reply.go b/common/reply.go
index 46b5c1f0..fe2f0ca1 100644
--- a/common/reply.go
+++ b/common/reply.go
@@ -12,7 +12,7 @@ import (
"html"
"time"
- "github.com/Azareal/Gosora/query_gen"
+ qgen "github.com/Azareal/Gosora/query_gen"
)
type ReplyUser struct {
@@ -45,6 +45,7 @@ type ReplyUser struct {
ActionIcon string
Attachments []*MiniAttachment
+ Deletable bool
}
type Reply struct {
@@ -57,7 +58,7 @@ type Reply struct {
LastEdit int
LastEditBy int
ContentLines int
- IP string
+ IP string
Liked bool
LikeCount int
AttachCount int
diff --git a/common/template_init.go b/common/template_init.go
index 694b3440..0cef94a0 100644
--- a/common/template_init.go
+++ b/common/template_init.go
@@ -238,7 +238,7 @@ func compileCommons(c *tmpl.CTemplateSet, header *Header, header2 *Header, forum
}, VoteCount: 7}
avatar, microAvatar := BuildAvatar(62, "")
miniAttach := []*MiniAttachment{&MiniAttachment{Path: "/"}}
- topic := TopicUser{1, "blah", "Blah", "Hey there!", 0, false, false, now, now, 1, 1, 0, "", "127.0.0.1", 1, 0, 1, 0, "classname", poll.ID, "weird-data", BuildProfileURL("fake-user", 62), "Fake User", Config.DefaultGroup, avatar, microAvatar, 0, "", "", "", "", "", 58, false, miniAttach, nil}
+ topic := TopicUser{1, "blah", "Blah", "Hey there!", 0, false, false, now, now, 1, 1, 0, "", "127.0.0.1", 1, 0, 1, 0, "classname", poll.ID, "weird-data", BuildProfileURL("fake-user", 62), "Fake User", Config.DefaultGroup, avatar, microAvatar, 0, "", "", "", "", "", 58, false, miniAttach, nil,false}
var replyList []*ReplyUser
reply := Reply{1, 1, "Yo!", 1, Config.DefaultGroup, now, 0, 0, 1, "::1", true, 1, 1, ""}
@@ -520,7 +520,7 @@ func compileJSTemplates(wg *sync.WaitGroup, c *tmpl.CTemplateSet, themeName stri
}, VoteCount: 7}
avatar, microAvatar := BuildAvatar(62, "")
miniAttach := []*MiniAttachment{&MiniAttachment{Path: "/"}}
- topic := TopicUser{1, "blah", "Blah", "Hey there!", 62, false, false, now, now, 1, 1, 0, "", "127.0.0.1", 1, 0, 1, 0, "classname", poll.ID, "weird-data", BuildProfileURL("fake-user", 62), "Fake User", Config.DefaultGroup, avatar, microAvatar, 0, "", "", "", "", "", 58, false, miniAttach, nil}
+ topic := TopicUser{1, "blah", "Blah", "Hey there!", 62, false, false, now, now, 1, 1, 0, "", "127.0.0.1", 1, 0, 1, 0, "classname", poll.ID, "weird-data", BuildProfileURL("fake-user", 62), "Fake User", Config.DefaultGroup, avatar, microAvatar, 0, "", "", "", "", "", 58, false, miniAttach, nil,false}
var replyList []*ReplyUser
// TODO: Do we really want the UID here to be zero?
avatar, microAvatar = BuildAvatar(0, "")
diff --git a/common/topic.go b/common/topic.go
index 12638fa2..c8c84b1c 100644
--- a/common/topic.go
+++ b/common/topic.go
@@ -10,13 +10,14 @@ import (
"database/sql"
"html"
"html/template"
+
//"log"
"strconv"
"strings"
"time"
p "github.com/Azareal/Gosora/common/phrases"
- "github.com/Azareal/Gosora/query_gen"
+ qgen "github.com/Azareal/Gosora/query_gen"
)
// This is also in reply.go
@@ -38,7 +39,7 @@ type Topic struct {
LastReplyID int
ParentID int
Status string // Deprecated. Marked for removal.
- IP string
+ IP string
ViewCount int64
PostCount int
LikeCount int
@@ -64,7 +65,7 @@ type TopicUser struct {
LastReplyID int
ParentID int
Status string // Deprecated. Marked for removal.
- IP string
+ IP string
ViewCount int64
PostCount int
LikeCount int
@@ -89,6 +90,7 @@ type TopicUser struct {
Attachments []*MiniAttachment
Rids []int
+ Deletable bool
}
// TODO: Embed TopicUser to simplify this structure and it's related logic?
@@ -106,7 +108,7 @@ type TopicsRow struct {
LastReplyID int
ParentID int
Status string // Deprecated. Marked for removal. -Is there anything we could use it for?
- IP string
+ IP string
ViewCount int64
PostCount int
LikeCount int
@@ -423,10 +425,11 @@ func GetRidsForTopic(tid int, offset int) (rids []int, err error) {
}
var aipost = ";︎"
-var lockai = "🔒"+aipost
+var lockai = "🔒" + aipost
var unlockai = "🔓"
var stickai = "📌"
-var unstickai = "📌"+aipost
+var unstickai = "📌" + aipost
+
func (ru *ReplyUser) Init() error {
ru.UserLink = BuildProfileURL(NameToSlug(ru.CreatedByName), ru.CreatedBy)
ru.ContentLines = strings.Count(ru.Content, "\n")
@@ -545,6 +548,7 @@ func (t *TopicUser) Replies(offset int, pFrag int, user *User) (rlist []*ReplyUs
attachMap[reply.ID] = len(rlist)
attachQueryList = append(attachQueryList, reply.ID)
}
+ reply.Deletable = user.Perms.DeleteReply || reply.CreatedBy == user.ID
hTbl.VhookNoRet("topic_reply_row_assign", &rlist, &reply)
rlist = append(rlist, reply)
@@ -568,6 +572,7 @@ func (t *TopicUser) Replies(offset int, pFrag int, user *User) (rlist []*ReplyUs
}
reply.ContentHtml = ParseMessage(reply.Content, t.ParentID, "forums")
+ // TODO: This doesn't work properly so pick the first one instead?
if reply.ID == pFrag {
ogdesc = reply.Content
if len(ogdesc) > 200 {
@@ -583,6 +588,7 @@ func (t *TopicUser) Replies(offset int, pFrag int, user *User) (rlist []*ReplyUs
attachMap[reply.ID] = len(rlist)
attachQueryList = append(attachQueryList, reply.ID)
}
+ reply.Deletable = user.Perms.DeleteReply || reply.CreatedBy == user.ID
hTbl.VhookNoRet("topic_reply_row_assign", &rlist, &reply)
// TODO: Use a pointer instead to make it easier to abstract this loop? What impact would this have on escape analysis?
diff --git a/langs/english.json b/langs/english.json
index e578c6d7..65484bd3 100644
--- a/langs/english.json
+++ b/langs/english.json
@@ -7,7 +7,7 @@
"LevelMax": ""
},
- "GlobalPerms": {
+ "Perms": {
"BanUsers": "Can ban users",
"ActivateUsers": "Can activate users",
"EditUser": "Can edit users",
@@ -30,10 +30,8 @@
"UploadFiles": "Can upload files",
"UploadAvatars": "Can upload avatars",
- "UseConvos":"Can use conversations"
- },
-
- "LocalPerms": {
+ "UseConvos":"Can use conversations",
+
"ViewTopic": "Can view topics",
"LikeItem": "Can like items",
"CreateTopic": "Can create topics",
diff --git a/misc_test.go b/misc_test.go
index 08d2139d..9aba15af 100644
--- a/misc_test.go
+++ b/misc_test.go
@@ -1242,14 +1242,13 @@ func TestPluginManager(t *testing.T) {
}
func TestPhrases(t *testing.T) {
- getPhrase := phrases.GetGlobalPermPhrase
+ getPhrase := phrases.GetPermPhrase
tp := func(name string, expects string) {
res := getPhrase(name)
expect(t, res == expects, "Not the expected phrase, got '"+res+"' instead")
}
tp("BanUsers", "Can ban users")
tp("NoSuchPerm", "{lang.perms[NoSuchPerm]}")
- getPhrase = phrases.GetLocalPermPhrase
tp("ViewTopic", "Can view topics")
tp("NoSuchPerm", "{lang.perms[NoSuchPerm]}")
diff --git a/routes/panel/forums.go b/routes/panel/forums.go
index 2ac2ca60..db8a4c75 100644
--- a/routes/panel/forums.go
+++ b/routes/panel/forums.go
@@ -8,7 +8,7 @@ import (
"strings"
c "github.com/Azareal/Gosora/common"
- "github.com/Azareal/Gosora/common/phrases"
+ p "github.com/Azareal/Gosora/common/phrases"
)
func Forums(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError {
@@ -49,7 +49,7 @@ func Forums(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError {
}
pi := c.PanelPage{basePage, forumList, nil}
- return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage,"","","panel_forums",&pi})
+ return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "", "", "panel_forums", &pi})
}
func ForumsCreateSubmit(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError {
@@ -98,7 +98,7 @@ func ForumsDelete(w http.ResponseWriter, r *http.Request, user c.User, sfid stri
return c.InternalError(err, w, r)
}
- confirmMsg := phrases.GetTmplPhrasef("panel_forum_delete_are_you_sure", forum.Name)
+ confirmMsg := p.GetTmplPhrasef("panel_forum_delete_are_you_sure", forum.Name)
yousure := c.AreYouSure{"/panel/forums/delete/submit/" + strconv.Itoa(fid), confirmMsg}
pi := c.PanelPage{basePage, tList, yousure}
@@ -165,10 +165,10 @@ func ForumsEdit(w http.ResponseWriter, r *http.Request, user c.User, sfid string
if !user.Perms.ManageForums {
return c.NoPermissions(w, r, user)
}
-
+
fid, err := strconv.Atoi(sfid)
if err != nil {
- return c.SimpleError(phrases.GetErrorPhrase("url_id_must_be_integer"),w,r,basePage.Header)
+ return c.SimpleError(p.GetErrorPhrase("url_id_must_be_integer"), w, r, basePage.Header)
}
basePage.Header.AddScriptAsync("panel_forum_edit.js")
@@ -207,7 +207,7 @@ func ForumsEdit(w http.ResponseWriter, r *http.Request, user c.User, sfid string
}
pi := c.PanelEditForumPage{basePage, forum.ID, forum.Name, forum.Desc, forum.Active, forum.Preset, gplist}
- return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage,"","","panel_forum_edit",&pi})
+ return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "", "", "panel_forum_edit", &pi})
}
func ForumsEditSubmit(w http.ResponseWriter, r *http.Request, user c.User, sfid string) c.RouteError {
@@ -341,31 +341,30 @@ func ForumsEditPermsAdvance(w http.ResponseWriter, r *http.Request, user c.User,
}
var formattedPermList []c.NameLangToggle
-
// TODO: Load the phrases in bulk for efficiency?
// TODO: Reduce the amount of code duplication between this and the group editor. Also, can we grind this down into one line or use a code generator to stay current more easily?
- addNameLangToggle := func(permStr string, perm bool) {
- formattedPermList = append(formattedPermList, c.NameLangToggle{permStr, phrases.GetLocalPermPhrase(permStr), perm})
+ addToggle := func(permStr string, perm bool) {
+ formattedPermList = append(formattedPermList, c.NameLangToggle{permStr, p.GetPermPhrase(permStr), perm})
}
- addNameLangToggle("ViewTopic", fp.ViewTopic)
- addNameLangToggle("LikeItem", fp.LikeItem)
- addNameLangToggle("CreateTopic", fp.CreateTopic)
+ addToggle("ViewTopic", fp.ViewTopic)
+ addToggle("LikeItem", fp.LikeItem)
+ addToggle("CreateTopic", fp.CreateTopic)
//<--
- addNameLangToggle("EditTopic", fp.EditTopic)
- addNameLangToggle("DeleteTopic", fp.DeleteTopic)
- addNameLangToggle("CreateReply", fp.CreateReply)
- addNameLangToggle("EditReply", fp.EditReply)
- addNameLangToggle("DeleteReply", fp.DeleteReply)
- addNameLangToggle("PinTopic", fp.PinTopic)
- addNameLangToggle("CloseTopic", fp.CloseTopic)
- addNameLangToggle("MoveTopic", fp.MoveTopic)
+ addToggle("EditTopic", fp.EditTopic)
+ addToggle("DeleteTopic", fp.DeleteTopic)
+ addToggle("CreateReply", fp.CreateReply)
+ addToggle("EditReply", fp.EditReply)
+ addToggle("DeleteReply", fp.DeleteReply)
+ addToggle("PinTopic", fp.PinTopic)
+ addToggle("CloseTopic", fp.CloseTopic)
+ addToggle("MoveTopic", fp.MoveTopic)
if r.FormValue("updated") == "1" {
basePage.AddNotice("panel_forum_perms_updated")
}
pi := c.PanelEditForumGroupPage{basePage, forum.ID, gid, forum.Name, forum.Desc, forum.Active, forum.Preset, formattedPermList}
- return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage,"","","panel_forum_edit_perms",&pi})
+ return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "", "", "panel_forum_edit_perms", &pi})
}
func ForumsEditPermsAdvanceSubmit(w http.ResponseWriter, r *http.Request, user c.User, paramList string) c.RouteError {
@@ -376,7 +375,7 @@ func ForumsEditPermsAdvanceSubmit(w http.ResponseWriter, r *http.Request, user c
if !user.Perms.ManageForums {
return c.NoPermissions(w, r, user)
}
- js := (r.PostFormValue("js") == "1")
+ js := r.PostFormValue("js") == "1"
fid, gid, err := forumPermsExtractDash(paramList)
if err != nil {
diff --git a/routes/panel/groups.go b/routes/panel/groups.go
index 78158d23..6172fb8c 100644
--- a/routes/panel/groups.go
+++ b/routes/panel/groups.go
@@ -301,7 +301,7 @@ func GroupsEditPerms(w http.ResponseWriter, r *http.Request, user c.User, sgid s
// TODO: Load the phrases in bulk for efficiency?
var localPerms []c.NameLangToggle
addLocalPerm := func(permStr string, perm bool) {
- localPerms = append(localPerms, c.NameLangToggle{permStr, p.GetLocalPermPhrase(permStr), perm})
+ localPerms = append(localPerms, c.NameLangToggle{permStr, p.GetPermPhrase(permStr), perm})
}
addLocalPerm("ViewTopic", g.Perms.ViewTopic)
@@ -319,7 +319,7 @@ func GroupsEditPerms(w http.ResponseWriter, r *http.Request, user c.User, sgid s
var globalPerms []c.NameLangToggle
addGlobalPerm := func(permStr string, perm bool) {
- globalPerms = append(globalPerms, c.NameLangToggle{permStr, p.GetGlobalPermPhrase(permStr), perm})
+ globalPerms = append(globalPerms, c.NameLangToggle{permStr, p.GetPermPhrase(permStr), perm})
}
addGlobalPerm("BanUsers", g.Perms.BanUsers)
diff --git a/routes/reply.go b/routes/reply.go
index 0a0c9cf1..cc6bc778 100644
--- a/routes/reply.go
+++ b/routes/reply.go
@@ -214,7 +214,7 @@ func CreateReplySubmit(w http.ResponseWriter, r *http.Request, user c.User) c.Ro
// TODO: Disable stat updates in posts handled by plugin_guilds
// TODO: Update the stats after edits so that we don't under or over decrement stats during deletes
func ReplyEditSubmit(w http.ResponseWriter, r *http.Request, user c.User, srid string) c.RouteError {
- js := (r.PostFormValue("js") == "1")
+ js := r.PostFormValue("js") == "1"
rid, err := strconv.Atoi(srid)
if err != nil {
return c.PreErrorJSQ("The provided Reply ID is not a valid number.", w, r, js)
@@ -282,7 +282,7 @@ func ReplyEditSubmit(w http.ResponseWriter, r *http.Request, user c.User, srid s
// TODO: Refactor this
// TODO: Disable stat updates in posts handled by plugin_guilds
func ReplyDeleteSubmit(w http.ResponseWriter, r *http.Request, user c.User, srid string) c.RouteError {
- js := (r.PostFormValue("js") == "1")
+ js := r.PostFormValue("js") == "1"
rid, err := strconv.Atoi(srid)
if err != nil {
return c.PreErrorJSQ("The provided Reply ID is not a valid number.", w, r, js)
@@ -307,8 +307,10 @@ func ReplyDeleteSubmit(w http.ResponseWriter, r *http.Request, user c.User, srid
if ferr != nil {
return ferr
}
- if !user.Perms.ViewTopic || !user.Perms.DeleteReply {
- return c.NoPermissionsJSQ(w, r, user, js)
+ if reply.CreatedBy != user.ID {
+ if !user.Perms.ViewTopic || !user.Perms.DeleteReply {
+ return c.NoPermissionsJSQ(w, r, user, js)
+ }
}
err = reply.Delete()
@@ -501,7 +503,7 @@ func ProfileReplyCreateSubmit(w http.ResponseWriter, r *http.Request, user c.Use
}
func ProfileReplyEditSubmit(w http.ResponseWriter, r *http.Request, user c.User, srid string) c.RouteError {
- js := (r.PostFormValue("js") == "1")
+ js := r.PostFormValue("js") == "1"
rid, err := strconv.Atoi(srid)
if err != nil {
return c.LocalErrorJSQ("The provided Reply ID is not a valid number.", w, r, user, js)
@@ -537,7 +539,7 @@ func ProfileReplyEditSubmit(w http.ResponseWriter, r *http.Request, user c.User,
}
func ProfileReplyDeleteSubmit(w http.ResponseWriter, r *http.Request, user c.User, srid string) c.RouteError {
- js := (r.PostFormValue("js") == "1")
+ js := r.PostFormValue("js") == "1"
rid, err := strconv.Atoi(srid)
if err != nil {
return c.LocalErrorJSQ("The provided Reply ID is not a valid number.", w, r, user, js)
@@ -573,7 +575,7 @@ func ProfileReplyDeleteSubmit(w http.ResponseWriter, r *http.Request, user c.Use
}
func ReplyLikeSubmit(w http.ResponseWriter, r *http.Request, user c.User, srid string) c.RouteError {
- js := (r.PostFormValue("js") == "1")
+ js := r.PostFormValue("js") == "1"
rid, err := strconv.Atoi(srid)
if err != nil {
return c.PreErrorJSQ("The provided Reply ID is not a valid number.", w, r, js)
diff --git a/routes/topic.go b/routes/topic.go
index c0057312..5810abe5 100644
--- a/routes/topic.go
+++ b/routes/topic.go
@@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"io"
+
//"fmt"
"log"
"net/http"
@@ -18,7 +19,7 @@ import (
c "github.com/Azareal/Gosora/common"
"github.com/Azareal/Gosora/common/counters"
"github.com/Azareal/Gosora/common/phrases"
- "github.com/Azareal/Gosora/query_gen"
+ qgen "github.com/Azareal/Gosora/query_gen"
)
type TopicStmts struct {
@@ -44,7 +45,7 @@ func ViewTopic(w http.ResponseWriter, r *http.Request, user c.User, header *c.He
page, _ := strconv.Atoi(r.FormValue("page"))
_, tid, err := ParseSEOURL(urlBit)
if err != nil {
- return c.SimpleError(phrases.GetErrorPhrase("url_id_must_be_integer"),w,r,header)
+ return c.SimpleError(phrases.GetErrorPhrase("url_id_must_be_integer"), w, r, header)
}
// Get the topic...
@@ -82,11 +83,11 @@ func ViewTopic(w http.ResponseWriter, r *http.Request, user c.User, header *c.He
if err != nil {
return c.InternalError(err, w, r)
}
-
topic.Tag = postGroup.Tag
if postGroup.IsMod {
topic.ClassName = c.Config.StaffCSS
}
+ topic.Deletable = user.Perms.DeleteTopic || topic.CreatedBy == user.ID
forum, err := c.Forums.Get(topic.ParentID)
if err != nil {
@@ -155,8 +156,8 @@ func ViewTopic(w http.ResponseWriter, r *http.Request, user c.User, header *c.He
if tmpl == "" {
rerr = renderTemplate("topic", w, r, header, tpage)
} else {
- tmpl = "topic_"+tmpl
- err = renderTemplate3(tmpl,tmpl, w, r, header, tpage)
+ tmpl = "topic_" + tmpl
+ err = renderTemplate3(tmpl, tmpl, w, r, header, tpage)
if err != nil {
rerr = renderTemplate("topic", w, r, header, tpage)
}
@@ -328,7 +329,7 @@ func CreateTopic(w http.ResponseWriter, r *http.Request, user c.User, header *c.
func CreateTopicSubmit(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError {
fid, err := strconv.Atoi(r.PostFormValue("topic-board"))
if err != nil {
- return c.LocalError(phrases.GetErrorPhrase("id_must_be_integer"),w,r,user)
+ return c.LocalError(phrases.GetErrorPhrase("id_must_be_integer"), w, r, user)
}
// TODO: Add hooks to make use of headerLite
lite, ferr := c.SimpleForumUserCheck(w, r, &user, fid)
@@ -616,8 +617,10 @@ func DeleteTopicSubmit(w http.ResponseWriter, r *http.Request, user c.User) c.Ro
if ferr != nil {
return ferr
}
- if !user.Perms.ViewTopic || !user.Perms.DeleteTopic {
- return c.NoPermissionsJSQ(w, r, user, js)
+ if topic.CreatedBy != user.ID {
+ if !user.Perms.ViewTopic || !user.Perms.DeleteTopic {
+ return c.NoPermissionsJSQ(w, r, user, js)
+ }
}
// We might be able to handle this err better
@@ -862,7 +865,7 @@ func addTopicAction(action string, t *c.Topic, u c.User) error {
// TODO: Refactor this
func LikeTopicSubmit(w http.ResponseWriter, r *http.Request, user c.User, stid string) c.RouteError {
- js := (r.PostFormValue("js") == "1")
+ js := r.PostFormValue("js") == "1"
tid, err := strconv.Atoi(stid)
if err != nil {
return c.PreErrorJSQ(phrases.GetErrorPhrase("id_must_be_integer"), w, r, js)
diff --git a/templates/topic.html b/templates/topic.html
index 5296cbc0..529572cd 100644
--- a/templates/topic.html
+++ b/templates/topic.html
@@ -47,7 +47,7 @@
{{if .CurrentUser.Perms.EditTopic}}{{end}}
{{end}}
- {{if .CurrentUser.Perms.DeleteTopic}}{{end}}
+ {{if .Topic.Deletable}}{{end}}
{{if .CurrentUser.Perms.CloseTopic}}{{if .Topic.IsClosed}}{{else}}{{end}}{{end}}
diff --git a/templates/topic_alt.html b/templates/topic_alt.html
index ee27cafd..5f51113a 100644
--- a/templates/topic_alt.html
+++ b/templates/topic_alt.html
@@ -90,7 +90,7 @@
{{if not .Topic.IsClosed or .CurrentUser.Perms.CloseTopic}}
{{if .CurrentUser.Perms.EditTopic}}{{end}}
{{end}}
- {{if .CurrentUser.Perms.DeleteTopic}}{{end}}
+ {{if .Topic.Deletable}}{{end}}
{{if .CurrentUser.Perms.CloseTopic}}
{{if .Topic.IsClosed}}{{else}}{{end}}{{end}}
{{if .CurrentUser.Perms.PinTopic}}
diff --git a/templates/topic_alt_posts.html b/templates/topic_alt_posts.html
index f6d601cf..46558475 100644
--- a/templates/topic_alt_posts.html
+++ b/templates/topic_alt_posts.html
@@ -36,7 +36,7 @@
{{if not $.Topic.IsClosed or $.CurrentUser.Perms.CloseTopic}}
{{if $.CurrentUser.Perms.EditReply}}{{end}}
{{end}}
- {{if $.CurrentUser.Perms.DeleteReply}}{{end}}
+ {{if .Deletable}}{{end}}
{{if $.CurrentUser.Perms.ViewIPs}}{{end}}
diff --git a/templates/topic_posts.html b/templates/topic_posts.html
index 5edf370b..299dbd5f 100644
--- a/templates/topic_posts.html
+++ b/templates/topic_posts.html
@@ -5,7 +5,7 @@
{{.ActionType}}
{{else}}
-
+
{{/** TODO: We might end up with
s in the inline editor, fix this **/}}
{{.ContentHtml}}
{{if $.CurrentUser.Loggedin}}{{.Content}}
{{end}}
@@ -21,7 +21,7 @@
{{if $.CurrentUser.Perms.EditReply}}{{end}}
{{end}}
- {{if $.CurrentUser.Perms.DeleteReply}}{{end}}
+ {{if .Deletable}}{{end}}
{{if $.CurrentUser.Perms.ViewIPs}}{{end}}