Skip to content

Commit

Permalink
feat(r/gnoland/home): add AdminSetOverride (#2583)
Browse files Browse the repository at this point in the history
My goal was to implement this for Test 4, but the current upgrade
strategy does not include contract patching.

---------

Signed-off-by: moul <94029+moul@users.noreply.github.com>
  • Loading branch information
moul authored Jul 24, 2024
1 parent 8865638 commit 691a1ba
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
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

0 comments on commit 691a1ba

Please sign in to comment.