Fossil SCM

This change ostensibly lets /attachadd deal with the new permission case, but it unconditionally redirects the test user to /login for reasons not yet clear.

stephan 2026-11-09 13:03 UTC forum-attach-moderated
Commit a73f05baa817de4e3529f8c31b8ad1b394fd758985126b49d6b79eef1834d5c4
+26 -10
--- src/attach.c
+++ src/attach.c
@@ -177,11 +177,12 @@
177177
int attach_user_may(int rid, int eArtifactType){
178178
if( g.perm.Admin ) return 1;
179179
if( !login_is_individual() ) return 0;
180180
switch(eArtifactType){
181181
case CFTYPE_FORUM:
182
- return g.perm.AttachForum && forumpost_is_owner(rid, 0);
182
+ return (g.perm.AttachForum || g.perm.WrTForum)
183
+ && forumpost_is_owner(rid, 0);
183184
case CFTYPE_WIKI:
184185
return g.perm.ApndWiki && g.perm.Attach;
185186
case CFTYPE_TICKET:
186187
return g.perm.ApndTkt && g.perm.Attach;
187188
case CFTYPE_EVENT:
@@ -645,11 +646,11 @@
645646
char *zTargetType = 0;
646647
char *zExtraFree = 0;
647648
int szContent;
648649
int goodCaptcha = 1;
649650
int szLimit = 0;
650
-
651
+ int bNeedsModeration = -1; /* -1==don't yet know */
651652
if( P("target")!=0 ){
652653
attachaddV2_page();
653654
return;
654655
}
655656
zPage = P("page");
@@ -670,12 +671,16 @@
670671
}
671672
login_check_credentials();
672673
if( zForumPost ){
673674
int fpid;
674675
if( g.perm.AttachForum==0 ){
675
- login_needed(g.anon.AttachForum);
676
- return;
676
+ if( g.perm.WrTForum ){
677
+ bNeedsModeration = 1;
678
+ }else{
679
+ login_needed(g.anon.AttachForum);
680
+ return;
681
+ }
677682
}
678683
fpid = forumpost_head_rid2(zForumPost);
679684
if( fpid<=0 ){
680685
webpage_error("Invalid forum post ID: %h", zForumPost);
681686
}else if( !g.perm.Admin && !forumpost_is_owner(fpid, 0) ){
@@ -737,14 +742,17 @@
737742
/* Fall through and render form. */
738743
}else if( P("ok")
739744
&& cgi_csrf_safe(2)
740745
&& szContent>0
741746
&& (goodCaptcha = captcha_is_correct(0)) ){
742
- int needModerator = (zForumPost!=0 && forum_need_moderation()) ||
743
- (zTkt!=0 && ticket_need_moderation(0)) ||
744
- (zPage!=0 && wiki_need_moderation(0));
745
- attach_commit(zName, zTarget, aContent, szContent, needModerator, zComment);
747
+ if( bNeedsModeration<0 ){
748
+ bNeedsModeration = (zForumPost!=0 && forum_need_moderation()) ||
749
+ (zTkt!=0 && ticket_need_moderation(0)) ||
750
+ (zPage!=0 && wiki_need_moderation(0));
751
+ }
752
+ attach_commit(zName, zTarget, aContent, szContent,
753
+ bNeedsModeration, zComment);
746754
cgi_redirect(zTo ? zTo : zFrom);
747755
}
748756
749757
style_set_current_feature("attach");
750758
style_header("Add Attachment");
@@ -804,11 +812,17 @@
804812
db_rollback_transaction();
805813
return;
806814
case CFTYPE_FORUM:{
807815
int fpid;
808816
if( g.perm.AttachForum==0 ){
809
- goto ajax_err_403;
817
+ if( g.perm.WrTForum ){
818
+ bNeedsModeration = 1;
819
+ }else{
820
+ goto ajax_err_403;
821
+ }
822
+ }else{
823
+ bNeedsModeration = -1;
810824
}
811825
fpid = forumpost_head_rid2(zTarget);
812826
if( fpid<=0 ){
813827
goto ajax_err_404;
814828
}else if( !g.perm.Admin && !forumpost_is_owner(fpid, 0) ){
@@ -816,11 +830,13 @@
816830
"other users' forum posts.");
817831
db_rollback_transaction();
818832
return;
819833
}
820834
zTarget = zExtraFree = rid_to_uuid(fpid);
821
- bNeedsModeration = forum_need_moderation();
835
+ if( bNeedsModeration < 0 ){
836
+ bNeedsModeration = forum_need_moderation();
837
+ }
822838
break;
823839
}
824840
case CFTYPE_EVENT:{
825841
if( g.perm.Write==0 || g.perm.ApndWiki==0 || g.perm.Attach==0 ){
826842
goto ajax_err_403;
827843
--- src/attach.c
+++ src/attach.c
@@ -177,11 +177,12 @@
177 int attach_user_may(int rid, int eArtifactType){
178 if( g.perm.Admin ) return 1;
179 if( !login_is_individual() ) return 0;
180 switch(eArtifactType){
181 case CFTYPE_FORUM:
182 return g.perm.AttachForum && forumpost_is_owner(rid, 0);
 
183 case CFTYPE_WIKI:
184 return g.perm.ApndWiki && g.perm.Attach;
185 case CFTYPE_TICKET:
186 return g.perm.ApndTkt && g.perm.Attach;
187 case CFTYPE_EVENT:
@@ -645,11 +646,11 @@
645 char *zTargetType = 0;
646 char *zExtraFree = 0;
647 int szContent;
648 int goodCaptcha = 1;
649 int szLimit = 0;
650
651 if( P("target")!=0 ){
652 attachaddV2_page();
653 return;
654 }
655 zPage = P("page");
@@ -670,12 +671,16 @@
670 }
671 login_check_credentials();
672 if( zForumPost ){
673 int fpid;
674 if( g.perm.AttachForum==0 ){
675 login_needed(g.anon.AttachForum);
676 return;
 
 
 
 
677 }
678 fpid = forumpost_head_rid2(zForumPost);
679 if( fpid<=0 ){
680 webpage_error("Invalid forum post ID: %h", zForumPost);
681 }else if( !g.perm.Admin && !forumpost_is_owner(fpid, 0) ){
@@ -737,14 +742,17 @@
737 /* Fall through and render form. */
738 }else if( P("ok")
739 && cgi_csrf_safe(2)
740 && szContent>0
741 && (goodCaptcha = captcha_is_correct(0)) ){
742 int needModerator = (zForumPost!=0 && forum_need_moderation()) ||
743 (zTkt!=0 && ticket_need_moderation(0)) ||
744 (zPage!=0 && wiki_need_moderation(0));
745 attach_commit(zName, zTarget, aContent, szContent, needModerator, zComment);
 
 
 
746 cgi_redirect(zTo ? zTo : zFrom);
747 }
748
749 style_set_current_feature("attach");
750 style_header("Add Attachment");
@@ -804,11 +812,17 @@
804 db_rollback_transaction();
805 return;
806 case CFTYPE_FORUM:{
807 int fpid;
808 if( g.perm.AttachForum==0 ){
809 goto ajax_err_403;
 
 
 
 
 
 
810 }
811 fpid = forumpost_head_rid2(zTarget);
812 if( fpid<=0 ){
813 goto ajax_err_404;
814 }else if( !g.perm.Admin && !forumpost_is_owner(fpid, 0) ){
@@ -816,11 +830,13 @@
816 "other users' forum posts.");
817 db_rollback_transaction();
818 return;
819 }
820 zTarget = zExtraFree = rid_to_uuid(fpid);
821 bNeedsModeration = forum_need_moderation();
 
 
822 break;
823 }
824 case CFTYPE_EVENT:{
825 if( g.perm.Write==0 || g.perm.ApndWiki==0 || g.perm.Attach==0 ){
826 goto ajax_err_403;
827
--- src/attach.c
+++ src/attach.c
@@ -177,11 +177,12 @@
177 int attach_user_may(int rid, int eArtifactType){
178 if( g.perm.Admin ) return 1;
179 if( !login_is_individual() ) return 0;
180 switch(eArtifactType){
181 case CFTYPE_FORUM:
182 return (g.perm.AttachForum || g.perm.WrTForum)
183 && forumpost_is_owner(rid, 0);
184 case CFTYPE_WIKI:
185 return g.perm.ApndWiki && g.perm.Attach;
186 case CFTYPE_TICKET:
187 return g.perm.ApndTkt && g.perm.Attach;
188 case CFTYPE_EVENT:
@@ -645,11 +646,11 @@
646 char *zTargetType = 0;
647 char *zExtraFree = 0;
648 int szContent;
649 int goodCaptcha = 1;
650 int szLimit = 0;
651 int bNeedsModeration = -1; /* -1==don't yet know */
652 if( P("target")!=0 ){
653 attachaddV2_page();
654 return;
655 }
656 zPage = P("page");
@@ -670,12 +671,16 @@
671 }
672 login_check_credentials();
673 if( zForumPost ){
674 int fpid;
675 if( g.perm.AttachForum==0 ){
676 if( g.perm.WrTForum ){
677 bNeedsModeration = 1;
678 }else{
679 login_needed(g.anon.AttachForum);
680 return;
681 }
682 }
683 fpid = forumpost_head_rid2(zForumPost);
684 if( fpid<=0 ){
685 webpage_error("Invalid forum post ID: %h", zForumPost);
686 }else if( !g.perm.Admin && !forumpost_is_owner(fpid, 0) ){
@@ -737,14 +742,17 @@
742 /* Fall through and render form. */
743 }else if( P("ok")
744 && cgi_csrf_safe(2)
745 && szContent>0
746 && (goodCaptcha = captcha_is_correct(0)) ){
747 if( bNeedsModeration<0 ){
748 bNeedsModeration = (zForumPost!=0 && forum_need_moderation()) ||
749 (zTkt!=0 && ticket_need_moderation(0)) ||
750 (zPage!=0 && wiki_need_moderation(0));
751 }
752 attach_commit(zName, zTarget, aContent, szContent,
753 bNeedsModeration, zComment);
754 cgi_redirect(zTo ? zTo : zFrom);
755 }
756
757 style_set_current_feature("attach");
758 style_header("Add Attachment");
@@ -804,11 +812,17 @@
812 db_rollback_transaction();
813 return;
814 case CFTYPE_FORUM:{
815 int fpid;
816 if( g.perm.AttachForum==0 ){
817 if( g.perm.WrTForum ){
818 bNeedsModeration = 1;
819 }else{
820 goto ajax_err_403;
821 }
822 }else{
823 bNeedsModeration = -1;
824 }
825 fpid = forumpost_head_rid2(zTarget);
826 if( fpid<=0 ){
827 goto ajax_err_404;
828 }else if( !g.perm.Admin && !forumpost_is_owner(fpid, 0) ){
@@ -816,11 +830,13 @@
830 "other users' forum posts.");
831 db_rollback_transaction();
832 return;
833 }
834 zTarget = zExtraFree = rid_to_uuid(fpid);
835 if( bNeedsModeration < 0 ){
836 bNeedsModeration = forum_need_moderation();
837 }
838 break;
839 }
840 case CFTYPE_EVENT:{
841 if( g.perm.Write==0 || g.perm.ApndWiki==0 || g.perm.Attach==0 ){
842 goto ajax_err_403;
843
--- src/fossil.page.forumpost.js
+++ src/fossil.page.forumpost.js
@@ -588,13 +588,11 @@
588588
589589
#initAttacherTab(){
590590
this.#att = new F.Attacher({
591591
reverse: true
592592
});
593
- if( this.#opt.edit && F.user.mayAttachForum>0 ){
594
- /* -----------------^^^^ standalone attachment page does not
595
- ** yet honor the F.user.mayAttachForum<0 case. */
593
+ if( this.#opt.edit ){
596594
const eNote = D.append(
597595
D.div(),
598596
"Tip: attachments can be added to posts without editing them ",
599597
"by visiting ",
600598
D.attr(
601599
--- src/fossil.page.forumpost.js
+++ src/fossil.page.forumpost.js
@@ -588,13 +588,11 @@
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
--- src/fossil.page.forumpost.js
+++ src/fossil.page.forumpost.js
@@ -588,13 +588,11 @@
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

Keyboard Shortcuts

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