Fossil SCM
Refactor forum post moderation and put untested/disabled pieces in place for applying the same moderation operation to the forum post's attachments.
Commit
5078e7206048e49477590c00bc4fcb82cc5d2f35c4fd57360bd392e4ef03b66f
Parent
0436eb5ce3961d6…
1 file changed
+59
-4
+59
-4
| --- src/forum.c | ||
| +++ src/forum.c | ||
| @@ -198,10 +198,65 @@ | ||
| 198 | 198 | db_reset(&qIrt); |
| 199 | 199 | } |
| 200 | 200 | return i ? -rc : rc; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | +/* True if moderation of forum posts performs the same operation | |
| 204 | +** on its attachments. UNTESTED. */ | |
| 205 | +#define FORUMPOST_MOD_ATTACHMENTS 0 | |
| 206 | +#if FORUMPOST_MOD_ATTACHMENTS | |
| 207 | +/* | |
| 208 | +** Internal helper for moderation_forumpost_...(). | |
| 209 | +*/ | |
| 210 | +static void forumpost_prepare_attachids(Stmt *q, int fpid){ | |
| 211 | + db_prepare( | |
| 212 | + q, | |
| 213 | + "SELECT attachid FROM attachment a " | |
| 214 | + "WHERE a.target=(" | |
| 215 | + " SELECT uuid FROM blob WHERE rid=%d" | |
| 216 | + ") and attachid in (" | |
| 217 | + " SELECT objid FROM modreq" | |
| 218 | + ")", | |
| 219 | + forumpost_head_rid(fpid) | |
| 220 | + ); | |
| 221 | +} | |
| 222 | +#endif | |
| 223 | +/* | |
| 224 | +** Approve the given forum post RID and any pending-approval | |
| 225 | +** attachments associated with it. | |
| 226 | +*/ | |
| 227 | +static void moderation_forumpost_approve(int fpid){ | |
| 228 | +#if !FORUMPOST_MOD_ATTACHMENTS | |
| 229 | + moderation_approve('f', fpid); | |
| 230 | +#else | |
| 231 | + /* UNTESTED! Also approve any pending attachments */ | |
| 232 | + Stmt q; | |
| 233 | + moderation_approve('f', fpid); | |
| 234 | + forumpost_prepare_attachids(&q, fpid); | |
| 235 | + while( SQLITE_ROW==db_step(&q) ){ | |
| 236 | + moderation_approve('a', db_column_int(&q, 0)); | |
| 237 | + } | |
| 238 | + db_finalize(&q); | |
| 239 | +#endif | |
| 240 | +} | |
| 241 | + | |
| 242 | +static void moderation_forumpost_disapprove(int fpid){ | |
| 243 | +#if !FORUMPOST_MOD_ATTACHMENTS | |
| 244 | + moderation_disapprove(fpid); | |
| 245 | +#else | |
| 246 | + /* UNTESTED! Also disapprove any pending attachments */ | |
| 247 | + Stmt q; | |
| 248 | + moderation_disapprove(fpid); | |
| 249 | + forumpost_prepare_attachids(&q, fpid); | |
| 250 | + while( SQLITE_ROW==db_step(&q) ){ | |
| 251 | + moderation_disapprove(db_column_int(&q, 0)); | |
| 252 | + } | |
| 253 | + db_finalize(&q); | |
| 254 | +#endif | |
| 255 | +} | |
| 256 | +#undef FORUMPOST_MOD_ATTACHMENTS | |
| 257 | + | |
| 203 | 258 | /* |
| 204 | 259 | ** Applies or cancels a tag named zTagName on the given forum RID via |
| 205 | 260 | ** addition of a new control artifact into the repository. In order to |
| 206 | 261 | ** provide consistent behavior, it always acts on the first version of |
| 207 | 262 | ** the given forum post, walking the forumpost.fprev values to find |
| @@ -973,11 +1028,11 @@ | ||
| 973 | 1028 | } |
| 974 | 1029 | login_insert_csrf_secret(); |
| 975 | 1030 | @ </form> |
| 976 | 1031 | |
| 977 | 1032 | if( bSelect ){ |
| 978 | - ForumPost *pHead = p->pEditHead ? p->pEditHead : p; | |
| 1033 | + const ForumPost *pHead = p->pEditHead ? p->pEditHead : p; | |
| 979 | 1034 | if( forumpost_may_close() && iClosed>=0 ){ |
| 980 | 1035 | @ <form method="post" \ |
| 981 | 1036 | @ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'> |
| 982 | 1037 | login_insert_csrf_secret(); |
| 983 | 1038 | @ <input type="hidden" name="fpid" value="%s(pHead->zUuid)" /> |
| @@ -1705,11 +1760,11 @@ | ||
| 1705 | 1760 | bSameUser = login_is_individual() |
| 1706 | 1761 | && fossil_strcmp(pPost->zUser, g.zLogin)==0; |
| 1707 | 1762 | if( isCsrfSafe && (g.perm.ModForum || (bPrivate && bSameUser)) ){ |
| 1708 | 1763 | if( g.perm.ModForum && P("approve") ){ |
| 1709 | 1764 | const char *zUserToTrust; |
| 1710 | - moderation_approve('f', fpid); | |
| 1765 | + moderation_forumpost_approve(fpid); | |
| 1711 | 1766 | if( g.perm.AdminForum |
| 1712 | 1767 | && PB("trust") |
| 1713 | 1768 | && (zUserToTrust = P("trustuser"))!=0 |
| 1714 | 1769 | ){ |
| 1715 | 1770 | db_unprotect(PROTECT_USER); |
| @@ -1726,11 +1781,11 @@ | ||
| 1726 | 1781 | db_text(0, |
| 1727 | 1782 | "SELECT uuid FROM forumpost, blob" |
| 1728 | 1783 | " WHERE forumpost.fpid=%d AND blob.rid=forumpost.firt", |
| 1729 | 1784 | fpid |
| 1730 | 1785 | ); |
| 1731 | - moderation_disapprove(fpid); | |
| 1786 | + moderation_forumpost_disapprove(fpid); | |
| 1732 | 1787 | if( zParent ){ |
| 1733 | 1788 | cgi_redirectf("%R/forumpost/%S",zParent); |
| 1734 | 1789 | }else{ |
| 1735 | 1790 | cgi_redirectf("%R/forum"); |
| 1736 | 1791 | } |
| @@ -1983,11 +2038,11 @@ | ||
| 1983 | 2038 | @ <a href='%R/help/%h(pSetting->name)'>%h(pSetting->name)</a>: |
| 1984 | 2039 | @ </td><td> |
| 1985 | 2040 | entry_attribute("", 25, pSetting->name, zQP/*works-like:""*/, |
| 1986 | 2041 | pSetting->def, 0); |
| 1987 | 2042 | @ </td></tr> |
| 1988 | - } | |
| 2043 | + } | |
| 1989 | 2044 | } |
| 1990 | 2045 | @ </tbody></table> |
| 1991 | 2046 | @ <input type='submit' name='submit' value='Apply changes'> |
| 1992 | 2047 | @ </form> |
| 1993 | 2048 | } |
| 1994 | 2049 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -198,10 +198,65 @@ | |
| 198 | db_reset(&qIrt); |
| 199 | } |
| 200 | return i ? -rc : rc; |
| 201 | } |
| 202 | |
| 203 | /* |
| 204 | ** Applies or cancels a tag named zTagName on the given forum RID via |
| 205 | ** addition of a new control artifact into the repository. In order to |
| 206 | ** provide consistent behavior, it always acts on the first version of |
| 207 | ** the given forum post, walking the forumpost.fprev values to find |
| @@ -973,11 +1028,11 @@ | |
| 973 | } |
| 974 | login_insert_csrf_secret(); |
| 975 | @ </form> |
| 976 | |
| 977 | if( bSelect ){ |
| 978 | ForumPost *pHead = p->pEditHead ? p->pEditHead : p; |
| 979 | if( forumpost_may_close() && iClosed>=0 ){ |
| 980 | @ <form method="post" \ |
| 981 | @ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'> |
| 982 | login_insert_csrf_secret(); |
| 983 | @ <input type="hidden" name="fpid" value="%s(pHead->zUuid)" /> |
| @@ -1705,11 +1760,11 @@ | |
| 1705 | bSameUser = login_is_individual() |
| 1706 | && fossil_strcmp(pPost->zUser, g.zLogin)==0; |
| 1707 | if( isCsrfSafe && (g.perm.ModForum || (bPrivate && bSameUser)) ){ |
| 1708 | if( g.perm.ModForum && P("approve") ){ |
| 1709 | const char *zUserToTrust; |
| 1710 | moderation_approve('f', fpid); |
| 1711 | if( g.perm.AdminForum |
| 1712 | && PB("trust") |
| 1713 | && (zUserToTrust = P("trustuser"))!=0 |
| 1714 | ){ |
| 1715 | db_unprotect(PROTECT_USER); |
| @@ -1726,11 +1781,11 @@ | |
| 1726 | db_text(0, |
| 1727 | "SELECT uuid FROM forumpost, blob" |
| 1728 | " WHERE forumpost.fpid=%d AND blob.rid=forumpost.firt", |
| 1729 | fpid |
| 1730 | ); |
| 1731 | moderation_disapprove(fpid); |
| 1732 | if( zParent ){ |
| 1733 | cgi_redirectf("%R/forumpost/%S",zParent); |
| 1734 | }else{ |
| 1735 | cgi_redirectf("%R/forum"); |
| 1736 | } |
| @@ -1983,11 +2038,11 @@ | |
| 1983 | @ <a href='%R/help/%h(pSetting->name)'>%h(pSetting->name)</a>: |
| 1984 | @ </td><td> |
| 1985 | entry_attribute("", 25, pSetting->name, zQP/*works-like:""*/, |
| 1986 | pSetting->def, 0); |
| 1987 | @ </td></tr> |
| 1988 | } |
| 1989 | } |
| 1990 | @ </tbody></table> |
| 1991 | @ <input type='submit' name='submit' value='Apply changes'> |
| 1992 | @ </form> |
| 1993 | } |
| 1994 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -198,10 +198,65 @@ | |
| 198 | db_reset(&qIrt); |
| 199 | } |
| 200 | return i ? -rc : rc; |
| 201 | } |
| 202 | |
| 203 | /* True if moderation of forum posts performs the same operation |
| 204 | ** on its attachments. UNTESTED. */ |
| 205 | #define FORUMPOST_MOD_ATTACHMENTS 0 |
| 206 | #if FORUMPOST_MOD_ATTACHMENTS |
| 207 | /* |
| 208 | ** Internal helper for moderation_forumpost_...(). |
| 209 | */ |
| 210 | static void forumpost_prepare_attachids(Stmt *q, int fpid){ |
| 211 | db_prepare( |
| 212 | q, |
| 213 | "SELECT attachid FROM attachment a " |
| 214 | "WHERE a.target=(" |
| 215 | " SELECT uuid FROM blob WHERE rid=%d" |
| 216 | ") and attachid in (" |
| 217 | " SELECT objid FROM modreq" |
| 218 | ")", |
| 219 | forumpost_head_rid(fpid) |
| 220 | ); |
| 221 | } |
| 222 | #endif |
| 223 | /* |
| 224 | ** Approve the given forum post RID and any pending-approval |
| 225 | ** attachments associated with it. |
| 226 | */ |
| 227 | static void moderation_forumpost_approve(int fpid){ |
| 228 | #if !FORUMPOST_MOD_ATTACHMENTS |
| 229 | moderation_approve('f', fpid); |
| 230 | #else |
| 231 | /* UNTESTED! Also approve any pending attachments */ |
| 232 | Stmt q; |
| 233 | moderation_approve('f', fpid); |
| 234 | forumpost_prepare_attachids(&q, fpid); |
| 235 | while( SQLITE_ROW==db_step(&q) ){ |
| 236 | moderation_approve('a', db_column_int(&q, 0)); |
| 237 | } |
| 238 | db_finalize(&q); |
| 239 | #endif |
| 240 | } |
| 241 | |
| 242 | static void moderation_forumpost_disapprove(int fpid){ |
| 243 | #if !FORUMPOST_MOD_ATTACHMENTS |
| 244 | moderation_disapprove(fpid); |
| 245 | #else |
| 246 | /* UNTESTED! Also disapprove any pending attachments */ |
| 247 | Stmt q; |
| 248 | moderation_disapprove(fpid); |
| 249 | forumpost_prepare_attachids(&q, fpid); |
| 250 | while( SQLITE_ROW==db_step(&q) ){ |
| 251 | moderation_disapprove(db_column_int(&q, 0)); |
| 252 | } |
| 253 | db_finalize(&q); |
| 254 | #endif |
| 255 | } |
| 256 | #undef FORUMPOST_MOD_ATTACHMENTS |
| 257 | |
| 258 | /* |
| 259 | ** Applies or cancels a tag named zTagName on the given forum RID via |
| 260 | ** addition of a new control artifact into the repository. In order to |
| 261 | ** provide consistent behavior, it always acts on the first version of |
| 262 | ** the given forum post, walking the forumpost.fprev values to find |
| @@ -973,11 +1028,11 @@ | |
| 1028 | } |
| 1029 | login_insert_csrf_secret(); |
| 1030 | @ </form> |
| 1031 | |
| 1032 | if( bSelect ){ |
| 1033 | const ForumPost *pHead = p->pEditHead ? p->pEditHead : p; |
| 1034 | if( forumpost_may_close() && iClosed>=0 ){ |
| 1035 | @ <form method="post" \ |
| 1036 | @ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'> |
| 1037 | login_insert_csrf_secret(); |
| 1038 | @ <input type="hidden" name="fpid" value="%s(pHead->zUuid)" /> |
| @@ -1705,11 +1760,11 @@ | |
| 1760 | bSameUser = login_is_individual() |
| 1761 | && fossil_strcmp(pPost->zUser, g.zLogin)==0; |
| 1762 | if( isCsrfSafe && (g.perm.ModForum || (bPrivate && bSameUser)) ){ |
| 1763 | if( g.perm.ModForum && P("approve") ){ |
| 1764 | const char *zUserToTrust; |
| 1765 | moderation_forumpost_approve(fpid); |
| 1766 | if( g.perm.AdminForum |
| 1767 | && PB("trust") |
| 1768 | && (zUserToTrust = P("trustuser"))!=0 |
| 1769 | ){ |
| 1770 | db_unprotect(PROTECT_USER); |
| @@ -1726,11 +1781,11 @@ | |
| 1781 | db_text(0, |
| 1782 | "SELECT uuid FROM forumpost, blob" |
| 1783 | " WHERE forumpost.fpid=%d AND blob.rid=forumpost.firt", |
| 1784 | fpid |
| 1785 | ); |
| 1786 | moderation_forumpost_disapprove(fpid); |
| 1787 | if( zParent ){ |
| 1788 | cgi_redirectf("%R/forumpost/%S",zParent); |
| 1789 | }else{ |
| 1790 | cgi_redirectf("%R/forum"); |
| 1791 | } |
| @@ -1983,11 +2038,11 @@ | |
| 2038 | @ <a href='%R/help/%h(pSetting->name)'>%h(pSetting->name)</a>: |
| 2039 | @ </td><td> |
| 2040 | entry_attribute("", 25, pSetting->name, zQP/*works-like:""*/, |
| 2041 | pSetting->def, 0); |
| 2042 | @ </td></tr> |
| 2043 | } |
| 2044 | } |
| 2045 | @ </tbody></table> |
| 2046 | @ <input type='submit' name='submit' value='Apply changes'> |
| 2047 | @ </form> |
| 2048 | } |
| 2049 |