Skip to content

Commit

Permalink
Merge pull request #41 from sdslabs/VettelMajor
Browse files Browse the repository at this point in the history
Fixes Ban-Identity Route
  • Loading branch information
pratham1729 authored Dec 18, 2023
2 parents e02c324 + 2120539 commit d537ce3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
15 changes: 13 additions & 2 deletions api/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -195,6 +206,6 @@ func HandleBanIdentity(c *gin.Context) {
return
}
c.JSON(http.StatusOK, gin.H{
"identities": id,
"identity": id,
})
}
22 changes: 11 additions & 11 deletions pkg/wrapper/kratos/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit d537ce3

Please sign in to comment.