mirror of
https://github.com/openziti/zrok.git
synced 2025-06-13 13:26:46 +02:00
remove members from organizations (#537)
This commit is contained in:
parent
84c4611d2d
commit
52333ddb69
51
cmd/zrok/adminDeleteOrgMember.go
Normal file
51
cmd/zrok/adminDeleteOrgMember.go
Normal 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])
|
||||||
|
}
|
@ -43,6 +43,8 @@ func (h *removeOrganizationMemberHandler) Handle(params admin.RemoveOrganization
|
|||||||
return admin.NewRemoveOrganizationMemberInternalServerError()
|
return admin.NewRemoveOrganizationMemberInternalServerError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logrus.Infof("removed '%v' from organization '%v'", acct.Email, org.Token)
|
||||||
|
|
||||||
if err := trx.Commit(); err != nil {
|
if err := trx.Commit(); err != nil {
|
||||||
logrus.Errorf("error committing transaction: %v", err)
|
logrus.Errorf("error committing transaction: %v", err)
|
||||||
return admin.NewRemoveOrganizationMemberInternalServerError()
|
return admin.NewRemoveOrganizationMemberInternalServerError()
|
||||||
|
@ -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 {
|
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 {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error preparing organization_members delete statement")
|
return errors.Wrap(err, "error preparing organization_members delete statement")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user