-
Notifications
You must be signed in to change notification settings - Fork 379
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: add r/gnoland/pages #874
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
090f3c8
feat: add r/gnoland/pages
moul 163d944
chore: fixup
moul 5c9f42b
chore: fixup
moul c7251fc
chore: fixup
moul 6b4f6ac
chore: fixup
moul 073dcae
chore: fixup
moul 5816273
Merge branch 'master' into dev/moul/addpages
moul 4deba8c
chore: add gno.mod
moul 7602ad6
Update examples/gno.land/r/gnoland/pages/admin.gno
moul bfab596
Merge branch 'master' into dev/moul/addpages
moul fc3ce83
chore: fix tests
moul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package gnopages | ||
|
||
import ( | ||
"std" | ||
"strings" | ||
|
||
"gno.land/p/demo/avl" | ||
) | ||
|
||
var ( | ||
adminAddr std.Address | ||
moderatorList avl.Tree | ||
inPause bool | ||
) | ||
|
||
func init() { | ||
// adminAddr = std.GetOrigCaller() // FIXME: find a way to use this from the main's genesis. | ||
adminAddr = "g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq" | ||
} | ||
|
||
func AdminSetAdminAddr(addr std.Address) { | ||
assertIsAdmin() | ||
adminAddr = addr | ||
} | ||
|
||
func AdminSetInPause(state bool) { | ||
assertIsAdmin() | ||
inPause = state | ||
} | ||
|
||
func AdminAddModerator(addr std.Address) { | ||
assertIsAdmin() | ||
moderatorList.Set(addr.String(), true) | ||
} | ||
|
||
func AdminRemoveModerator(addr std.Address) { | ||
assertIsAdmin() | ||
moderatorList.Set(addr.String(), false) // XXX: delete instead? | ||
} | ||
|
||
func ModAddPost(slug, title, body, tags string) { | ||
assertIsModerator() | ||
|
||
caller := std.GetOrigCaller() | ||
tagList := strings.Split(tags, ",") | ||
err := b.NewPost(caller, slug, title, body, tagList) | ||
checkErr(err) | ||
} | ||
|
||
func ModEditPost(slug, title, body, tags string) { | ||
assertIsModerator() | ||
|
||
tagList := strings.Split(tags, ",") | ||
err := b.GetPost(slug).Update(title, body, tagList) | ||
checkErr(err) | ||
} | ||
|
||
func isAdmin(addr std.Address) bool { | ||
return addr == adminAddr | ||
} | ||
|
||
func isModerator(addr std.Address) bool { | ||
_, found := moderatorList.Get(addr.String()) | ||
return found | ||
} | ||
|
||
func assertIsAdmin() { | ||
caller := std.GetOrigCaller() | ||
if !isAdmin(caller) { | ||
panic("access restricted.") | ||
} | ||
} | ||
|
||
func assertIsModerator() { | ||
caller := std.GetOrigCaller() | ||
if isAdmin(caller) || isModerator(caller) { | ||
return | ||
} | ||
panic("access restricted") | ||
} | ||
|
||
func assertNotInPause() { | ||
if inPause { | ||
panic("access restricted (pause)") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module gno.land/r/gnoland/pages | ||
|
||
require ( | ||
"gno.land/p/demo/avl" v0.0.0-latest | ||
"gno.land/p/demo/blog" v0.0.0-latest | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package gnopages | ||
|
||
import ( | ||
"gno.land/p/demo/blog" | ||
) | ||
|
||
var b = &blog.Blog{ | ||
Title: "Gnoland's Pages", | ||
Prefix: "/r/gnoland/pages:", | ||
} | ||
|
||
func init() { | ||
_ = b.NewPost("", "gor", "Game of Realms", "Lorem Ipsum", nil) | ||
_ = b.NewPost("", "events", "Events", "Lorem Ipsum", nil) | ||
_ = b.NewPost("", "tokenomics", "Tokenomics", "Lorem Ipsum", nil) | ||
_ = b.NewPost("", "start", "Getting Started", "Lorem Ipsum", nil) | ||
} | ||
|
||
func Render(path string) string { | ||
return b.Render(path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package gnopages | ||
|
||
import ( | ||
"std" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestPackage(t *testing.T) { | ||
std.TestSetOrigCaller(std.Address("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq")) | ||
|
||
author := std.GetOrigCaller() | ||
|
||
// by default, lorem ipsum posts | ||
{ | ||
got := Render("") | ||
expected := ` | ||
# Gnoland's Pages | ||
|
||
## [▸ Events](/r/gnoland/pages:p/events) | ||
|
||
## [▸ Game of Realms](/r/gnoland/pages:p/gor) | ||
|
||
## [▸ Getting Started](/r/gnoland/pages:p/start) | ||
|
||
## [▸ Tokenomics](/r/gnoland/pages:p/tokenomics) | ||
` | ||
assertMDEquals(t, got, expected) | ||
} | ||
} | ||
|
||
func assertMDEquals(t *testing.T, got, expected string) { | ||
t.Helper() | ||
expected = strings.TrimSpace(expected) | ||
got = strings.TrimSpace(got) | ||
if expected != got { | ||
t.Errorf("invalid render output.\nexpected %q.\ngot %q.", expected, got) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package gnopages | ||
|
||
func checkErr(err error) { | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
shall we open an issue for this?
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.
Just check, I think we already have one, it’s related to the thing we said about having a way to skip the need of faucet for local development, where we could imagine having a detection of accounts on the FS to automatically craft a genesis.
Note that we already have a system which patches the genesis to have a dynamic hostname.
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.
Can't we set this value in the
init
method (constructor)?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.
We can, but not with « auto-genesis »; we need to have the auto-genesis taking an account as argument to simulate the initial uploaded.