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

feat(r/gnoland/home): add AdminSetOverride #2583

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/gno.land/r/gnoland/home/gno.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module gno.land/r/gnoland/home

require (
gno.land/p/demo/ownable v0.0.0-latest
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/p/demo/ui v0.0.0-latest
gno.land/r/gnoland/blog v0.0.0-latest
Expand Down
20 changes: 20 additions & 0 deletions examples/gno.land/r/gnoland/home/home.gno
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package home
import (
"std"

"gno.land/p/demo/ownable"
"gno.land/p/demo/ufmt"
"gno.land/p/demo/ui"
blog "gno.land/r/gnoland/blog"
Expand All @@ -12,7 +13,16 @@ import (
// XXX: use an updatable block system to update content from a DAO
// XXX: var blocks avl.Tree

var (
override string
admin = ownable.NewWithAddress("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq") // @manfred by default
)

func Render(_ string) string {
if override != "" {
return override
}

dom := ui.DOM{Prefix: "r/gnoland/home:"}
dom.Title = "Welcome to gno.land"
dom.Classes = []string{"gno-tmpl-section"}
Expand Down Expand Up @@ -267,3 +277,13 @@ func discoverLinks() ui.Element {
</div><!-- end columns-3-->`),
}
}

func AdminSetOverride(content string) {
admin.AssertCallerIsOwner()
override = content
}

func AdminTransferOwnership(newAdmin std.Address) {
admin.AssertCallerIsOwner()
admin.TransferOwnership(newAdmin)
}
24 changes: 24 additions & 0 deletions examples/gno.land/r/gnoland/home/overide_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"std"

"gno.land/p/demo/testutils"
"gno.land/r/gnoland/home"
)

func main() {
std.TestSetOrigCaller("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq")
home.AdminSetOverride("Hello World!")
println(home.Render(""))
home.AdminTransferOwnership(testutils.TestAddress("newAdmin"))
defer func() {
r := recover()
println("r: ", r)
}()
home.AdminSetOverride("Not admin anymore")
}

// Output:
// Hello World!
// r: unauthorized; caller is not owner
Loading