Skip to content

Commit

Permalink
feat(boards2): board creation and permissions (gnolang#3211)
Browse files Browse the repository at this point in the history
Related to gnolang#3140
  • Loading branch information
jeronimoalbi authored and x1unix committed Jan 6, 2025
1 parent a2a9113 commit 5f64241
Show file tree
Hide file tree
Showing 22 changed files with 941 additions and 463 deletions.
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

0 comments on commit 5f64241

Please sign in to comment.