Fossil SCM

/json/user/save now allows mixing GET/CLI and POST.payload data sources.

json-demo 2011-11-04 18:48 json-multitag-test
Commit 92b163a0692523ae7e7c96462535675d7ce7e235
1 file changed +36 -36
+36 -36
--- src/json_user.c
+++ src/json_user.c
@@ -212,19 +212,20 @@
212212
}
213213
214214
blob_append(&sql, "UPDATE USER SET",-1 );
215215
blob_append(&sql, " mtime=cast(strftime('%s') AS INTEGER)", -1);
216216
217
- if((uid>0) && zName
218
- && zNameOrig && (zName != zNameOrig)
219
- && (0!=strcmp(zNameOrig,zName))){
217
+ if((uid>0) && zName){
220218
/* Only change the name if the uid is explicitly set and name
221219
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
+ }
226227
}
227228
blob_appendf(&sql, ", login=%Q", zNameOrig);
228229
++gotFields;
229230
}
230231
@@ -282,36 +283,35 @@
282283
**
283284
** - Return something useful in the payload (at least the id of the
284285
** modified/created user).
285286
*/
286287
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);
316316
return NULL;
317317
}
318318
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button