Fossil SCM
/json/user/save now allows mixing GET/CLI and POST.payload data sources.
Commit
92b163a0692523ae7e7c96462535675d7ce7e235
Parent
34359c3ad1324ac…
1 file changed
+36
-36
+36
-36
| --- src/json_user.c | ||
| +++ src/json_user.c | ||
| @@ -212,19 +212,20 @@ | ||
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | blob_append(&sql, "UPDATE USER SET",-1 ); |
| 215 | 215 | blob_append(&sql, " mtime=cast(strftime('%s') AS INTEGER)", -1); |
| 216 | 216 | |
| 217 | - if((uid>0) && zName | |
| 218 | - && zNameOrig && (zName != zNameOrig) | |
| 219 | - && (0!=strcmp(zNameOrig,zName))){ | |
| 217 | + if((uid>0) && zName){ | |
| 220 | 218 | /* Only change the name if the uid is explicitly set and name |
| 221 | 219 | would actually change. */ |
| 222 | - if(!g.perm.Admin && !g.perm.Setup) { | |
| 223 | - json_set_err( FSL_JSON_E_DENIED, | |
| 224 | - "Modifying user names requires 'a' or 's' privileges."); | |
| 225 | - goto error; | |
| 220 | + if( zNameOrig && (zName != zNameOrig) | |
| 221 | + && (0!=strcmp(zNameOrig,zName))){ | |
| 222 | + if(!g.perm.Admin && !g.perm.Setup) { | |
| 223 | + json_set_err( FSL_JSON_E_DENIED, | |
| 224 | + "Modifying user names requires 'a' or 's' privileges."); | |
| 225 | + goto error; | |
| 226 | + } | |
| 226 | 227 | } |
| 227 | 228 | blob_appendf(&sql, ", login=%Q", zNameOrig); |
| 228 | 229 | ++gotFields; |
| 229 | 230 | } |
| 230 | 231 | |
| @@ -282,36 +283,35 @@ | ||
| 282 | 283 | ** |
| 283 | 284 | ** - Return something useful in the payload (at least the id of the |
| 284 | 285 | ** modified/created user). |
| 285 | 286 | */ |
| 286 | 287 | static cson_value * json_user_save(){ |
| 287 | - if( g.json.reqPayload.o ){ | |
| 288 | - json_user_update_from_json( g.json.reqPayload.o ); | |
| 289 | - }else{ | |
| 290 | - /* try to get user info from GET/CLI args and construct | |
| 291 | - a JSON form of it... */ | |
| 292 | - cson_object * u = cson_new_object(); | |
| 293 | - char const * str = NULL; | |
| 294 | - char b = -1; | |
| 295 | - int i = -1; | |
| 296 | -#define PROP(LK) str = json_find_option_cstr(LK,NULL,NULL); \ | |
| 297 | - if(str){ cson_object_set(u, LK, json_new_string(str)); } (void)0 | |
| 298 | - PROP("name"); | |
| 299 | - PROP("password"); | |
| 300 | - PROP("info"); | |
| 301 | - PROP("capabilities"); | |
| 302 | -#undef PROP | |
| 303 | - | |
| 304 | -#define PROP(LK,DFLT) b = json_find_option_bool(LK,NULL,NULL,DFLT); \ | |
| 305 | - if(DFLT!=b){ cson_object_set(u, LK, cson_value_new_bool(b)); } (void)0 | |
| 306 | - PROP("forceLogout",-1); | |
| 307 | -#undef PROP | |
| 308 | - | |
| 309 | -#define PROP(LK,DFLT) i = json_find_option_int(LK,NULL,NULL,DFLT); \ | |
| 310 | - if(DFLT != i){ cson_object_set(u, LK, cson_value_new_integer(i)); } (void)0 | |
| 311 | - PROP("uid",-99); | |
| 312 | -#undef PROP | |
| 313 | - json_user_update_from_json( u ); | |
| 314 | - cson_free_object(u); | |
| 315 | - } | |
| 288 | + /* try to get user info from GET/CLI args and construct | |
| 289 | + a JSON form of it... */ | |
| 290 | + cson_object * u = cson_new_object(); | |
| 291 | + char const * str = NULL; | |
| 292 | + char b = -1; | |
| 293 | + int i = -1; | |
| 294 | +#define PROP(LK) str = json_find_option_cstr(LK,NULL,NULL); \ | |
| 295 | + if(str){ cson_object_set(u, LK, json_new_string(str)); } (void)0 | |
| 296 | + PROP("name"); | |
| 297 | + PROP("password"); | |
| 298 | + PROP("info"); | |
| 299 | + PROP("capabilities"); | |
| 300 | +#undef PROP | |
| 301 | + | |
| 302 | +#define PROP(LK,DFLT) b = json_find_option_bool(LK,NULL,NULL,DFLT); \ | |
| 303 | + if(DFLT!=b){ cson_object_set(u, LK, cson_value_new_bool(b)); } (void)0 | |
| 304 | + PROP("forceLogout",-1); | |
| 305 | +#undef PROP | |
| 306 | + | |
| 307 | +#define PROP(LK,DFLT) i = json_find_option_int(LK,NULL,NULL,DFLT); \ | |
| 308 | + if(DFLT != i){ cson_object_set(u, LK, cson_value_new_integer(i)); } (void)0 | |
| 309 | + PROP("uid",-99); | |
| 310 | +#undef PROP | |
| 311 | + if( g.json.reqPayload.o ){ | |
| 312 | + cson_object_merge( u, g.json.reqPayload.o, CSON_MERGE_NO_RECURSE ); | |
| 313 | + } | |
| 314 | + json_user_update_from_json( u ); | |
| 315 | + cson_free_object(u); | |
| 316 | 316 | return NULL; |
| 317 | 317 | } |
| 318 | 318 |
| --- src/json_user.c | |
| +++ src/json_user.c | |
| @@ -212,19 +212,20 @@ | |
| 212 | } |
| 213 | |
| 214 | blob_append(&sql, "UPDATE USER SET",-1 ); |
| 215 | blob_append(&sql, " mtime=cast(strftime('%s') AS INTEGER)", -1); |
| 216 | |
| 217 | if((uid>0) && zName |
| 218 | && zNameOrig && (zName != zNameOrig) |
| 219 | && (0!=strcmp(zNameOrig,zName))){ |
| 220 | /* Only change the name if the uid is explicitly set and name |
| 221 | would actually change. */ |
| 222 | if(!g.perm.Admin && !g.perm.Setup) { |
| 223 | json_set_err( FSL_JSON_E_DENIED, |
| 224 | "Modifying user names requires 'a' or 's' privileges."); |
| 225 | goto error; |
| 226 | } |
| 227 | blob_appendf(&sql, ", login=%Q", zNameOrig); |
| 228 | ++gotFields; |
| 229 | } |
| 230 | |
| @@ -282,36 +283,35 @@ | |
| 282 | ** |
| 283 | ** - Return something useful in the payload (at least the id of the |
| 284 | ** modified/created user). |
| 285 | */ |
| 286 | static cson_value * json_user_save(){ |
| 287 | if( g.json.reqPayload.o ){ |
| 288 | json_user_update_from_json( g.json.reqPayload.o ); |
| 289 | }else{ |
| 290 | /* try to get user info from GET/CLI args and construct |
| 291 | a JSON form of it... */ |
| 292 | cson_object * u = cson_new_object(); |
| 293 | char const * str = NULL; |
| 294 | char b = -1; |
| 295 | int i = -1; |
| 296 | #define PROP(LK) str = json_find_option_cstr(LK,NULL,NULL); \ |
| 297 | if(str){ cson_object_set(u, LK, json_new_string(str)); } (void)0 |
| 298 | PROP("name"); |
| 299 | PROP("password"); |
| 300 | PROP("info"); |
| 301 | PROP("capabilities"); |
| 302 | #undef PROP |
| 303 | |
| 304 | #define PROP(LK,DFLT) b = json_find_option_bool(LK,NULL,NULL,DFLT); \ |
| 305 | if(DFLT!=b){ cson_object_set(u, LK, cson_value_new_bool(b)); } (void)0 |
| 306 | PROP("forceLogout",-1); |
| 307 | #undef PROP |
| 308 | |
| 309 | #define PROP(LK,DFLT) i = json_find_option_int(LK,NULL,NULL,DFLT); \ |
| 310 | if(DFLT != i){ cson_object_set(u, LK, cson_value_new_integer(i)); } (void)0 |
| 311 | PROP("uid",-99); |
| 312 | #undef PROP |
| 313 | json_user_update_from_json( u ); |
| 314 | cson_free_object(u); |
| 315 | } |
| 316 | return NULL; |
| 317 | } |
| 318 |
| --- src/json_user.c | |
| +++ src/json_user.c | |
| @@ -212,19 +212,20 @@ | |
| 212 | } |
| 213 | |
| 214 | blob_append(&sql, "UPDATE USER SET",-1 ); |
| 215 | blob_append(&sql, " mtime=cast(strftime('%s') AS INTEGER)", -1); |
| 216 | |
| 217 | if((uid>0) && zName){ |
| 218 | /* Only change the name if the uid is explicitly set and name |
| 219 | would actually change. */ |
| 220 | if( zNameOrig && (zName != zNameOrig) |
| 221 | && (0!=strcmp(zNameOrig,zName))){ |
| 222 | if(!g.perm.Admin && !g.perm.Setup) { |
| 223 | json_set_err( FSL_JSON_E_DENIED, |
| 224 | "Modifying user names requires 'a' or 's' privileges."); |
| 225 | goto error; |
| 226 | } |
| 227 | } |
| 228 | blob_appendf(&sql, ", login=%Q", zNameOrig); |
| 229 | ++gotFields; |
| 230 | } |
| 231 | |
| @@ -282,36 +283,35 @@ | |
| 283 | ** |
| 284 | ** - Return something useful in the payload (at least the id of the |
| 285 | ** modified/created user). |
| 286 | */ |
| 287 | static cson_value * json_user_save(){ |
| 288 | /* try to get user info from GET/CLI args and construct |
| 289 | a JSON form of it... */ |
| 290 | cson_object * u = cson_new_object(); |
| 291 | char const * str = NULL; |
| 292 | char b = -1; |
| 293 | int i = -1; |
| 294 | #define PROP(LK) str = json_find_option_cstr(LK,NULL,NULL); \ |
| 295 | if(str){ cson_object_set(u, LK, json_new_string(str)); } (void)0 |
| 296 | PROP("name"); |
| 297 | PROP("password"); |
| 298 | PROP("info"); |
| 299 | PROP("capabilities"); |
| 300 | #undef PROP |
| 301 | |
| 302 | #define PROP(LK,DFLT) b = json_find_option_bool(LK,NULL,NULL,DFLT); \ |
| 303 | if(DFLT!=b){ cson_object_set(u, LK, cson_value_new_bool(b)); } (void)0 |
| 304 | PROP("forceLogout",-1); |
| 305 | #undef PROP |
| 306 | |
| 307 | #define PROP(LK,DFLT) i = json_find_option_int(LK,NULL,NULL,DFLT); \ |
| 308 | if(DFLT != i){ cson_object_set(u, LK, cson_value_new_integer(i)); } (void)0 |
| 309 | PROP("uid",-99); |
| 310 | #undef PROP |
| 311 | if( g.json.reqPayload.o ){ |
| 312 | cson_object_merge( u, g.json.reqPayload.o, CSON_MERGE_NO_RECURSE ); |
| 313 | } |
| 314 | json_user_update_from_json( u ); |
| 315 | cson_free_object(u); |
| 316 | return NULL; |
| 317 | } |
| 318 |