MCPcopy Create free account
hub / github.com/netlify/gotrue / adminUserUpdate

Method adminUserUpdate

api/admin.go:91–152  ·  view source on GitHub ↗

adminUserUpdate updates a single user object

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

89
90// adminUserUpdate updates a single user object
91func (a *API) adminUserUpdate(w http.ResponseWriter, r *http.Request) error {
92 ctx := r.Context()
93 user := getUser(ctx)
94 adminUser := getAdminUser(ctx)
95 instanceID := getInstanceID(ctx)
96 params, err := a.getAdminParams(r)
97 if err != nil {
98 return err
99 }
100
101 err = a.db.Transaction(func(tx *storage.Connection) error {
102 if params.Role != "" {
103 if terr := user.SetRole(tx, params.Role); terr != nil {
104 return terr
105 }
106 }
107
108 if params.Confirm {
109 if terr := user.Confirm(tx); terr != nil {
110 return terr
111 }
112 }
113
114 if params.Password != "" {
115 if terr := user.UpdatePassword(tx, params.Password); terr != nil {
116 return terr
117 }
118 }
119
120 if params.Email != "" {
121 if terr := user.SetEmail(tx, params.Email); terr != nil {
122 return terr
123 }
124 }
125
126 if params.AppMetaData != nil {
127 if terr := user.UpdateAppMetaData(tx, params.AppMetaData); terr != nil {
128 return terr
129 }
130 }
131
132 if params.UserMetaData != nil {
133 if terr := user.UpdateUserMetaData(tx, params.UserMetaData); terr != nil {
134 return terr
135 }
136 }
137
138 if terr := models.NewAuditLogEntry(tx, instanceID, adminUser, models.UserModifiedAction, map[string]interface{}{
139 "user_id": user.ID,
140 "user_email": user.Email,
141 }); terr != nil {
142 return terr
143 }
144 return nil
145 })
146
147 if err != nil {
148 return internalServerError("Error updating user").WithInternalError(err)

Callers

nothing calls this directly

Calls 15

getAdminParamsMethod · 0.95
NewAuditLogEntryFunction · 0.92
getUserFunction · 0.85
getAdminUserFunction · 0.85
getInstanceIDFunction · 0.85
internalServerErrorFunction · 0.85
sendJSONFunction · 0.85
TransactionMethod · 0.80
SetRoleMethod · 0.80
ConfirmMethod · 0.80
UpdatePasswordMethod · 0.80
SetEmailMethod · 0.80

Tested by

no test coverage detected