remove members from organizations (#537)

This commit is contained in:
Michael Quigley 2024-12-09 15:04:43 -05:00
parent 84c4611d2d
commit 52333ddb69
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 54 additions and 1 deletions

View File

@ -0,0 +1,51 @@
package main
import (
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func init() {
adminDeleteCmd.AddCommand(newAdminDeleteOrgMemberCommand().cmd)
}
type adminDeleteOrgMemberCommand struct {
cmd *cobra.Command
}
func newAdminDeleteOrgMemberCommand() *adminDeleteOrgMemberCommand {
cmd := &cobra.Command{
Use: "org-member <accountEmail> <organizationToken>",
Aliases: []string{"member"},
Short: "Remove an account from an organization",
Args: cobra.ExactArgs(2),
}
command := &adminDeleteOrgMemberCommand{cmd: cmd}
cmd.Run = command.run
return command
}
func (cmd *adminDeleteOrgMemberCommand) run(_ *cobra.Command, args []string) {
env, err := environment.LoadRoot()
if err != nil {
panic(err)
}
zrok, err := env.Client()
if err != nil {
panic(err)
}
req := admin.NewRemoveOrganizationMemberParams()
req.Body.Email = args[0]
req.Body.Token = args[1]
_, err = zrok.Admin.RemoveOrganizationMember(req, mustGetAdminAuth())
if err != nil {
panic(err)
}
logrus.Infof("removed '%v' from organization '%v", args[0], args[1])
}

View File

@ -43,6 +43,8 @@ func (h *removeOrganizationMemberHandler) Handle(params admin.RemoveOrganization
return admin.NewRemoveOrganizationMemberInternalServerError()
}
logrus.Infof("removed '%v' from organization '%v'", acct.Email, org.Token)
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing transaction: %v", err)
return admin.NewRemoveOrganizationMemberInternalServerError()

View File

@ -46,7 +46,7 @@ func (str *Store) IsAccountAdminOfOrganization(acctId, orgId int, trx *sqlx.Tx)
}
func (str *Store) RemoveAccountFromOrganization(acctId, orgId int, trx *sqlx.Tx) error {
stmt, err := trx.Prepare("delete from organization_members where organization_id = $1 and account_id = $2")
stmt, err := trx.Prepare("delete from organization_members where account_id = $1 and organization_id = $2")
if err != nil {
return errors.Wrap(err, "error preparing organization_members delete statement")
}