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.
Commit
a73f05baa817de4e3529f8c31b8ad1b394fd758985126b49d6b79eef1834d5c4
Parent
c9b8b676f62dcfc…
2 files changed
+26
-10
+1
-3
+26
-10
| --- src/attach.c | ||
| +++ src/attach.c | ||
| @@ -177,11 +177,12 @@ | ||
| 177 | 177 | int attach_user_may(int rid, int eArtifactType){ |
| 178 | 178 | if( g.perm.Admin ) return 1; |
| 179 | 179 | if( !login_is_individual() ) return 0; |
| 180 | 180 | switch(eArtifactType){ |
| 181 | 181 | 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); | |
| 183 | 184 | case CFTYPE_WIKI: |
| 184 | 185 | return g.perm.ApndWiki && g.perm.Attach; |
| 185 | 186 | case CFTYPE_TICKET: |
| 186 | 187 | return g.perm.ApndTkt && g.perm.Attach; |
| 187 | 188 | case CFTYPE_EVENT: |
| @@ -645,11 +646,11 @@ | ||
| 645 | 646 | char *zTargetType = 0; |
| 646 | 647 | char *zExtraFree = 0; |
| 647 | 648 | int szContent; |
| 648 | 649 | int goodCaptcha = 1; |
| 649 | 650 | int szLimit = 0; |
| 650 | - | |
| 651 | + int bNeedsModeration = -1; /* -1==don't yet know */ | |
| 651 | 652 | if( P("target")!=0 ){ |
| 652 | 653 | attachaddV2_page(); |
| 653 | 654 | return; |
| 654 | 655 | } |
| 655 | 656 | zPage = P("page"); |
| @@ -670,12 +671,16 @@ | ||
| 670 | 671 | } |
| 671 | 672 | login_check_credentials(); |
| 672 | 673 | if( zForumPost ){ |
| 673 | 674 | int fpid; |
| 674 | 675 | 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 | + } | |
| 677 | 682 | } |
| 678 | 683 | fpid = forumpost_head_rid2(zForumPost); |
| 679 | 684 | if( fpid<=0 ){ |
| 680 | 685 | webpage_error("Invalid forum post ID: %h", zForumPost); |
| 681 | 686 | }else if( !g.perm.Admin && !forumpost_is_owner(fpid, 0) ){ |
| @@ -737,14 +742,17 @@ | ||
| 737 | 742 | /* Fall through and render form. */ |
| 738 | 743 | }else if( P("ok") |
| 739 | 744 | && cgi_csrf_safe(2) |
| 740 | 745 | && szContent>0 |
| 741 | 746 | && (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); | |
| 746 | 754 | cgi_redirect(zTo ? zTo : zFrom); |
| 747 | 755 | } |
| 748 | 756 | |
| 749 | 757 | style_set_current_feature("attach"); |
| 750 | 758 | style_header("Add Attachment"); |
| @@ -804,11 +812,17 @@ | ||
| 804 | 812 | db_rollback_transaction(); |
| 805 | 813 | return; |
| 806 | 814 | case CFTYPE_FORUM:{ |
| 807 | 815 | int fpid; |
| 808 | 816 | 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; | |
| 810 | 824 | } |
| 811 | 825 | fpid = forumpost_head_rid2(zTarget); |
| 812 | 826 | if( fpid<=0 ){ |
| 813 | 827 | goto ajax_err_404; |
| 814 | 828 | }else if( !g.perm.Admin && !forumpost_is_owner(fpid, 0) ){ |
| @@ -816,11 +830,13 @@ | ||
| 816 | 830 | "other users' forum posts."); |
| 817 | 831 | db_rollback_transaction(); |
| 818 | 832 | return; |
| 819 | 833 | } |
| 820 | 834 | zTarget = zExtraFree = rid_to_uuid(fpid); |
| 821 | - bNeedsModeration = forum_need_moderation(); | |
| 835 | + if( bNeedsModeration < 0 ){ | |
| 836 | + bNeedsModeration = forum_need_moderation(); | |
| 837 | + } | |
| 822 | 838 | break; |
| 823 | 839 | } |
| 824 | 840 | case CFTYPE_EVENT:{ |
| 825 | 841 | if( g.perm.Write==0 || g.perm.ApndWiki==0 || g.perm.Attach==0 ){ |
| 826 | 842 | goto ajax_err_403; |
| 827 | 843 |
| --- 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 |
+1
-3
| --- src/fossil.page.forumpost.js | ||
| +++ src/fossil.page.forumpost.js | ||
| @@ -588,13 +588,11 @@ | ||
| 588 | 588 | |
| 589 | 589 | #initAttacherTab(){ |
| 590 | 590 | this.#att = new F.Attacher({ |
| 591 | 591 | reverse: true |
| 592 | 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. */ | |
| 593 | + if( this.#opt.edit ){ | |
| 596 | 594 | const eNote = D.append( |
| 597 | 595 | D.div(), |
| 598 | 596 | "Tip: attachments can be added to posts without editing them ", |
| 599 | 597 | "by visiting ", |
| 600 | 598 | D.attr( |
| 601 | 599 |
| --- 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 |