Browse Source

Add functions for adding groups of Admins, Owners, Readers, and Writers to teams

main
Sam 6 years ago
parent
commit
c468039d94
  1. 84
      team.go
  2. 4
      types.go

84
team.go

@ -22,7 +22,7 @@ func teamAPIOut(keybasePath string, w TeamAPI) (TeamAPI, error) {
return r, nil return r, nil
} }
// AddUser adds members to a team by username // AddUser adds a member to a team by username
func (t Team) AddUser(user, role string) (TeamAPI, error) { func (t Team) AddUser(user, role string) (TeamAPI, error) {
m := TeamAPI{ m := TeamAPI{
Params: &tParams{}, Params: &tParams{},
@ -37,7 +37,87 @@ func (t Team) AddUser(user, role string) (TeamAPI, error) {
} }
r, err := teamAPIOut(t.keybase.Path, m) r, err := teamAPIOut(t.keybase.Path, m)
if err == nil { if err == nil && r.Error == nil {
r, err = t.MemberList()
}
return r, err
}
// AddReaders adds members to a team by username, and sets their roles to Reader
func (t Team) AddReaders(users ...string) (TeamAPI, error) {
m := TeamAPI{
Params: &tParams{},
}
m.Method = "add-members"
m.Params.Options.Team = t.Name
addUsers := []usernames{}
for _, u := range users {
addUsers = append(addUsers, usernames{Username: u, Role: "reader"})
}
m.Params.Options.Usernames = addUsers
r, err := teamAPIOut(t.keybase.Path, m)
if err == nil && r.Error == nil {
r, err = t.MemberList()
}
return r, err
}
// AddWriters adds members to a team by username, and sets their roles to Writer
func (t Team) AddWriters(users ...string) (TeamAPI, error) {
m := TeamAPI{
Params: &tParams{},
}
m.Method = "add-members"
m.Params.Options.Team = t.Name
addUsers := []usernames{}
for _, u := range users {
addUsers = append(addUsers, usernames{Username: u, Role: "writer"})
}
m.Params.Options.Usernames = addUsers
r, err := teamAPIOut(t.keybase.Path, m)
if err == nil && r.Error == nil {
r, err = t.MemberList()
}
return r, err
}
// AddAdmins adds members to a team by username, and sets their roles to Writer
func (t Team) AddAdmins(users ...string) (TeamAPI, error) {
m := TeamAPI{
Params: &tParams{},
}
m.Method = "add-members"
m.Params.Options.Team = t.Name
addUsers := []usernames{}
for _, u := range users {
addUsers = append(addUsers, usernames{Username: u, Role: "admin"})
}
m.Params.Options.Usernames = addUsers
r, err := teamAPIOut(t.keybase.Path, m)
if err == nil && r.Error == nil {
r, err = t.MemberList()
}
return r, err
}
// AddOwners adds members to a team by username, and sets their roles to Writer
func (t Team) AddOwners(users ...string) (TeamAPI, error) {
m := TeamAPI{
Params: &tParams{},
}
m.Method = "add-members"
m.Params.Options.Team = t.Name
addUsers := []usernames{}
for _, u := range users {
addUsers = append(addUsers, usernames{Username: u, Role: "owner"})
}
m.Params.Options.Usernames = addUsers
r, err := teamAPIOut(t.keybase.Path, m)
if err == nil && r.Error == nil {
r, err = t.MemberList() r, err = t.MemberList()
} }
return r, err return r, err

4
types.go

@ -429,7 +429,11 @@ type Team struct {
} }
type team interface { type team interface {
AddAdmins(users ...string) (TeamAPI, error)
AddOwners(users ...string) (TeamAPI, error)
AddReaders(users ...string) (TeamAPI, error)
AddUser(user, role string) (TeamAPI, error) AddUser(user, role string) (TeamAPI, error)
AddWriters(users ...string) (TeamAPI, error)
CreateSubteam(name string) (TeamAPI, error) CreateSubteam(name string) (TeamAPI, error)
MemberList() (TeamAPI, error) MemberList() (TeamAPI, error)
} }

Loading…
Cancel
Save