From 41947f89ada89819f00e1db468c38f33aff84cba Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 29 Jun 2022 17:17:04 -0400 Subject: [PATCH] Pass through the data to tell the client if it has room aide privileges and/or permission to delete messages in the current room. Aide or Room Aide privileges are now indicated via a user-with-cog icon in the room name banner. The delete button in the forum view now only appears if the client believes it is allowed. --- webcit-ng/room_functions.c | 16 ++++++++++++++-- webcit-ng/static/js/defs.js | 2 ++ webcit-ng/static/js/main.js | 8 +++++--- webcit-ng/static/js/view_forum.js | 16 ++++++++++------ webcit-ng/webcit.h | 1 + 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/webcit-ng/room_functions.c b/webcit-ng/room_functions.c index b6e508c1d..8944224e9 100644 --- a/webcit-ng/room_functions.c +++ b/webcit-ng/room_functions.c @@ -425,6 +425,8 @@ void get_the_room_itself(struct http_transaction *h, struct ctdlsession *c) { JsonObjectAppend(j, NewJsonPlainString(HKEY("name"), c->room, -1)); JsonObjectAppend(j, NewJsonNumber(HKEY("current_view"), c->room_current_view)); JsonObjectAppend(j, NewJsonNumber(HKEY("default_view"), c->room_default_view)); + JsonObjectAppend(j, NewJsonNumber(HKEY("is_room_aide"), c->is_room_aide)); + JsonObjectAppend(j, NewJsonNumber(HKEY("can_delete_messages"), c->can_delete_messages)); JsonObjectAppend(j, NewJsonNumber(HKEY("new_messages"), c->new_messages)); JsonObjectAppend(j, NewJsonNumber(HKEY("total_messages"), c->total_messages)); JsonObjectAppend(j, NewJsonNumber(HKEY("last_seen"), c->last_seen)); @@ -525,6 +527,8 @@ void room_list(struct http_transaction *h, struct ctdlsession *c) { void ctdl_r(struct http_transaction *h, struct ctdlsession *c) { char requested_roomname[128]; char buf[1024]; + long room_flags = 0; + long room_flags2 = 0; // All room-related functions require being "in" the room specified. Are we in that room already? extract_token(requested_roomname, h->url, 3, '/', sizeof requested_roomname); @@ -544,7 +548,7 @@ void ctdl_r(struct http_transaction *h, struct ctdlsession *c) { c->new_messages = extract_int(&buf[4], 1); c->total_messages = extract_int(&buf[4], 2); // 3 (int)info Info flag: set to nonzero if the user needs to read this room's info file - // 4 (int)CC->room.QRflags Various flags associated with this room. + room_flags = extract_long(&buf[4], 3); // Various flags associated with this room. // 5 (long)CC->room.QRhighest The highest message number present in this room c->last_seen = extract_long(&buf[4], 6); // The highest message number the user has read in this room // 7 (int)rmailflag Boolean flag: 1 if this is a Mail> room, 0 otherwise. @@ -554,8 +558,16 @@ void ctdl_r(struct http_transaction *h, struct ctdlsession *c) { c->room_current_view = extract_int(&buf[4], 11); c->room_default_view = extract_int(&buf[4], 12); // 13 (int)is_trash Boolean flag: 1 if this is the user's Trash folder, 0 otherwise. - // 14 (int)CC->room.QRflags2 More flags associated with this room + room_flags2 = extract_long(&buf[4], 14); // More flags associated with this room. // 15 (long)CC->room.QRmtime Timestamp of the last write activity in this room + + // If any of these three conditions are met, let the client know it has permission to delete messages. + if ((c->is_room_aide) || (room_flags & QR_MAILBOX) || (room_flags2 & QR2_COLLABDEL)) { + c->can_delete_messages = 1; + } + else { + c->can_delete_messages = 0; + } } else { do_404(h); diff --git a/webcit-ng/static/js/defs.js b/webcit-ng/static/js/defs.js index dfaf7be98..571afc03d 100644 --- a/webcit-ng/static/js/defs.js +++ b/webcit-ng/static/js/defs.js @@ -19,6 +19,8 @@ var logged_in = 0; var current_user = _("Not logged in."); var serv_info; var last_seen = 0; +var is_room_aide = 0; +var can_delete_messages = 0; var messages_per_page = 20; var march_list = [] ; diff --git a/webcit-ng/static/js/main.js b/webcit-ng/static/js/main.js index 822277088..20b629a3d 100644 --- a/webcit-ng/static/js/main.js +++ b/webcit-ng/static/js/main.js @@ -41,10 +41,10 @@ function update_banner() { detect_logged_in(); if (current_room) { document.getElementById("ctdl_banner_title").innerHTML = current_room; + if (is_room_aide) { + document.getElementById("ctdl_banner_title").innerHTML += ""; + } document.title = current_room; - - - } else { document.getElementById("ctdl_banner_title").innerHTML = serv_info.serv_humannode; @@ -72,6 +72,8 @@ function gotoroom(roomname) { current_view = data.current_view; default_view = data.default_view; last_seen = data.last_seen; + is_room_aide = data.is_room_aide; + can_delete_messages = data.can_delete_messages; update_banner(); render_room_view(0, 9999999999); } diff --git a/webcit-ng/static/js/view_forum.js b/webcit-ng/static/js/view_forum.js index 684046046..cfe9ac619 100644 --- a/webcit-ng/static/js/view_forum.js +++ b/webcit-ng/static/js/view_forum.js @@ -200,14 +200,18 @@ function forum_render_one(msg, existing_div) { + "" + " " + _("ReplyQuoted") - + "" + + ""; - + "" // Delete , show only with permission FIXME - + " " - + _("Delete") - + "" + if (can_delete_messages) { + outmsg += + "" // Delete (shown only with permission) + + " " + + _("Delete") + + ""; + } - + ""; // end buttons on right side + outmsg += + ""; // end buttons on right side if (msg.subj) { outmsg += "
" + msg.subj + ""; diff --git a/webcit-ng/webcit.h b/webcit-ng/webcit.h index 7e1667a8d..eeeac89b2 100644 --- a/webcit-ng/webcit.h +++ b/webcit-ng/webcit.h @@ -84,6 +84,7 @@ struct ctdlsession { int room_current_view; int room_default_view; int is_room_aide; // nonzero if the user has aide rights to THIS room + int can_delete_messages; // nonzeri if the user is permitted to delete messages in THIS room long last_seen; int new_messages; int total_messages; -- 2.39.2