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] thread freezing #3821

Open
5 tasks
salmad3 opened this issue Feb 24, 2025 · 2 comments
Open
5 tasks

[r/boards] thread freezing #3821

salmad3 opened this issue Feb 24, 2025 · 2 comments

Comments

@salmad3
Copy link
Member

salmad3 commented Feb 24, 2025

Context:

Thread freezing is necessary to prevent any further modifications to a specific thread upon meeting freezing criteria or as determined by CommonDAO. This includes editing its content, adding replies, flagging, or deleting it. Once frozen, the thread should be immutable regardless of any existing permissions. Only users with the freeze privilege may reverse this state by unfreezing the thread.

Follows: #3755
Related to: #3820

Acceptance Criteria:

  • Extends the Thread struct (or the Post struct when representing top-level posts) to include a Frozen boolean field.

    Example
    type Thread struct {
        ThreadID   string
        Title      string
        Author     Address
        Content    string
        Timestamp  time.Time
        Flags      []Flag
        Frozen     bool // indicates whether the thread is frozen
        // ... other fields
    }
  • Implements a FreezeThread(boardID BoardID, threadID PostID) function that:

    • Verifies that the thread is not already frozen.
    • Checks that the caller has the required freeze permission (e.g., PermissionThreadFreeze).
    • Sets the thread's Frozen flag to true, effectively blocking all modifications.
    Example
    func FreezeThread(boardID BoardID, threadID PostID) {
        board := mustGetBoard(boardID)
        thread := mustGetThread(board, threadID)
        if thread.Frozen {
            panic("thread is already frozen")
        }
    
        caller := std.GetOrigCaller()
        args := Args{boardID, threadID}
        board.perms.WithPermission(caller, PermissionThreadFreeze, args, func(Args) {
            // Double-check to handle race conditions
            thread := mustGetThread(board, threadID)
            if thread.Frozen {
                panic("thread is already frozen")
            }
            thread.Frozen = true
        })
    }
  • Creates an UnfreezeThread(boardID BoardID, threadID PostID) function that:

    • Validates that the thread is currently frozen.
    • Verifies that the caller holds the freeze/unfreeze permission.
    • Sets the Frozen flag to false.
  • Overrides Existing Permissions

    • Once a thread is frozen, all modifying actions (editing, replying, flagging, deleting, etc.) are blocked—even if the caller would normally be allowed to perform these actions.
    • Relevant functions (e.g., EditThread, DeleteThread, FlagThread) include a check for thread.Frozen and reject modifications if set.
  • Tests

    • Verifies that freezing a thread prevents any modifications.
    • Confirms that only authorized users (those with freeze permissions) can freeze or unfreeze a thread.
      -Attempting to freeze an already frozen thread results in an error.
    • Validates that once unfrozen, the thread can again be modified as normal.
@x1unix
Copy link
Contributor

x1unix commented Feb 25, 2025

Implementing this alongside #3820

@x1unix
Copy link
Contributor

x1unix commented Feb 25, 2025

#3829

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