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.

stephan 2026-05-23 09:01 UTC forum-attachments
Commit 5078e7206048e49477590c00bc4fcb82cc5d2f35c4fd57360bd392e4ef03b66f
1 file changed +59 -4
+59 -4
--- src/forum.c
+++ src/forum.c
@@ -198,10 +198,65 @@
198198
db_reset(&qIrt);
199199
}
200200
return i ? -rc : rc;
201201
}
202202
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
+
203258
/*
204259
** Applies or cancels a tag named zTagName on the given forum RID via
205260
** addition of a new control artifact into the repository. In order to
206261
** provide consistent behavior, it always acts on the first version of
207262
** the given forum post, walking the forumpost.fprev values to find
@@ -973,11 +1028,11 @@
9731028
}
9741029
login_insert_csrf_secret();
9751030
@ </form>
9761031
9771032
if( bSelect ){
978
- ForumPost *pHead = p->pEditHead ? p->pEditHead : p;
1033
+ const ForumPost *pHead = p->pEditHead ? p->pEditHead : p;
9791034
if( forumpost_may_close() && iClosed>=0 ){
9801035
@ <form method="post" \
9811036
@ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'>
9821037
login_insert_csrf_secret();
9831038
@ <input type="hidden" name="fpid" value="%s(pHead->zUuid)" />
@@ -1705,11 +1760,11 @@
17051760
bSameUser = login_is_individual()
17061761
&& fossil_strcmp(pPost->zUser, g.zLogin)==0;
17071762
if( isCsrfSafe && (g.perm.ModForum || (bPrivate && bSameUser)) ){
17081763
if( g.perm.ModForum && P("approve") ){
17091764
const char *zUserToTrust;
1710
- moderation_approve('f', fpid);
1765
+ moderation_forumpost_approve(fpid);
17111766
if( g.perm.AdminForum
17121767
&& PB("trust")
17131768
&& (zUserToTrust = P("trustuser"))!=0
17141769
){
17151770
db_unprotect(PROTECT_USER);
@@ -1726,11 +1781,11 @@
17261781
db_text(0,
17271782
"SELECT uuid FROM forumpost, blob"
17281783
" WHERE forumpost.fpid=%d AND blob.rid=forumpost.firt",
17291784
fpid
17301785
);
1731
- moderation_disapprove(fpid);
1786
+ moderation_forumpost_disapprove(fpid);
17321787
if( zParent ){
17331788
cgi_redirectf("%R/forumpost/%S",zParent);
17341789
}else{
17351790
cgi_redirectf("%R/forum");
17361791
}
@@ -1983,11 +2038,11 @@
19832038
@ <a href='%R/help/%h(pSetting->name)'>%h(pSetting->name)</a>:
19842039
@ </td><td>
19852040
entry_attribute("", 25, pSetting->name, zQP/*works-like:""*/,
19862041
pSetting->def, 0);
19872042
@ </td></tr>
1988
- }
2043
+ }
19892044
}
19902045
@ </tbody></table>
19912046
@ <input type='submit' name='submit' value='Apply changes'>
19922047
@ </form>
19932048
}
19942049
--- 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

Keyboard Shortcuts

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