diff --git a/api/admin.go b/api/admin.go index 0616fd1..44843d7 100644 --- a/api/admin.go +++ b/api/admin.go @@ -184,7 +184,18 @@ func HandleBanIdentity(c *gin.Context) { return } - id, r, err := admin.BanIdentityFlowWrapper(t.Identity) + identityResult, r, err := admin.GetIdentityFlowWrapper(t.Identity) + + if err != nil { + log.ErrorLogger("Error while fetching Identity details", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Internal server error", + }) + return + } + + id, r, err := admin.BanIdentityFlowWrapper(identityResult) if err != nil { log.ErrorLogger("Error while calling `AdminPatchIdentities`", err) @@ -195,6 +206,6 @@ func HandleBanIdentity(c *gin.Context) { return } c.JSON(http.StatusOK, gin.H{ - "identities": id, + "identity": id, }) } diff --git a/pkg/wrapper/kratos/admin/admin.go b/pkg/wrapper/kratos/admin/admin.go index 27bb09f..e24da94 100644 --- a/pkg/wrapper/kratos/admin/admin.go +++ b/pkg/wrapper/kratos/admin/admin.go @@ -47,18 +47,18 @@ func ListIdentityFlowWrapper() ([]client.Identity, *http.Response, error) { } -func BanIdentityFlowWrapper(identity string) (*client.Identity, *http.Response, error) { - apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) - - jsonPatch := []client.JsonPatch{ - { - From: nil, - Op: "replace", - Path: "/active", - Value: false, - }, +func BanIdentityFlowWrapper(identity *client.Identity) (*client.Identity, *http.Response, error) { + newState, err := client.NewIdentityStateFromValue("inactive") + if err != nil { + return nil, nil, err } - id, r, err := apiClient.V0alpha2Api.AdminPatchIdentity(context.Background(), identity).JsonPatch(jsonPatch).Execute() + + identity.Traits.(map[string]interface{})["active"] = false + + submitDataBody := *client.NewAdminUpdateIdentityBody(identity.SchemaId, *newState, identity.Traits.(map[string]interface{})) + + apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) + id, r, err := apiClient.V0alpha2Api.AdminUpdateIdentity(context.Background(), identity.Id).AdminUpdateIdentityBody(submitDataBody).Execute() return id, r, err }