mirror of
https://github.com/harness/drone.git
synced 2025-05-08 13:32:38 +08:00
Update user-admin update API to use the user_uid instead of user_id
This commit is contained in:
parent
03cc7de4f2
commit
a57f4f22a9
@ -20,8 +20,8 @@ type UpdateAdminInput struct {
|
||||
|
||||
// UpdateAdmin updates the admin state of a user.
|
||||
func (c *Controller) UpdateAdmin(ctx context.Context, session *auth.Session,
|
||||
userID int64, request *UpdateAdminInput) (*types.User, error) {
|
||||
user, err := findUserFromID(ctx, c.principalStore, userID)
|
||||
userUID string, request *UpdateAdminInput) (*types.User, error) {
|
||||
user, err := findUserFromUID(ctx, c.principalStore, userUID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -13,14 +13,14 @@ import (
|
||||
"github.com/harness/gitness/internal/api/request"
|
||||
)
|
||||
|
||||
// HandleUpdateAdmin returns an http.HandlerFunc that processes an http.Request
|
||||
// HandleUpdateAdmin returns a http.HandlerFunc that processes an http.Request
|
||||
// to update the current user admin status.
|
||||
func HandleUpdateAdmin(userCtrl *user.Controller) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
session, _ := request.AuthSessionFrom(ctx)
|
||||
|
||||
userID, err := request.GetUserIDFromPath(r)
|
||||
userUID, err := request.GetUserUIDFromPath(r)
|
||||
if err != nil {
|
||||
render.BadRequestf(w, "Invalid request: %s.", err)
|
||||
return
|
||||
@ -33,7 +33,7 @@ func HandleUpdateAdmin(userCtrl *user.Controller) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
user, err := userCtrl.UpdateAdmin(ctx, session, userID, in)
|
||||
user, err := userCtrl.UpdateAdmin(ctx, session, userUID, in)
|
||||
if err != nil {
|
||||
render.TranslatedUserError(w, err)
|
||||
return
|
||||
|
@ -19,7 +19,7 @@ type createTokenRequest struct {
|
||||
}
|
||||
|
||||
type updateAdminRequest struct {
|
||||
ID int64 `path:"user_id"`
|
||||
UID string `path:"user_uid"`
|
||||
user.UpdateAdminInput
|
||||
}
|
||||
|
||||
@ -57,5 +57,5 @@ func buildUser(reflector *openapi3.Reflector) {
|
||||
_ = reflector.SetJSONResponse(&opUpdateAdmin, new(types.User), http.StatusOK)
|
||||
_ = reflector.SetJSONResponse(&opUpdateAdmin, new(usererror.Error), http.StatusNotFound)
|
||||
_ = reflector.SetJSONResponse(&opUpdateAdmin, new(usererror.Error), http.StatusInternalServerError)
|
||||
_ = reflector.Spec.AddOperation(http.MethodPatch, "/user/{user_id}/admin", opUpdateAdmin)
|
||||
_ = reflector.Spec.AddOperation(http.MethodPatch, "/user/{user_uid}/admin", opUpdateAdmin)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user