fixed bug in AmNewPost and filling in default pseud for post box
This commit is contained in:
+32
-54
@@ -137,19 +137,11 @@ func NewTopicForm(ctxt ui.AmContext) (string, any, error) {
|
||||
ctxt.VarMap().Set("conferenceName", conf.Name)
|
||||
ctxt.VarMap().Set("urlStem", fmt.Sprintf("/comm/%s/conf/%s", comm.Alias, ctxt.URLParam("confid")))
|
||||
ctxt.VarMap().Set("topicName", "")
|
||||
cs, err := conf.Settings(ctxt.Ctx(), ctxt.CurrentUser())
|
||||
pseud, err := conf.DefaultPseud(ctxt.Ctx(), ctxt.CurrentUser())
|
||||
if err != nil {
|
||||
return ui.ErrorPage(ctxt, err)
|
||||
}
|
||||
if cs == nil || cs.DefaultPseud == nil {
|
||||
ci, err := ctxt.CurrentUser().ContactInfo(ctxt.Ctx())
|
||||
if err != nil {
|
||||
return ui.ErrorPage(ctxt, err)
|
||||
}
|
||||
ctxt.VarMap().Set("pseud", ci.FullName(false))
|
||||
} else {
|
||||
ctxt.VarMap().Set("pseud", *cs.DefaultPseud)
|
||||
}
|
||||
ctxt.VarMap().Set("pseud", pseud)
|
||||
ctxt.VarMap().Set("pb", "")
|
||||
ctxt.VarMap().Set("amsterdam_pageTitle", "Create New Topic")
|
||||
return "framed_template", "new_topic.jet", nil
|
||||
@@ -524,6 +516,13 @@ func ReadPosts(ctxt ui.AmContext) (string, any, error) {
|
||||
plc.LastPost = postRange[1]
|
||||
postsPostRef := plc.AsString()
|
||||
|
||||
// Set the user's pseud.
|
||||
pseud, err := conf.DefaultPseud(ctxt.Ctx(), ctxt.CurrentUser())
|
||||
if err != nil {
|
||||
return ui.ErrorPage(ctxt, err)
|
||||
}
|
||||
ctxt.VarMap().Set("pseud", pseud)
|
||||
|
||||
// Render the output.
|
||||
ctxt.VarMap().Set("amsterdam_pageTitle", fmt.Sprintf("%s: %s", topic.Name, summaryLine))
|
||||
ctxt.VarMap().Set("topicName", topic.Name)
|
||||
@@ -589,26 +588,29 @@ func PostInTopic(ctxt ui.AmContext) (string, any, error) {
|
||||
return ui.ErrorPage(ctxt, errors.New("this topic is archived, and you do not have permission to post to it"))
|
||||
}
|
||||
|
||||
// Set the escaped version of the text into the varmap, because it'll be needed if we do anything other than redirect.
|
||||
checker, err := htmlcheck.AmNewHTMLChecker(ctxt.Ctx(), "escaper")
|
||||
if err != nil {
|
||||
return ui.ErrorPage(ctxt, err)
|
||||
}
|
||||
checker.Append(ctxt.FormField("pseud"))
|
||||
checker.Finish()
|
||||
v, _ := checker.Value()
|
||||
ctxt.VarMap().Set("pseud", v)
|
||||
postdata := ctxt.FormField("pb")
|
||||
checker.Reset()
|
||||
checker.Append(postdata)
|
||||
checker.Finish()
|
||||
v, _ = checker.Value()
|
||||
ctxt.VarMap().Set("pb", v)
|
||||
|
||||
// also set the "attach" flag into the post data
|
||||
if ctxt.FormFieldIsSet("attach") {
|
||||
ctxt.VarMap().Set("attachFile", true)
|
||||
}
|
||||
|
||||
if ctxt.FormFieldIsSet("preview") {
|
||||
// Preview the post.
|
||||
checker, err := htmlcheck.AmNewHTMLChecker(ctxt.Ctx(), "escaper")
|
||||
if err != nil {
|
||||
return ui.ErrorPage(ctxt, err)
|
||||
}
|
||||
checker.Append(ctxt.FormField("pseud"))
|
||||
checker.Finish()
|
||||
v, _ := checker.Value()
|
||||
ctxt.VarMap().Set("pseud", v)
|
||||
|
||||
// escape the data
|
||||
postdata := ctxt.FormField("pb")
|
||||
checker.Reset()
|
||||
checker.Append(postdata)
|
||||
checker.Finish()
|
||||
v, _ = checker.Value()
|
||||
ctxt.VarMap().Set("pb", v)
|
||||
|
||||
// run the preview
|
||||
checker, err = htmlcheck.AmNewHTMLChecker(ctxt.Ctx(), "preview")
|
||||
if err != nil {
|
||||
return ui.ErrorPage(ctxt, err)
|
||||
@@ -622,9 +624,6 @@ func PostInTopic(ctxt ui.AmContext) (string, any, error) {
|
||||
ctxt.VarMap().Set("nError", nErr)
|
||||
|
||||
ctxt.VarMap().Set("maxPost", ctxt.FormField("xp"))
|
||||
if ctxt.FormFieldIsSet("attach") {
|
||||
ctxt.VarMap().Set("attachFile", true)
|
||||
}
|
||||
ctxt.VarMap().Set("urlStem", urlStem)
|
||||
ctxt.VarMap().Set("amsterdam_pageTitle", "Previewing Message")
|
||||
return "framed_template", "preview_post.jet", nil
|
||||
@@ -652,27 +651,6 @@ func PostInTopic(ctxt ui.AmContext) (string, any, error) {
|
||||
return ui.ErrorPage(ctxt, err)
|
||||
}
|
||||
|
||||
// start with escaping the post data
|
||||
checker, err := htmlcheck.AmNewHTMLChecker(ctxt.Ctx(), "escaper")
|
||||
if err != nil {
|
||||
return ui.ErrorPage(ctxt, err)
|
||||
}
|
||||
checker.Append(ctxt.FormField("pseud"))
|
||||
checker.Finish()
|
||||
v, _ := checker.Value()
|
||||
ctxt.VarMap().Set("pseud", v)
|
||||
|
||||
// escape the data
|
||||
postdata := ctxt.FormField("pb")
|
||||
checker.Reset()
|
||||
checker.Append(postdata)
|
||||
checker.Finish()
|
||||
v, _ = checker.Value()
|
||||
ctxt.VarMap().Set("pb", v)
|
||||
if ctxt.FormFieldIsSet("attach") {
|
||||
ctxt.VarMap().Set("attachFile", true)
|
||||
}
|
||||
|
||||
plc := database.AmCreatePostLinkContext("", ctxt.GetScratch("currentAlias").(string), topic.Number)
|
||||
topicConferenceRef := plc.AsString()
|
||||
plc.Community = comm.Alias
|
||||
@@ -692,8 +670,8 @@ func PostInTopic(ctxt ui.AmContext) (string, any, error) {
|
||||
|
||||
return "framed_template", "slippage.jet", nil
|
||||
}
|
||||
// start by checking the title and pseud
|
||||
checker, err := htmlcheck.AmNewHTMLChecker(ctxt.Ctx(), "post-pseud")
|
||||
// if we get here, we are posting - start by checking the title and pseud
|
||||
checker, err = htmlcheck.AmNewHTMLChecker(ctxt.Ctx(), "post-pseud")
|
||||
if err != nil {
|
||||
return ui.ErrorPage(ctxt, err)
|
||||
}
|
||||
|
||||
@@ -178,6 +178,22 @@ func (c *Conference) Settings(ctx context.Context, u *User) (*ConferenceSettings
|
||||
return &(dbdata[0]), nil
|
||||
}
|
||||
|
||||
// DefaultPseud returns the default pseud for a user in the conference.
|
||||
func (c *Conference) DefaultPseud(ctx context.Context, u *User) (string, error) {
|
||||
settings, err := c.Settings(ctx, u)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if settings != nil && settings.DefaultPseud != nil {
|
||||
return *settings.DefaultPseud, nil
|
||||
}
|
||||
ci, err := u.ContactInfo(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return ci.FullName(false), nil
|
||||
}
|
||||
|
||||
// TouchUpdate updates the "last update" date/time in the conference.
|
||||
func (c *Conference) TouchUpdate(ctx context.Context, tx *sqlx.Tx, lastUpdate time.Time) error {
|
||||
_, err := tx.ExecContext(ctx, "UPDATE confs SET lastupdate = ? WHERE confid = ?", lastUpdate, c.ConfId)
|
||||
|
||||
+1
-1
@@ -178,7 +178,7 @@ func AmNewPost(ctx context.Context, conf *Conference, topic *Topic, user *User,
|
||||
hdr := &(dbdata[0])
|
||||
|
||||
// Add the post data.
|
||||
_, err = tx.ExecContext(ctx, "INSERT INTO postdata (postid, data) VALUES (?, ?)", int32(xid), hdr.PostId)
|
||||
_, err = tx.ExecContext(ctx, "INSERT INTO postdata (postid, data) VALUES (?, ?)", hdr.PostId, post)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+1
-1
@@ -113,7 +113,7 @@
|
||||
<div>
|
||||
<label for="pseud" class="block text-black text-sm font-medium mb-2">Your name/header:</label>
|
||||
<div class="flex items-center gap-4">
|
||||
<input type="text" id="pseud" name="pseud" size="37" maxlength="255" value="System Administrator"
|
||||
<input type="text" id="pseud" name="pseud" size="37" maxlength="255" value="{{ pseud }}"
|
||||
class="flex-1 px-3 py-2 border border-gray-300 rounded font-mono focus:outline-none focus:ring-2 focus:ring-blue-500">
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" id="attach" name="attach" value="Y" class="w-4 h-4 text-blue-600 border-gray-300 rounded">
|
||||
|
||||
Reference in New Issue
Block a user