Skip to content
quarry Artifact [4e91272451]
Login

Artifact [4e91272451]

Artifact 4e9127245174fc27bf7a06625a4801a69f3ab77332c929018bc267305690f572:


package oltp

import "testing"

// An author sees their OWN held submissions and nobody else's.
//
// A staged post lives in forum_staged and never in the DAG, and every
// forum surface reads the DAG — so its author could not see it and
// concluded the post had failed. jva measured the whole silence from a
// non-moderator account: invisible in forum.list, invisible on the
// page, 403 on the queue, and the rejection reason published in a
// modlog the author is never pointed at (G-118).
//
// The other half of the assertion matters as much: this must not become
// a second way to read the queue. Reading the queue takes the
// moderation letter; reading your own held post does not.
func TestStagedMineIsYoursAndOnlyYours(t *testing.T) {
	db := testDB(t)
	if _, err := db.StagePost("r", "post", "", "eve's post", "b", "text/x-markdown", "eve"); err != nil {
		t.Fatal(err)
	}
	if _, err := db.StagePost("r", "reply", "root1", "jan's reply", "b", "text/x-markdown", "jan"); err != nil {
		t.Fatal(err)
	}

	mine, err := db.StagedMine("r", "eve")
	if err != nil {
		t.Fatal(err)
	}
	if len(mine) != 1 || mine[0].Author != "eve" || mine[0].Title != "eve's post" {
		t.Fatalf("eve's own held submissions = %+v", mine)
	}
	if len(mine) > 0 && mine[0].State != "pending" {
		t.Errorf("state = %q, want pending: the author is told THAT it is held and not what "+
			"is happening to it", mine[0].State)
	}

	// Not a queue read by another name.
	for _, who := range []string{"jan", "mallory"} {
		got, err := db.StagedMine("r", who)
		if err != nil {
			t.Fatal(err)
		}
		for _, s := range got {
			if s.Author != who {
				t.Errorf("%s was shown %s's held submission: this is a queue read without "+
					"the moderation letter", who, s.Author)
			}
		}
	}

	// A signed-out reader has no own-content to see, and asking must not
	// answer with everyone's.
	if got, err := db.StagedMine("r", ""); err != nil || len(got) != 0 {
		t.Errorf("anonymous got %+v (err=%v), want nothing", got, err)
	}

	// Resolved submissions leave: the list is what is WAITING, not a history.
	if err := db.ResolveStaged("r", 1, "approved"); err != nil {
		t.Fatal(err)
	}
	if got, _ := db.StagedMine("r", "eve"); len(got) != 0 {
		t.Errorf("an approved submission is still listed as waiting: %+v", got)
	}
}