-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add command update users (#968)
Co-authored-by: David Ragot <[email protected]>
- Loading branch information
Showing
26 changed files
with
1,863 additions
and
1,725 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package users | ||
|
||
import ( | ||
"fmt" | ||
|
||
fctl "github.com/formancehq/fctl/pkg" | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type UpdateStore struct { | ||
Id string `json:"id"` | ||
Email string `json:"email"` | ||
IsAdmin bool `json:"is_admin"` | ||
} | ||
type UpdateController struct { | ||
store *UpdateStore | ||
} | ||
|
||
var _ fctl.Controller[*UpdateStore] = (*UpdateController)(nil) | ||
|
||
func NewDefaultUpdateStore() *UpdateStore { | ||
return &UpdateStore{} | ||
} | ||
|
||
func NewUpdateController() *UpdateController { | ||
return &UpdateController{ | ||
store: NewDefaultUpdateStore(), | ||
} | ||
} | ||
|
||
func NewUpdateCommand() *cobra.Command { | ||
return fctl.NewCommand("update <user-id> <roles...>", | ||
fctl.WithAliases("s"), | ||
fctl.WithShortDescription("Update user roles by by id within an organization"), | ||
fctl.WithArgs(cobra.MinimumNArgs(1)), | ||
fctl.WithController[*UpdateStore](NewUpdateController()), | ||
) | ||
} | ||
|
||
func (c *UpdateController) GetStore() *UpdateStore { | ||
return c.store | ||
} | ||
|
||
func (c *UpdateController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { | ||
cfg, err := fctl.GetConfig(cmd) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
apiClient, err := fctl.NewMembershipClient(cmd, cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
organizationID, err := fctl.ResolveOrganizationID(cmd, cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
roles := []string{} | ||
roles = append(roles, args[1:]...) | ||
|
||
response, err := apiClient.DefaultApi.UpdateOrganizationUser( | ||
cmd.Context(), | ||
organizationID, | ||
args[0]).RequestBody(roles).Execute() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if response.StatusCode > 300 { | ||
return nil, fmt.Errorf("error updating user: %s", response.Status) | ||
} | ||
|
||
return c, nil | ||
} | ||
|
||
func (c *UpdateController) Render(cmd *cobra.Command, args []string) error { | ||
pterm.Success.WithWriter(cmd.OutOrStdout()).Printfln("User updated.") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
ff4c77c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
docs – ./
docs-formance.vercel.app
docs-git-main-formance.vercel.app
docs.numary.com
docs.formance.com
developers.numary.com
developers.formance.com