jcs
/subtext
/amendments
/520
board+folder: When dynamically disabling menu options, do it by ret
Options were added to the menu in board_post_read but the array index
wasn't updated for disabling 'd', so this was disabling '>' instead.
To prevent this in the future, disable by the returned option rather
than hard-coding an index.
jcs made amendment 520 about 1 year ago
--- board.c Thu Jun 15 10:58:01 2023
+++ board.c Thu Aug 3 09:46:08 2023
@@ -898,7 +898,7 @@ board_post_read(struct session *s, struct board *board
short ret = POST_READ_RETURN_DONE;
char c;
char *data, *subject, *plain_post, *tplain_post;
- short cc, bcret;
+ short cc, bcret, n;
bool done = false, show_help = false;
dopts = xmalloc(sizeof(opts));
@@ -921,9 +921,15 @@ show_post:
if (ret == BILE_ERR_NO_MEMORY)
goto done_reading;
- if (!(s->user && s->user->is_sysop))
+ if (!(s->user && s->user->is_sysop)) {
/* disable deleting */
- dopts[1].key[0] = '\0';
+ for (n = 0; n < nitems(opts); n++) {
+ if (dopts[n].ret == 'd') {
+ dopts[n].key[0] = '\0';
+ break;
+ }
+ }
+ }
strftime(time, sizeof(time), "%Y-%m-%d %H:%M:%S",
localtime(&fpost.time));
@@ -985,9 +991,15 @@ show_post:
goto done_reading;
if (!(s->user && (s->user->is_sysop ||
- s->user->id == post.sender_user_id)))
+ s->user->id == post.sender_user_id))) {
/* disable deleting */
- dopts[1].key[0] = '\0';
+ for (n = 0; n < nitems(opts); n++) {
+ if (dopts[n].ret == 'd') {
+ dopts[n].key[0] = '\0';
+ break;
+ }
+ }
+ }
sender = user_username(post.sender_user_id);
--- folder.c Thu Apr 27 10:56:29 2023
+++ folder.c Thu Aug 3 09:47:23 2023
@@ -582,7 +582,7 @@ folder_file_view(struct session *s, struct folder *fol
struct session_menu_option *dopts = NULL;
FILE *fp;
size_t size;
- short cc, bret, ret = FILE_VIEW_RETURN_FIND;
+ short cc, n, bret, ret = FILE_VIEW_RETURN_FIND;
bool done = false, show_help = false;
size = bile_read_alloc(folder->bile, FOLDER_FILE_RTYPE, id, &data);
@@ -602,8 +602,10 @@ folder_file_view(struct session *s, struct folder *fol
if (!(s->user && (s->user->is_sysop ||
s->user->id == file.uploader_user_id))) {
/* disable deleting and editing */
- dopts[1].key[0] = '\0';
- dopts[2].key[0] = '\0';
+ for (n = 0; n < nitems(opts); n++) {
+ if (dopts[n].ret == 'r' || dopts[n].ret == 'e')
+ dopts[n].key[0] = '\0';
+ }
}
uploader = user_username(file.uploader_user_id);