Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[r/boards] post freezing #3820

Open
4 tasks
salmad3 opened this issue Feb 24, 2025 · 1 comment
Open
4 tasks

[r/boards] post freezing #3820

salmad3 opened this issue Feb 24, 2025 · 1 comment

Comments

@salmad3
Copy link
Member

salmad3 commented Feb 24, 2025

Context:

Freezing posts (i.e., individual replies or comments within a thread) is aimed at ensuring that once a post is frozen, it becomes completely immutable. This prevents any further editing, deletion, or flagging actions, even if the post’s author or a moderator would normally be allowed to modify it.

Follows: #3755
Related to:

Acceptance Criteria:

  • Updates the Post (or reply/comment) struct to include a Frozen boolean field.

    Example
    type Post struct {
        PostID    string
        ParentID  string    // if empty, this is a thread; if set, it's a reply/comment
        Author    Address
        Content   string
        Timestamp time.Time
        Flags     []Flag
        Frozen    bool // indicates whether the post is frozen
        // ... other fields
    }
  • Implements a FreezePost(boardID BoardID, threadID PostID, postID PostID) function that:

    • Checks that the specified post is not already frozen.
    • Validates the caller's permission to freeze posts (e.g., PermissionPostFreeze).
    • Sets the post’s Frozen flag to true to block any further modifications.
    Example
    func FreezePost(boardID BoardID, threadID PostID, postID PostID) {
        board := mustGetBoard(boardID)
        thread := mustGetThread(board, threadID)
        post := mustGetReply(thread, postID) // assuming posts are accessed via replies in a thread
        if post.Frozen {
            panic("post is already frozen")
        }
    
        caller := std.GetOrigCaller()
        args := Args{boardID, threadID, postID}
        board.perms.WithPermission(caller, PermissionPostFreeze, args, func(Args) {
            // Re-check the post to ensure it hasn't been frozen in the meantime
            post := mustGetReply(thread, postID)
            if post.Frozen {
                panic("post is already frozen")
            }
            post.Frozen = true
        })
    }
  • Provides an UnfreezePost(boardID BoardID, threadID PostID, postID PostID) function that:

    • Validates that the post is currently frozen.
    • Checks that the caller is authorized to perform the unfreeze operation.
    • Resets the Frozen flag to false.
  • Overrides Existing Permissions

    • Once a post is frozen, any actions that would normally modify it (editing, deleting, adding flags, etc.) are blocked.
    • Relevant post-modification functions check for the Frozen state and respond with an error or panic if true.
  • Tests

    • Confirms that a frozen post cannot be edited, deleted, or flagged.
    • Ensures that only users with the freeze permission can freeze or unfreeze a post.
    • Attempting to freeze an already frozen post results in an appropriate error.
    • Validate that once a post is unfrozen, normal modifications are allowed again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Triage
Development

No branches or pull requests

2 participants