-
Notifications
You must be signed in to change notification settings - Fork 398
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
feat(boards2): implement freeze and unfreeze for thread and reply #3829
base: devx/feature/boardsv2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package boards2 | ||
|
||
import "std" | ||
|
||
type freezeArgs struct { | ||
boardID BoardID | ||
threadID PostID | ||
replyID PostID | ||
} | ||
|
||
func (args freezeArgs) getThread() (*Post, *Board) { | ||
board := mustGetBoard(args.boardID) | ||
assertBoardIsNotFrozen(board) | ||
|
||
thread := mustGetThread(board, args.threadID) | ||
return thread, board | ||
} | ||
|
||
func (args freezeArgs) getReply() (*Post, *Board) { | ||
board := mustGetBoard(args.boardID) | ||
assertBoardIsNotFrozen(board) | ||
|
||
thread := mustGetThread(board, args.threadID) | ||
assertThreadVisible(thread) | ||
assertThreadIsNotFrozen(thread) | ||
|
||
reply := mustGetReply(thread, args.replyID) | ||
assertReplyVisible(reply) | ||
return reply, board | ||
} | ||
Comment on lines
+11
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering why not just keep using Otherwise it would make sense to just return one type per function:
|
||
|
||
func setReplyReadOnly(args freezeArgs, isReadOnly bool) { | ||
reply, board := args.getReply() | ||
|
||
if isReadOnly { | ||
// disallow freezing already frozen reply | ||
assertReplyIsNotFrozen(reply) | ||
} | ||
Comment on lines
+35
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be moved to |
||
|
||
caller := std.OriginCaller() | ||
permArgs := Args{args.boardID, args.threadID, args.replyID} | ||
board.perms.WithPermission(caller, PermissionReplyFreeze, permArgs, func(Args) { | ||
reply, _ := args.getReply() | ||
reply.SetReadOnly(isReadOnly) | ||
}) | ||
} | ||
|
||
func setThreadReadOnly(args freezeArgs, isReadOnly bool) { | ||
thread, board := args.getThread() | ||
|
||
if isReadOnly { | ||
// disallow freezing of already frozen thread | ||
assertThreadIsNotFrozen(thread) | ||
} | ||
Comment on lines
+51
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be moved to |
||
|
||
caller := std.OriginCaller() | ||
permArgs := Args{args.boardID, args.threadID} | ||
board.perms.WithPermission(caller, PermissionThreadFreeze, permArgs, func(Args) { | ||
thread, _ := args.getThread() | ||
thread.SetReadOnly(isReadOnly) | ||
}) | ||
} | ||
|
||
func setBoardReadOnly(boardID BoardID, isReadOnly bool) { | ||
board := mustGetBoard(boardID) | ||
if isReadOnly { | ||
assertBoardIsNotFrozen(board) | ||
} | ||
Comment on lines
+65
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could potentially be removed from here and left in func FreezeBoard(boardID BoardID) {
board := mustGetBoard(boardID)
assertBoardIsNotFrozen(board)
setBoardReadOnly(boardID, true)
} |
||
|
||
caller := std.OriginCaller() | ||
args := Args{boardID} | ||
board.perms.WithPermission(caller, PermissionBoardFreeze, args, func(Args) { | ||
board := mustGetBoard(boardID) | ||
board.SetReadOnly(isReadOnly) | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package main | ||
|
||
import ( | ||
"std" | ||
|
||
boards2 "gno.land/r/nt/boards2/v1" | ||
) | ||
|
||
const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 | ||
|
||
var ( | ||
bid boards2.BoardID | ||
tid boards2.PostID | ||
) | ||
|
||
func init() { | ||
std.TestSetOriginCaller(owner) | ||
bid = boards2.CreateBoard("test123") | ||
tid = boards2.CreateThread(bid, "foo", "bar") | ||
|
||
boards2.FreezeBoard(bid) | ||
} | ||
|
||
func main() { | ||
// Attempt to freeze a thread on frozen board | ||
boards2.FreezeThread(bid, tid) | ||
} | ||
|
||
// Error: | ||
// board is frozen |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package main | ||
|
||
import ( | ||
"std" | ||
|
||
boards2 "gno.land/r/nt/boards2/v1" | ||
) | ||
|
||
const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 | ||
|
||
var ( | ||
bid boards2.BoardID | ||
tid boards2.PostID | ||
) | ||
|
||
func init() { | ||
std.TestSetOriginCaller(owner) | ||
bid = boards2.CreateBoard("test123") | ||
tid = boards2.CreateThread(bid, "foo", "bar") | ||
|
||
boards2.FreezeThread(bid, tid) | ||
} | ||
|
||
func main() { | ||
// Attempt to freeze a frozen thread | ||
boards2.FreezeThread(bid, tid) | ||
} | ||
|
||
// Error: | ||
// thread is frozen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type could be removed if arguments are used in
setThreadReadOnly
andsetReplyReadOnly
functions instead of passing a type. If so, that change might simplify the code