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(boards2): board creation and permissions #3211

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
19 changes: 19 additions & 0 deletions examples/gno.land/p/demo/boards2/admindao/admindao.gno
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package admindao

import (
"errors"
"std"

"gno.land/p/demo/avl"
Expand All @@ -9,6 +10,9 @@ import (
// TODO: Add support for proposals
// TODO: Add support for events

// ErrMemberExists indicates that a member is already part of the DAO.
var ErrMemberExists = errors.New("member already exist")

// AdminDAO defines a Boards administration DAO.
type AdminDAO struct {
parent *AdminDAO
Expand Down Expand Up @@ -40,6 +44,21 @@ func (dao AdminDAO) Members() []std.Address {
return members
}

// AddMember adds a new member to the DAO.
func (dao *AdminDAO) AddMember(user std.Address) error {
if dao.IsMember(user) {
return ErrMemberExists
}
dao.members.Set(user.String(), struct{}{})
return nil
}

// RemoveMember removes a member from the DAO.
func (dao *AdminDAO) RemoveMember(user std.Address) (removed bool) {
_, removed = dao.members.Remove(user.String())
return removed
}

// IsMember checks if a user is a member of the DAO.
func (dao AdminDAO) IsMember(user std.Address) bool {
return dao.members.Has(user.String())
Expand Down
24 changes: 24 additions & 0 deletions examples/gno.land/p/demo/boards2/admindao/admindao_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,30 @@ func TestNew(t *testing.T) {
}
}

func TestAdminDAOAddMember(t *testing.T) {
member := std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
dao := New(WithMember("g1w4ek2u33ta047h6lta047h6lta047h6ldvdwpn"))

err := dao.AddMember(member)
urequire.NoError(t, err)
uassert.Equal(t, 2, len(dao.Members()))
uassert.True(t, dao.IsMember(member))

err = dao.AddMember(member)
uassert.ErrorIs(t, err, ErrMemberExists)
}

func TestAdminDAORemoveMember(t *testing.T) {
member := std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
dao := New(WithMember(member))

removed := dao.RemoveMember(member)
urequire.True(t, removed)

removed = dao.RemoveMember(member)
urequire.False(t, removed)
}

func TestAdminDAOIsMember(t *testing.T) {
cases := []struct {
name string
Expand Down
100 changes: 0 additions & 100 deletions examples/gno.land/r/demo/boards2/acl.gno

This file was deleted.

30 changes: 0 additions & 30 deletions examples/gno.land/r/demo/boards2/acl_options.gno

This file was deleted.

Loading
Loading