Fossil SCM

Do not show the Attach button for anonymous/nobody.

stephan 2026-05-24 13:54 UTC forum-attachments
Commit dfe39cc5c25c907aa78dbb0ab27691cc6ed1fc2b07969723820bbd310217db04
1 file changed +20 -12
+20 -12
--- src/forum.c
+++ src/forum.c
@@ -205,50 +205,55 @@
205205
#define FORUMPOST_MOD_ATTACHMENTS 1
206206
#if FORUMPOST_MOD_ATTACHMENTS
207207
/*
208208
** Internal helper for moderation_forumpost_...().
209209
*/
210
-static void forumpost_prepare_attachids(Stmt *q, int fpid){
210
+static void forumpost_prep_pending_attachids(Stmt *q, int fpid){
211211
db_prepare(
212212
q,
213
- "SELECT attachid FROM attachment a "
214
- "WHERE a.target=("
213
+ "SELECT attachid FROM attachment "
214
+ "WHERE target=("
215215
" SELECT uuid FROM blob WHERE rid=%d"
216216
") and attachid in ("
217217
" SELECT objid FROM modreq"
218218
")",
219219
forumpost_head_rid(fpid)
220220
);
221221
}
222222
#endif
223
+
223224
/*
224225
** Approve the given forum post RID and any pending-approval
225
-** attachments associated with it.
226
+** attachments associated with its initial version.
226227
*/
227228
static void moderation_forumpost_approve(int fpid){
228229
#if !FORUMPOST_MOD_ATTACHMENTS
229230
moderation_approve('f', fpid);
230231
#else
231232
/* Also approve any pending attachments */
232233
Stmt q;
233234
moderation_approve('f', fpid);
234
- forumpost_prepare_attachids(&q, fpid);
235
+ forumpost_prep_pending_attachids(&q, fpid);
235236
while( SQLITE_ROW==db_step(&q) ){
236237
moderation_approve('a', db_column_int(&q, 0));
237238
}
238239
db_finalize(&q);
239240
#endif
240241
}
241242
243
+/*
244
+** Disapprove the given forum post and any pending-moderation
245
+** attachments on its initial version.
246
+*/
242247
static void moderation_forumpost_disapprove(int fpid){
243248
#if !FORUMPOST_MOD_ATTACHMENTS
244249
moderation_disapprove(fpid);
245250
#else
246251
/* Also disapprove any pending attachments */
247252
Stmt q;
248253
moderation_disapprove(fpid);
249
- forumpost_prepare_attachids(&q, fpid);
254
+ forumpost_prep_pending_attachids(&q, fpid);
250255
while( SQLITE_ROW==db_step(&q) ){
251256
moderation_disapprove(db_column_int(&q, 0));
252257
}
253258
db_finalize(&q);
254259
#endif
@@ -263,18 +268,18 @@
263268
** the head of the chain.
264269
**
265270
** If addTag is true then a propagating tag is added, except as noted
266271
** below, with the given optional zReason string as the tag's
267272
** value. If addTag is false then any matching active tag on frid is
268
-** cancelled, except as noted below. zReason is ignored if doClose is
269
-** false or if zReason is NULL or starts with a NUL byte.
273
+** cancelled, except as noted below. zReason is ignored if it is NULL
274
+** or starts with a NUL byte, or if addTag is false.
270275
**
271276
** This function only adds a tag if forum_rid_is_tagged() indicates
272277
** that frid's head is not tagged. If a parent post is already tagged,
273
-** no tag is added. Similarly, it will only remove a tagtag from a
274
-** post which has its own tag tag, and will not remove an inherited
275
-** one from a parent post.
278
+** no tag is added. Similarly, it will only remove a tag from a post
279
+** which has its own tag, and will not remove an inherited one from a
280
+** parent post.
276281
**
277282
** If addTag is true and frid is already tagged (directly or
278283
** inherited), this is a no-op. Likewise, if addTag is false and frid
279284
** itself is not tagged (not accounting for an inherited closed tag),
280285
** this is a no-op.
@@ -1054,19 +1059,22 @@
10541059
@ <input type="button" value='%s(iClosed ? "Re-open" : "Close")' \
10551060
@ class='%s(iClosed ? "action-reopen" : "action-close")'/>
10561061
}
10571062
@ </form>
10581063
}
1059
- if( g.perm.Admin || forumpost_is_owner(p/*not pHead*/->fpid, 0) ){
1064
+ if( g.perm.Admin ||
1065
+ (login_is_individual()
1066
+ && forumpost_is_owner(p/*not pHead*/->fpid, 0)) ){
10601067
/* When an admin edits someone else's post, the admin
10611068
** effectively takes over ownership of it (and we currently
10621069
** have no way of passing it back). Because of this, we
10631070
** check the ownership of `p` instead of `pHead`. */
10641071
@ <form method="post" action="%R/attachadd">\
10651072
@ <input type="hidden" name="forumpost" value="%T(pHead->zUuid)">
10661073
@ <input type="submit" value="Attach...">
10671074
login_insert_csrf_secret();
1075
+ moderation_pending_www(p->fpid);
10681076
@ </form>
10691077
}
10701078
}
10711079
@ </div>
10721080
}
10731081
--- src/forum.c
+++ src/forum.c
@@ -205,50 +205,55 @@
205 #define FORUMPOST_MOD_ATTACHMENTS 1
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 /* 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 /* 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
@@ -263,18 +268,18 @@
263 ** the head of the chain.
264 **
265 ** If addTag is true then a propagating tag is added, except as noted
266 ** below, with the given optional zReason string as the tag's
267 ** value. If addTag is false then any matching active tag on frid is
268 ** cancelled, except as noted below. zReason is ignored if doClose is
269 ** false or if zReason is NULL or starts with a NUL byte.
270 **
271 ** This function only adds a tag if forum_rid_is_tagged() indicates
272 ** that frid's head is not tagged. If a parent post is already tagged,
273 ** no tag is added. Similarly, it will only remove a tagtag from a
274 ** post which has its own tag tag, and will not remove an inherited
275 ** one from a parent post.
276 **
277 ** If addTag is true and frid is already tagged (directly or
278 ** inherited), this is a no-op. Likewise, if addTag is false and frid
279 ** itself is not tagged (not accounting for an inherited closed tag),
280 ** this is a no-op.
@@ -1054,19 +1059,22 @@
1054 @ <input type="button" value='%s(iClosed ? "Re-open" : "Close")' \
1055 @ class='%s(iClosed ? "action-reopen" : "action-close")'/>
1056 }
1057 @ </form>
1058 }
1059 if( g.perm.Admin || forumpost_is_owner(p/*not pHead*/->fpid, 0) ){
 
 
1060 /* When an admin edits someone else's post, the admin
1061 ** effectively takes over ownership of it (and we currently
1062 ** have no way of passing it back). Because of this, we
1063 ** check the ownership of `p` instead of `pHead`. */
1064 @ <form method="post" action="%R/attachadd">\
1065 @ <input type="hidden" name="forumpost" value="%T(pHead->zUuid)">
1066 @ <input type="submit" value="Attach...">
1067 login_insert_csrf_secret();
 
1068 @ </form>
1069 }
1070 }
1071 @ </div>
1072 }
1073
--- src/forum.c
+++ src/forum.c
@@ -205,50 +205,55 @@
205 #define FORUMPOST_MOD_ATTACHMENTS 1
206 #if FORUMPOST_MOD_ATTACHMENTS
207 /*
208 ** Internal helper for moderation_forumpost_...().
209 */
210 static void forumpost_prep_pending_attachids(Stmt *q, int fpid){
211 db_prepare(
212 q,
213 "SELECT attachid FROM attachment "
214 "WHERE 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 /*
225 ** Approve the given forum post RID and any pending-approval
226 ** attachments associated with its initial version.
227 */
228 static void moderation_forumpost_approve(int fpid){
229 #if !FORUMPOST_MOD_ATTACHMENTS
230 moderation_approve('f', fpid);
231 #else
232 /* Also approve any pending attachments */
233 Stmt q;
234 moderation_approve('f', fpid);
235 forumpost_prep_pending_attachids(&q, fpid);
236 while( SQLITE_ROW==db_step(&q) ){
237 moderation_approve('a', db_column_int(&q, 0));
238 }
239 db_finalize(&q);
240 #endif
241 }
242
243 /*
244 ** Disapprove the given forum post and any pending-moderation
245 ** attachments on its initial version.
246 */
247 static void moderation_forumpost_disapprove(int fpid){
248 #if !FORUMPOST_MOD_ATTACHMENTS
249 moderation_disapprove(fpid);
250 #else
251 /* Also disapprove any pending attachments */
252 Stmt q;
253 moderation_disapprove(fpid);
254 forumpost_prep_pending_attachids(&q, fpid);
255 while( SQLITE_ROW==db_step(&q) ){
256 moderation_disapprove(db_column_int(&q, 0));
257 }
258 db_finalize(&q);
259 #endif
@@ -263,18 +268,18 @@
268 ** the head of the chain.
269 **
270 ** If addTag is true then a propagating tag is added, except as noted
271 ** below, with the given optional zReason string as the tag's
272 ** value. If addTag is false then any matching active tag on frid is
273 ** cancelled, except as noted below. zReason is ignored if it is NULL
274 ** or starts with a NUL byte, or if addTag is false.
275 **
276 ** This function only adds a tag if forum_rid_is_tagged() indicates
277 ** that frid's head is not tagged. If a parent post is already tagged,
278 ** no tag is added. Similarly, it will only remove a tag from a post
279 ** which has its own tag, and will not remove an inherited one from a
280 ** parent post.
281 **
282 ** If addTag is true and frid is already tagged (directly or
283 ** inherited), this is a no-op. Likewise, if addTag is false and frid
284 ** itself is not tagged (not accounting for an inherited closed tag),
285 ** this is a no-op.
@@ -1054,19 +1059,22 @@
1059 @ <input type="button" value='%s(iClosed ? "Re-open" : "Close")' \
1060 @ class='%s(iClosed ? "action-reopen" : "action-close")'/>
1061 }
1062 @ </form>
1063 }
1064 if( g.perm.Admin ||
1065 (login_is_individual()
1066 && forumpost_is_owner(p/*not pHead*/->fpid, 0)) ){
1067 /* When an admin edits someone else's post, the admin
1068 ** effectively takes over ownership of it (and we currently
1069 ** have no way of passing it back). Because of this, we
1070 ** check the ownership of `p` instead of `pHead`. */
1071 @ <form method="post" action="%R/attachadd">\
1072 @ <input type="hidden" name="forumpost" value="%T(pHead->zUuid)">
1073 @ <input type="submit" value="Attach...">
1074 login_insert_csrf_secret();
1075 moderation_pending_www(p->fpid);
1076 @ </form>
1077 }
1078 }
1079 @ </div>
1080 }
1081

Keyboard Shortcuts

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