mirror of
https://github.com/harness/drone.git
synced 2025-05-12 23:20:10 +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.
|
// UpdateAdmin updates the admin state of a user.
|
||||||
func (c *Controller) UpdateAdmin(ctx context.Context, session *auth.Session,
|
func (c *Controller) UpdateAdmin(ctx context.Context, session *auth.Session,
|
||||||
userID int64, request *UpdateAdminInput) (*types.User, error) {
|
userUID string, request *UpdateAdminInput) (*types.User, error) {
|
||||||
user, err := findUserFromID(ctx, c.principalStore, userID)
|
user, err := findUserFromUID(ctx, c.principalStore, userUID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -13,14 +13,14 @@ import (
|
|||||||
"github.com/harness/gitness/internal/api/request"
|
"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.
|
// to update the current user admin status.
|
||||||
func HandleUpdateAdmin(userCtrl *user.Controller) http.HandlerFunc {
|
func HandleUpdateAdmin(userCtrl *user.Controller) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
session, _ := request.AuthSessionFrom(ctx)
|
session, _ := request.AuthSessionFrom(ctx)
|
||||||
|
|
||||||
userID, err := request.GetUserIDFromPath(r)
|
userUID, err := request.GetUserUIDFromPath(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
render.BadRequestf(w, "Invalid request: %s.", err)
|
render.BadRequestf(w, "Invalid request: %s.", err)
|
||||||
return
|
return
|
||||||
@ -33,7 +33,7 @@ func HandleUpdateAdmin(userCtrl *user.Controller) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err := userCtrl.UpdateAdmin(ctx, session, userID, in)
|
user, err := userCtrl.UpdateAdmin(ctx, session, userUID, in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
render.TranslatedUserError(w, err)
|
render.TranslatedUserError(w, err)
|
||||||
return
|
return
|
||||||
|
@ -19,7 +19,7 @@ type createTokenRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type updateAdminRequest struct {
|
type updateAdminRequest struct {
|
||||||
ID int64 `path:"user_id"`
|
UID string `path:"user_uid"`
|
||||||
user.UpdateAdminInput
|
user.UpdateAdminInput
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,5 +57,5 @@ func buildUser(reflector *openapi3.Reflector) {
|
|||||||
_ = reflector.SetJSONResponse(&opUpdateAdmin, new(types.User), http.StatusOK)
|
_ = reflector.SetJSONResponse(&opUpdateAdmin, new(types.User), http.StatusOK)
|
||||||
_ = reflector.SetJSONResponse(&opUpdateAdmin, new(usererror.Error), http.StatusNotFound)
|
_ = reflector.SetJSONResponse(&opUpdateAdmin, new(usererror.Error), http.StatusNotFound)
|
||||||
_ = reflector.SetJSONResponse(&opUpdateAdmin, new(usererror.Error), http.StatusInternalServerError)
|
_ = 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