@@ -83,26 +83,16 @@ func (s *Server) encryptAllUsersAndIdentities(apiContext api.Context) error {
83
83
}
84
84
85
85
func (s * Server ) getUser (apiContext api.Context ) error {
86
- var (
87
- getByID = apiContext .URL .Query ().Get ("by-id" ) == "true"
88
- usernameOrID = apiContext .PathValue ("username_or_id" )
89
- user * types.User
90
- )
86
+ userID := apiContext .PathValue ("user_id" )
91
87
92
- if usernameOrID == "" {
93
- return types2 .NewErrHTTP (http .StatusBadRequest , "username path parameter is required" )
94
- }
95
-
96
- var err error
97
- if getByID {
98
- user , err = apiContext .GatewayClient .UserByID (apiContext .Context (), usernameOrID )
99
- } else {
100
- user , err = apiContext .GatewayClient .User (apiContext .Context (), usernameOrID )
88
+ if userID == "" {
89
+ return types2 .NewErrHTTP (http .StatusBadRequest , "user_id path parameter is required" )
101
90
}
102
91
92
+ user , err := apiContext .GatewayClient .UserByID (apiContext .Context (), userID )
103
93
if err != nil {
104
94
if errors .Is (err , gorm .ErrRecordNotFound ) {
105
- return types2 .NewErrNotFound ("user %s not found" , usernameOrID )
95
+ return types2 .NewErrNotFound ("user %s not found" , userID )
106
96
}
107
97
return fmt .Errorf ("failed to get user: %v" , err )
108
98
}
@@ -111,16 +101,9 @@ func (s *Server) getUser(apiContext api.Context) error {
111
101
}
112
102
113
103
func (s * Server ) updateUser (apiContext api.Context ) error {
114
- requestingUsername := apiContext .User .GetName ()
115
- actingUserIsAdmin := apiContext .UserIsAdmin ()
116
-
117
- username := apiContext .PathValue ("username" )
118
- if username == "" {
119
- return types2 .NewErrHTTP (http .StatusBadRequest , "username path parameter is required" )
120
- }
121
-
122
- if ! actingUserIsAdmin && requestingUsername != username {
123
- return types2 .NewErrHTTP (http .StatusForbidden , "only admins can update other users" )
104
+ userID := apiContext .PathValue ("user_id" )
105
+ if userID == "" {
106
+ return types2 .NewErrHTTP (http .StatusBadRequest , "user_id path parameter is required" )
124
107
}
125
108
126
109
user := new (types.User )
@@ -135,7 +118,7 @@ func (s *Server) updateUser(apiContext api.Context) error {
135
118
}
136
119
137
120
status := http .StatusInternalServerError
138
- existingUser , err := apiContext .GatewayClient .UpdateUser (apiContext .Context (), actingUserIsAdmin , user , username )
121
+ existingUser , err := apiContext .GatewayClient .UpdateUser (apiContext .Context (), apiContext . UserIsAdmin () , user , userID )
139
122
if err != nil {
140
123
if errors .Is (err , gorm .ErrRecordNotFound ) {
141
124
status = http .StatusNotFound
@@ -161,14 +144,14 @@ func (s *Server) markUserExternal(apiContext api.Context) error {
161
144
}
162
145
163
146
func (s * Server ) changeUserInternalStatus (apiContext api.Context , internal bool ) error {
164
- username := apiContext .PathValue ("username " )
165
- if username == "" {
166
- return types2 .NewErrHTTP (http .StatusBadRequest , "username path parameter is required" )
147
+ userID := apiContext .PathValue ("user_id " )
148
+ if userID == "" {
149
+ return types2 .NewErrHTTP (http .StatusBadRequest , "user_id path parameter is required" )
167
150
}
168
151
169
- if err := apiContext .GatewayClient .UpdateUserInternalStatus (apiContext .Context (), username , internal ); err != nil {
152
+ if err := apiContext .GatewayClient .UpdateUserInternalStatus (apiContext .Context (), userID , internal ); err != nil {
170
153
if errors .Is (err , gorm .ErrRecordNotFound ) {
171
- return types2 .NewErrNotFound ("user %s not found" , username )
154
+ return types2 .NewErrNotFound ("user %s not found" , userID )
172
155
}
173
156
return types2 .NewErrHTTP (http .StatusInternalServerError , fmt .Sprintf ("failed to update user: %v" , err ))
174
157
}
@@ -177,10 +160,10 @@ func (s *Server) changeUserInternalStatus(apiContext api.Context, internal bool)
177
160
}
178
161
179
162
func (s * Server ) deleteUser (apiContext api.Context ) (err error ) {
180
- username := apiContext .PathValue ("username " )
181
- if username == "" {
163
+ userID := apiContext .PathValue ("user_id " )
164
+ if userID == "" {
182
165
// This is the "delete me" API
183
- username = apiContext .User .GetName ()
166
+ userID = apiContext .User .GetUID ()
184
167
defer func () {
185
168
if err == nil {
186
169
// If everything was successful, remove the cookie so the user isn't authenticated again.
@@ -189,16 +172,16 @@ func (s *Server) deleteUser(apiContext api.Context) (err error) {
189
172
}()
190
173
}
191
174
192
- existingUser , err := apiContext .GatewayClient .User (apiContext .Context (), username )
175
+ existingUser , err := apiContext .GatewayClient .UserByID (apiContext .Context (), userID )
193
176
if err != nil {
194
177
if errors .Is (err , gorm .ErrRecordNotFound ) {
195
- return types2 .NewErrNotFound ("user %s not found" , username )
178
+ return types2 .NewErrNotFound ("user %s not found" , userID )
196
179
}
197
180
return fmt .Errorf ("failed to get user: %v" , err )
198
181
}
199
182
200
183
status := http .StatusInternalServerError
201
- _ , err = apiContext .GatewayClient .DeleteUser (apiContext .Context (), apiContext .Storage , username )
184
+ _ , err = apiContext .GatewayClient .DeleteUser (apiContext .Context (), apiContext .Storage , userID )
202
185
if err != nil {
203
186
if errors .Is (err , gorm .ErrRecordNotFound ) {
204
187
status = http .StatusNotFound
0 commit comments