Fossil SCM

Allow users with permission '4' but not 'B' to post attachments to the forum but unconditionally hold them for moderation. Issues: (A) does not yet work with the standalone attachment page. (B) is only accessible via the forum edit button and can still can only submit after doing a preview, making attachment-only changes slightly annoying (but possible).

stephan 2026-11-09 12:45 UTC trunk
Commit c9b8b676f62dcfc5705a2689534dc32e05cc4818dbcc3c99564f596376768416
+6 -1
--- src/builtin.c
+++ src/builtin.c
@@ -697,11 +697,16 @@
697697
CX("};\n"/*window.fossil.config.forum*/);
698698
#define JBOOL(COND) ((COND) ? "true" : "false")
699699
CX("window.fossil.user = {");
700700
CX("name: %!j,", (g.zLogin&&*g.zLogin) ? g.zLogin : "guest");
701701
CX("isAdmin: %s,", JBOOL(g.perm.Admin || g.perm.Setup));
702
- CX("mayAttachForum: %s,", JBOOL(g.perm.AttachForum));
702
+ CX("mayAttachForum: %d,", g.perm.AttachForum
703
+ ? 1 : (g.perm.WrForum
704
+ ? -1 : 0))
705
+ /* 0 = no, 1 = 'B' permissions,
706
+ ** -1 = moderated attachments. Potential TODO is a setting
707
+ ** to enable this. */;
703708
CX("enableDebug: %s,", JBOOL(g.perm.Debug || g.perm.Admin));
704709
CX("isIndividual: %s", JBOOL(login_is_individual()));
705710
CX("};\n"/*fossil.user*/);
706711
{ /* Workaround for cases like:
707712
** https://fossil-scm.org/forum/forumpost/31cc00b361496cb8
708713
--- src/builtin.c
+++ src/builtin.c
@@ -697,11 +697,16 @@
697 CX("};\n"/*window.fossil.config.forum*/);
698 #define JBOOL(COND) ((COND) ? "true" : "false")
699 CX("window.fossil.user = {");
700 CX("name: %!j,", (g.zLogin&&*g.zLogin) ? g.zLogin : "guest");
701 CX("isAdmin: %s,", JBOOL(g.perm.Admin || g.perm.Setup));
702 CX("mayAttachForum: %s,", JBOOL(g.perm.AttachForum));
 
 
 
 
 
703 CX("enableDebug: %s,", JBOOL(g.perm.Debug || g.perm.Admin));
704 CX("isIndividual: %s", JBOOL(login_is_individual()));
705 CX("};\n"/*fossil.user*/);
706 { /* Workaround for cases like:
707 ** https://fossil-scm.org/forum/forumpost/31cc00b361496cb8
708
--- src/builtin.c
+++ src/builtin.c
@@ -697,11 +697,16 @@
697 CX("};\n"/*window.fossil.config.forum*/);
698 #define JBOOL(COND) ((COND) ? "true" : "false")
699 CX("window.fossil.user = {");
700 CX("name: %!j,", (g.zLogin&&*g.zLogin) ? g.zLogin : "guest");
701 CX("isAdmin: %s,", JBOOL(g.perm.Admin || g.perm.Setup));
702 CX("mayAttachForum: %d,", g.perm.AttachForum
703 ? 1 : (g.perm.WrForum
704 ? -1 : 0))
705 /* 0 = no, 1 = 'B' permissions,
706 ** -1 = moderated attachments. Potential TODO is a setting
707 ** to enable this. */;
708 CX("enableDebug: %s,", JBOOL(g.perm.Debug || g.perm.Admin));
709 CX("isIndividual: %s", JBOOL(login_is_individual()));
710 CX("};\n"/*fossil.user*/);
711 { /* Workaround for cases like:
712 ** https://fossil-scm.org/forum/forumpost/31cc00b361496cb8
713
+16 -9
--- src/forum.c
+++ src/forum.c
@@ -2238,12 +2238,12 @@
22382238
}
22392239
forum_render_debug_options();
22402240
login_insert_csrf_secret();
22412241
@ </form>
22422242
/* When JS is disabled the block above will work. When it's
2243
- enabled, the above will be removed and JS will render the editor
2244
- form in the next element. */
2243
+ ** enabled, the above will be removed and JS will render the editor
2244
+ ** form in the next element. */
22452245
@ <div hidden id='forumnew-placeholder'>
22462246
@ <input type='hidden' name='title' value='%h(zTitle)'>
22472247
login_insert_csrf_secret();
22482248
@ </div>
22492249
forum_render_attachment_notice();
@@ -3243,15 +3243,15 @@
32433243
return rc;
32443244
}
32453245
/*
32463246
** WEBPAGE: forumajax_save hidden
32473247
**
3248
-** WIP
3248
+** Used by the forum JS pages to save a post.
32493249
**
32503250
** Response JSON:
32513251
**
3252
-** { uuid: hash, ...tbd }
3252
+** { uuid: hash, ...TO DOCUMENT }
32533253
*/
32543254
void forum_ajax_save_page(void){
32553255
const char *zFpid;
32563256
const char *zTitle;
32573257
const char *zIrt;
@@ -3267,22 +3267,27 @@
32673267
int nrid = 0; /* New artifact rid. */
32683268
int iPostFlags; /* forum_post_flags() (after perms check) */
32693269
int bRollback; /* True = roll back. */
32703270
int nAttach = 0; /* Number of attachments added */
32713271
int bStatusSet = 0; /* True if status tag set. */
3272
+ int bNeedsModeration = -1; /* -1 = we don't yet know */
32723273
32733274
if( !ajax_route_bootstrap(0, 1) ){
32743275
return;
3275
- }else if( !g.perm.WrForum
3276
- || (bHasAttachment && !g.perm.AttachForum) ){
3276
+ }else if( !g.perm.WrForum ){
32773277
ajax_route_error_forbidden();
32783278
return;
32793279
}else if( !ajax_check_csrf(2) ){
32803280
ajax_route_error_csrf();
32813281
return;
32823282
}
32833283
3284
+ if( bHasAttachment && !g.perm.AttachForum && g.perm.WrTForum ){
3285
+ /* 2026-11-09: a user with WrForum but not AttachForum may attach
3286
+ ** but they'll be moderated. */
3287
+ bNeedsModeration = 1;
3288
+ }
32843289
iPostFlags = forum_post_flags(/*must come after permissions init*/);
32853290
bRollback = (FPOST_DRYRUN & iPostFlags);
32863291
zFpid = P("fpid");
32873292
zIrt = P("firt");
32883293
zMimetype = P("mimetype");
@@ -3345,18 +3350,20 @@
33453350
CX("{\"message\": \"Rolled back for dry-run.\","
33463351
"\"iPostFlags\":%d}\n", iPostFlags);
33473352
}
33483353
goto ajax_save_end;
33493354
}else{
3350
- const int bNeedsModeration = forum_need_moderation();
33513355
const int fpHead = forumpost_head_rid(nrid);
33523356
assert( nrid>0 );
33533357
assert( fpHead>0 );
3358
+ if( bNeedsModeration<0 ){
3359
+ bNeedsModeration = forum_need_moderation();
3360
+ }
33543361
zNewUuid = rid_to_uuid(nrid);
3355
- if( 0!=P("file1") ){
3362
+ if( bHasAttachment ){
33563363
/* Attachments */
3357
- if( !g.perm.Admin && !g.perm.AttachForum ){
3364
+ if( !g.perm.Admin && !(g.perm.AttachForum ||g.perm.WrTForum) ){
33583365
rc = -ajax_route_error(403, "No permission no attach files.");
33593366
goto ajax_save_end;
33603367
}else{
33613368
char *zRoot = (nrid==fpHead) ? 0 : rid_to_uuid(fpHead);
33623369
nAttach = attachments_ajax_from_POST(zRoot ? zRoot : zNewUuid,
33633370
--- src/forum.c
+++ src/forum.c
@@ -2238,12 +2238,12 @@
2238 }
2239 forum_render_debug_options();
2240 login_insert_csrf_secret();
2241 @ </form>
2242 /* When JS is disabled the block above will work. When it's
2243 enabled, the above will be removed and JS will render the editor
2244 form in the next element. */
2245 @ <div hidden id='forumnew-placeholder'>
2246 @ <input type='hidden' name='title' value='%h(zTitle)'>
2247 login_insert_csrf_secret();
2248 @ </div>
2249 forum_render_attachment_notice();
@@ -3243,15 +3243,15 @@
3243 return rc;
3244 }
3245 /*
3246 ** WEBPAGE: forumajax_save hidden
3247 **
3248 ** WIP
3249 **
3250 ** Response JSON:
3251 **
3252 ** { uuid: hash, ...tbd }
3253 */
3254 void forum_ajax_save_page(void){
3255 const char *zFpid;
3256 const char *zTitle;
3257 const char *zIrt;
@@ -3267,22 +3267,27 @@
3267 int nrid = 0; /* New artifact rid. */
3268 int iPostFlags; /* forum_post_flags() (after perms check) */
3269 int bRollback; /* True = roll back. */
3270 int nAttach = 0; /* Number of attachments added */
3271 int bStatusSet = 0; /* True if status tag set. */
 
3272
3273 if( !ajax_route_bootstrap(0, 1) ){
3274 return;
3275 }else if( !g.perm.WrForum
3276 || (bHasAttachment && !g.perm.AttachForum) ){
3277 ajax_route_error_forbidden();
3278 return;
3279 }else if( !ajax_check_csrf(2) ){
3280 ajax_route_error_csrf();
3281 return;
3282 }
3283
 
 
 
 
 
3284 iPostFlags = forum_post_flags(/*must come after permissions init*/);
3285 bRollback = (FPOST_DRYRUN & iPostFlags);
3286 zFpid = P("fpid");
3287 zIrt = P("firt");
3288 zMimetype = P("mimetype");
@@ -3345,18 +3350,20 @@
3345 CX("{\"message\": \"Rolled back for dry-run.\","
3346 "\"iPostFlags\":%d}\n", iPostFlags);
3347 }
3348 goto ajax_save_end;
3349 }else{
3350 const int bNeedsModeration = forum_need_moderation();
3351 const int fpHead = forumpost_head_rid(nrid);
3352 assert( nrid>0 );
3353 assert( fpHead>0 );
 
 
 
3354 zNewUuid = rid_to_uuid(nrid);
3355 if( 0!=P("file1") ){
3356 /* Attachments */
3357 if( !g.perm.Admin && !g.perm.AttachForum ){
3358 rc = -ajax_route_error(403, "No permission no attach files.");
3359 goto ajax_save_end;
3360 }else{
3361 char *zRoot = (nrid==fpHead) ? 0 : rid_to_uuid(fpHead);
3362 nAttach = attachments_ajax_from_POST(zRoot ? zRoot : zNewUuid,
3363
--- src/forum.c
+++ src/forum.c
@@ -2238,12 +2238,12 @@
2238 }
2239 forum_render_debug_options();
2240 login_insert_csrf_secret();
2241 @ </form>
2242 /* When JS is disabled the block above will work. When it's
2243 ** enabled, the above will be removed and JS will render the editor
2244 ** form in the next element. */
2245 @ <div hidden id='forumnew-placeholder'>
2246 @ <input type='hidden' name='title' value='%h(zTitle)'>
2247 login_insert_csrf_secret();
2248 @ </div>
2249 forum_render_attachment_notice();
@@ -3243,15 +3243,15 @@
3243 return rc;
3244 }
3245 /*
3246 ** WEBPAGE: forumajax_save hidden
3247 **
3248 ** Used by the forum JS pages to save a post.
3249 **
3250 ** Response JSON:
3251 **
3252 ** { uuid: hash, ...TO DOCUMENT }
3253 */
3254 void forum_ajax_save_page(void){
3255 const char *zFpid;
3256 const char *zTitle;
3257 const char *zIrt;
@@ -3267,22 +3267,27 @@
3267 int nrid = 0; /* New artifact rid. */
3268 int iPostFlags; /* forum_post_flags() (after perms check) */
3269 int bRollback; /* True = roll back. */
3270 int nAttach = 0; /* Number of attachments added */
3271 int bStatusSet = 0; /* True if status tag set. */
3272 int bNeedsModeration = -1; /* -1 = we don't yet know */
3273
3274 if( !ajax_route_bootstrap(0, 1) ){
3275 return;
3276 }else if( !g.perm.WrForum ){
 
3277 ajax_route_error_forbidden();
3278 return;
3279 }else if( !ajax_check_csrf(2) ){
3280 ajax_route_error_csrf();
3281 return;
3282 }
3283
3284 if( bHasAttachment && !g.perm.AttachForum && g.perm.WrTForum ){
3285 /* 2026-11-09: a user with WrForum but not AttachForum may attach
3286 ** but they'll be moderated. */
3287 bNeedsModeration = 1;
3288 }
3289 iPostFlags = forum_post_flags(/*must come after permissions init*/);
3290 bRollback = (FPOST_DRYRUN & iPostFlags);
3291 zFpid = P("fpid");
3292 zIrt = P("firt");
3293 zMimetype = P("mimetype");
@@ -3345,18 +3350,20 @@
3350 CX("{\"message\": \"Rolled back for dry-run.\","
3351 "\"iPostFlags\":%d}\n", iPostFlags);
3352 }
3353 goto ajax_save_end;
3354 }else{
 
3355 const int fpHead = forumpost_head_rid(nrid);
3356 assert( nrid>0 );
3357 assert( fpHead>0 );
3358 if( bNeedsModeration<0 ){
3359 bNeedsModeration = forum_need_moderation();
3360 }
3361 zNewUuid = rid_to_uuid(nrid);
3362 if( bHasAttachment ){
3363 /* Attachments */
3364 if( !g.perm.Admin && !(g.perm.AttachForum ||g.perm.WrTForum) ){
3365 rc = -ajax_route_error(403, "No permission no attach files.");
3366 goto ajax_save_end;
3367 }else{
3368 char *zRoot = (nrid==fpHead) ? 0 : rid_to_uuid(fpHead);
3369 nAttach = attachments_ajax_from_POST(zRoot ? zRoot : zNewUuid,
3370
--- src/fossil.attach.js
+++ src/fossil.attach.js
@@ -138,11 +138,10 @@
138138
}
139139
}else{
140140
this.#updateControls();
141141
}
142142
}
143
-
144143
145144
get widget(){
146145
return this.#e.body;
147146
}
148147
149148
--- src/fossil.attach.js
+++ src/fossil.attach.js
@@ -138,11 +138,10 @@
138 }
139 }else{
140 this.#updateControls();
141 }
142 }
143
144
145 get widget(){
146 return this.#e.body;
147 }
148
149
--- src/fossil.attach.js
+++ src/fossil.attach.js
@@ -138,11 +138,10 @@
138 }
139 }else{
140 this.#updateControls();
141 }
142 }
 
143
144 get widget(){
145 return this.#e.body;
146 }
147
148
--- src/fossil.page.forumpost.js
+++ src/fossil.page.forumpost.js
@@ -337,11 +337,11 @@
337337
}
338338
});
339339
}
340340
}/*e.status*/
341341
342
- if( F.user.mayAttachForum ){
342
+ if( 0!==F.user.mayAttachForum ){
343343
//e.buttons.append( e.button.addAttach = this.#att.takeAddButton() );
344344
e.tabAttach = D.div();
345345
e.tabAttach.setAttribute('id', idPrefix+'-attach');
346346
e.tabAttach.dataset.tabLabel = 'Attachments';
347347
this.#tabs.addTab(e.tabAttach);
@@ -588,23 +588,35 @@
588588
589589
#initAttacherTab(){
590590
this.#att = new F.Attacher({
591591
reverse: true
592592
});
593
- if( this.#opt.edit ){
593
+ if( this.#opt.edit && F.user.mayAttachForum>0 ){
594
+ /* -----------------^^^^ standalone attachment page does not
595
+ ** yet honor the F.user.mayAttachForum<0 case. */
594596
const eNote = D.append(
595597
D.div(),
596598
"Tip: attachments can be added to posts without editing them ",
597599
"by visiting ",
598600
D.attr(
599601
D.a(F.repoUrl('attachadd?target='+this.#opt.edit.uuid), '/attachadd'),
600602
'target',
601603
'_new'
602604
),
603
- ".",
605
+ "."
604606
);
605607
this.#e.tabAttach.append(eNote);
608
+ }
609
+ if( F.user.mayAttachForum < 0 ){
610
+ /* Users with permission '4' (forum unmoderated) but not 'B'
611
+ ** (forum-attach) may attach files but they will undergo
612
+ ** moderation. */
613
+ const w = D.div();
614
+ w.append("Your attachments will be held "+
615
+ "for moderation.");
616
+ w.classList.add('warning');
617
+ this.#e.tabAttach.append(w);
606618
}
607619
this.#e.tabAttach.append(this.#att.widget);
608620
}
609621
610622
#newFormData(addThisContent){
611623
--- src/fossil.page.forumpost.js
+++ src/fossil.page.forumpost.js
@@ -337,11 +337,11 @@
337 }
338 });
339 }
340 }/*e.status*/
341
342 if( F.user.mayAttachForum ){
343 //e.buttons.append( e.button.addAttach = this.#att.takeAddButton() );
344 e.tabAttach = D.div();
345 e.tabAttach.setAttribute('id', idPrefix+'-attach');
346 e.tabAttach.dataset.tabLabel = 'Attachments';
347 this.#tabs.addTab(e.tabAttach);
@@ -588,23 +588,35 @@
588
589 #initAttacherTab(){
590 this.#att = new F.Attacher({
591 reverse: true
592 });
593 if( this.#opt.edit ){
 
 
594 const eNote = D.append(
595 D.div(),
596 "Tip: attachments can be added to posts without editing them ",
597 "by visiting ",
598 D.attr(
599 D.a(F.repoUrl('attachadd?target='+this.#opt.edit.uuid), '/attachadd'),
600 'target',
601 '_new'
602 ),
603 ".",
604 );
605 this.#e.tabAttach.append(eNote);
 
 
 
 
 
 
 
 
 
 
606 }
607 this.#e.tabAttach.append(this.#att.widget);
608 }
609
610 #newFormData(addThisContent){
611
--- src/fossil.page.forumpost.js
+++ src/fossil.page.forumpost.js
@@ -337,11 +337,11 @@
337 }
338 });
339 }
340 }/*e.status*/
341
342 if( 0!==F.user.mayAttachForum ){
343 //e.buttons.append( e.button.addAttach = this.#att.takeAddButton() );
344 e.tabAttach = D.div();
345 e.tabAttach.setAttribute('id', idPrefix+'-attach');
346 e.tabAttach.dataset.tabLabel = 'Attachments';
347 this.#tabs.addTab(e.tabAttach);
@@ -588,23 +588,35 @@
588
589 #initAttacherTab(){
590 this.#att = new F.Attacher({
591 reverse: true
592 });
593 if( this.#opt.edit && F.user.mayAttachForum>0 ){
594 /* -----------------^^^^ standalone attachment page does not
595 ** yet honor the F.user.mayAttachForum<0 case. */
596 const eNote = D.append(
597 D.div(),
598 "Tip: attachments can be added to posts without editing them ",
599 "by visiting ",
600 D.attr(
601 D.a(F.repoUrl('attachadd?target='+this.#opt.edit.uuid), '/attachadd'),
602 'target',
603 '_new'
604 ),
605 "."
606 );
607 this.#e.tabAttach.append(eNote);
608 }
609 if( F.user.mayAttachForum < 0 ){
610 /* Users with permission '4' (forum unmoderated) but not 'B'
611 ** (forum-attach) may attach files but they will undergo
612 ** moderation. */
613 const w = D.div();
614 w.append("Your attachments will be held "+
615 "for moderation.");
616 w.classList.add('warning');
617 this.#e.tabAttach.append(w);
618 }
619 this.#e.tabAttach.append(this.#att.widget);
620 }
621
622 #newFormData(addThisContent){
623
+1 -1
--- src/style.c
+++ src/style.c
@@ -505,11 +505,11 @@
505505
** the ID of the <span> that surrounds the display text and the ID
506506
** of the <button> becomes "copy-%s" where %s is filled in by zTargetId.
507507
** If zTargetId is NULL (the usual case) then IDs are selected automatically.
508508
**
509509
** The bOutputCGI parameter is usually true, meaning that the output
510
-** is appended to the CGI result under construction. However, if
510
+** is appended to the CGI result under construction. However, if
511511
** bOutputCGI is false, the generated HTML is written into memory
512512
** obtained from fossil_malloc() and returned.
513513
**
514514
** If the bAfter argument is non-zero, the copy button is displayed
515515
** after the text. Normally the copy button comes before the text.
516516
--- src/style.c
+++ src/style.c
@@ -505,11 +505,11 @@
505 ** the ID of the <span> that surrounds the display text and the ID
506 ** of the <button> becomes "copy-%s" where %s is filled in by zTargetId.
507 ** If zTargetId is NULL (the usual case) then IDs are selected automatically.
508 **
509 ** The bOutputCGI parameter is usually true, meaning that the output
510 ** is appended to the CGI result under construction. However, if
511 ** bOutputCGI is false, the generated HTML is written into memory
512 ** obtained from fossil_malloc() and returned.
513 **
514 ** If the bAfter argument is non-zero, the copy button is displayed
515 ** after the text. Normally the copy button comes before the text.
516
--- src/style.c
+++ src/style.c
@@ -505,11 +505,11 @@
505 ** the ID of the <span> that surrounds the display text and the ID
506 ** of the <button> becomes "copy-%s" where %s is filled in by zTargetId.
507 ** If zTargetId is NULL (the usual case) then IDs are selected automatically.
508 **
509 ** The bOutputCGI parameter is usually true, meaning that the output
510 ** is appended to the CGI result under construction. However, if
511 ** bOutputCGI is false, the generated HTML is written into memory
512 ** obtained from fossil_malloc() and returned.
513 **
514 ** If the bAfter argument is non-zero, the copy button is displayed
515 ** after the text. Normally the copy button comes before the text.
516

Keyboard Shortcuts

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