AmendHub

Download:

jcs

/

subtext

/

amendments

/

458

sysop: List more users per page, edit by user id, add edit by username


jcs made amendment 458 about 1 year ago
--- sysop.c Thu Mar 23 21:24:35 2023 +++ sysop.c Thu Mar 30 12:30:57 2023 @@ -24,7 +24,7 @@ #include "session.h" #include "sysop.h" -#define USERS_PER_PAGE 10 +#define USERS_PER_PAGE 20 void sysop_edit_boards(struct session *s); void sysop_edit_folders(struct session *s); @@ -542,7 +542,8 @@ void sysop_edit_users(struct session *s) { static const struct session_menu_option opts[] = { - { '#', "#", "Edit user [#]" }, + { '#', "#", "Edit user id [#]" }, + { 'u', "Uu", "Edit user by username" }, { '<', "<", "Previous page of users" }, { 'l', "Ll", "List users" }, { '>', ">", "Next page of users" }, @@ -552,11 +553,10 @@ sysop_edit_users(struct session *s) static const char prompt_help[] = "#:Edit User <:Prev >:Next L:List Q:Return ?:Help"; unsigned long *all_user_ids = NULL, *user_ids = NULL; - struct user user; + struct user user, *fuser; size_t pages, page, n, size, nall_user_ids, nuser_ids; - short suser_id; - char c; - char time[30]; + short suser_id, upp; + char c, time[30], *username; bool show_help = false; bool show_list = true; bool done = false; @@ -568,10 +568,13 @@ sysop_edit_users(struct session *s) while (!done && !s->ending) { if (find_user_ids) { + upp = USERS_PER_PAGE; + if (s->terminal_lines < upp + 3) + upp = BOUND(upp, 5, s->terminal_lines - 3); nuser_ids = sysop_find_user_ids(nall_user_ids, all_user_ids, - &user_ids, page * USERS_PER_PAGE, USERS_PER_PAGE); - /* ceil(nall_user_ids / USERS_PER_PAGE) */ - pages = (nall_user_ids + USERS_PER_PAGE - 1) / USERS_PER_PAGE; + &user_ids, page * upp, upp); + /* ceil(nall_user_ids / upp) */ + pages = (nall_user_ids + upp - 1) / upp; if (page >= pages) page = pages - 1; @@ -582,7 +585,7 @@ sysop_edit_users(struct session *s) if (show_list) { session_printf(s, "{{B}}Users (Page %ld of %ld){{/B}}\r\n", page + 1, pages); - session_printf(s, "%s# Username ID Active Sysop Last Login%s\r\n", + session_printf(s, "%s # Username Active Sysop Last Login%s\r\n", ansi(s, ANSI_BOLD, ANSI_END), ansi(s, ANSI_RESET, ANSI_END)); session_flush(s); @@ -596,20 +599,19 @@ sysop_edit_users(struct session *s) localtime(&user.last_seen_at)); else snprintf(time, sizeof(time), "Never"); - session_printf(s, "%ld %-14s %-5ld %c %c %s\r\n", - n + 1, - user.username, + session_printf(s, "%3ld %-14s %c %c %s\r\n", user.id, - user.is_enabled ? 'Y' : ' ', - user.is_sysop ? 'Y' : ' ', + user.username, + user.is_enabled ? 'Y' : '-', + user.is_sysop ? 'Y' : '-', time); - session_flush(s); } + session_flush(s); show_list = false; } c = session_menu(s, "Edit Users", "Sysop:Users", (char *)prompt_help, - opts, nitems(opts), show_help, "User #", &suser_id); + opts, nitems(opts), show_help, "User ID", &suser_id); show_help = false; handle_opt: @@ -637,12 +639,32 @@ handle_opt: show_list = true; break; case '#': - if (suser_id < 1 || suser_id > nuser_ids) { - session_printf(s, "Invalid user\r\n"); + sysop_edit_user(s, suser_id); + break; + case 'u': + session_printf(s, "Username: "); + session_flush(s); + + username = session_field_input(s, 30, 30, NULL, false, 0); + session_output(s, "\r\n", 2); + session_flush(s); + if (username == NULL) + break; + if (username[0] == '\0') { + xfree(&username); + break; + } + + fuser = user_find_by_username(username); + xfree(&username); + if (!fuser) { + session_printf(s, "Error: No such user.\r\n"); session_flush(s); break; } - sysop_edit_user(s, user_ids[suser_id - 1]); + + sysop_edit_user(s, fuser->id); + xfree(&fuser); break; case '?': show_help = true;