-
Notifications
You must be signed in to change notification settings - Fork 41
Add profile view, edit implementation #1137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0632873
23d2ab6
7bb0f2b
0067225
122925b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ type IdentityController interface { | |
| GetUserGroups(w http.ResponseWriter, r *http.Request) | ||
| GetUserRoles(w http.ResponseWriter, r *http.Request) | ||
| InviteUser(w http.ResponseWriter, r *http.Request) | ||
| UpdateCurrentUserProfile(w http.ResponseWriter, r *http.Request) | ||
|
|
||
| // Groups | ||
| ListGroups(w http.ResponseWriter, r *http.Request) | ||
|
|
@@ -1298,6 +1299,39 @@ func (c *identityController) ListAMPPermissions(w http.ResponseWriter, r *http.R | |
| utils.WriteSuccessResponse(w, http.StatusOK, map[string]any{"permissions": perms, "resourceServerId": rsID}) | ||
| } | ||
|
|
||
| // UpdateCurrentUserProfile updates the current user's profile information | ||
| func (c *identityController) UpdateCurrentUserProfile(w http.ResponseWriter, r *http.Request) { | ||
| ctx := r.Context() | ||
| log := logger.GetLogger(ctx) | ||
|
|
||
| userID := r.PathValue(utils.PathParamUserID) | ||
| if userID == "" { | ||
| utils.WriteErrorResponse(w, http.StatusBadRequest, "User ID is required") | ||
| return | ||
| } | ||
|
|
||
| var body spec.UpdateUserRequest | ||
| if err := json.NewDecoder(r.Body).Decode(&body); err != nil { | ||
| utils.WriteErrorResponse(w, http.StatusBadRequest, "Invalid request body") | ||
| return | ||
| } | ||
|
|
||
| updatedUser, err := c.client.UpdateUser(ctx, userID, thundersvc.UpdateUserRequest{ | ||
| Attributes: *body.Attributes, | ||
| }) | ||
|
Comment on lines
+1319
to
+1321
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard against nil
💡 Suggested fix var body spec.UpdateUserRequest
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, "Invalid request body")
return
}
+if body.Attributes == nil {
+ utils.WriteErrorResponse(w, http.StatusBadRequest, "Attributes are required")
+ return
+}
updatedUser, err := c.client.UpdateUser(ctx, userID, thundersvc.UpdateUserRequest{
- Attributes: *body.Attributes,
+ Attributes: body.GetAttributes(),
})🤖 Prompt for AI Agents |
||
| if err != nil { | ||
| if thundersvc.IsNotFound(err) { | ||
| utils.WriteErrorResponse(w, http.StatusNotFound, "User not found") | ||
| return | ||
| } | ||
| log.Error("UpdateCurrentUserProfile failed", "userID", userID, "error", err) | ||
| utils.WriteErrorResponse(w, http.StatusInternalServerError, "Failed to update user profile") | ||
| return | ||
| } | ||
|
|
||
| utils.WriteSuccessResponse(w, http.StatusOK, updatedUser) | ||
| } | ||
|
|
||
| // validateUserOwnership checks if a user belongs to the caller's OU | ||
| func validateUserOwnership(w http.ResponseWriter, ctx context.Context, user *thundersvc.ThunderUser, callerOuID string) bool { | ||
| if user.OuID != "" && user.OuID != callerOuID { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7932,6 +7932,63 @@ paths: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $ref: "#/components/schemas/ErrorResponse" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /orgs/{orgName}/identities/users/{userId}/profile: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| put: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| summary: Update user profile and credentials | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| operationId: updateCurrentUserProfile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tags: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Identity - Users | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: orgName | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in: path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: Organization name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: userId | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in: path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: User ID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+7935
to
+7953
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolve self-service contract ambiguity in
Suggested OpenAPI direction (self-service variant)- /orgs/{orgName}/identities/users/{userId}/profile:
+ /orgs/{orgName}/identities/users/me/profile:
put:
summary: Update user profile and credentials
operationId: updateCurrentUserProfile
tags:
- Identity - Users
parameters:
- name: orgName
in: path
required: true
description: Organization name
schema:
type: string
- - name: userId
- in: path
- required: true
- description: User ID
- schema:
- type: string📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestBody: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| application/json: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $ref: "#/components/schemas/UpdateUserRequest" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| responses: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "200": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: User profile and credentials updated successfully | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| application/json: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $ref: "#/components/schemas/UserResponse" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "400": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: Invalid request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| application/json: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $ref: "#/components/schemas/ErrorResponse" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "403": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: Forbidden - missing org context | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+7973
to
+7975
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align the 403 response description with adjacent user endpoints. Line 7963 currently documents only “missing org context”, while sibling user endpoints also include “user does not belong to organization.” Keeping this consistent avoids client-side error-handling drift for the same identity domain. 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| application/json: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $ref: "#/components/schemas/ErrorResponse" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "404": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: User not found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| application/json: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $ref: "#/components/schemas/ErrorResponse" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "500": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: Internal server error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| application/json: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $ref: "#/components/schemas/ErrorResponse" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /orgs/{orgName}/identities/groups: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| get: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| summary: List groups in an organization | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Enforce self-only profile updates before calling the admin client.
This handler trusts the path
userIDand updates that account directly, so any caller withprofile:update-attributescan target other users by ID. For a “current user profile” endpoint, bind the target user to the authenticated subject (or use/me) and reject mismatches.🤖 Prompt for AI Agents