From 655245393a5d3f06bb47aee8c6f431c05ca3214d Mon Sep 17 00:00:00 2001 From: san7890 Date: Wed, 6 Dec 2023 19:00:35 -0700 Subject: [PATCH] Turns the "Admin Permission Elevation Notification" into a macro (#80149) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## About The Pull Request Turns this boilerplate message into a centralized macro because this code is important, but not so important that every coder know the nitty gritty details of it. In case someone wants to add more logging/handling (or update the message), there's now a central macro to update for all nine events in which we check. This shouldn't break anything because it's the exact same thing we were doing previously and the early return checks are still all there, but it does work on my machine regardless ✔️ ![image](https://github.com/tgstation/tgstation/assets/34697715/db4405d3-e57d-4c29-8a01-b32ba185041b) --- code/__DEFINES/admin.dm | 1 + code/__HELPERS/admin.dm | 7 +++++++ code/modules/admin/admin_ranks.dm | 12 +++--------- code/modules/admin/holder2.dm | 24 ++++++------------------ 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/code/__DEFINES/admin.dm b/code/__DEFINES/admin.dm index ceb30e7591f..fbc223f62a5 100644 --- a/code/__DEFINES/admin.dm +++ b/code/__DEFINES/admin.dm @@ -174,3 +174,4 @@ GLOBAL_VAR_INIT(ghost_role_flags, ALL) /// Used in logging uses of admin verbs (and sometimes some non-admin or debug verbs) to the blackbox /// Only pass it a string key, the verb being used. #define BLACKBOX_LOG_ADMIN_VERB(the_verb) SSblackbox.record_feedback("tally", "admin_verb", 1, the_verb) + diff --git a/code/__HELPERS/admin.dm b/code/__HELPERS/admin.dm index 94f61ef0152..8564937f9c6 100644 --- a/code/__HELPERS/admin.dm +++ b/code/__HELPERS/admin.dm @@ -1,3 +1,10 @@ /// Returns if the given client is an admin, REGARDLESS of if they're deadminned or not. /proc/is_admin(client/client) return !isnull(GLOB.admin_datums[client.ckey]) || !isnull(GLOB.deadmins[client.ckey]) + +/// Sends a message in the event that someone attempts to elevate their permissions through invoking a certain proc. +/proc/alert_to_permissions_elevation_attempt(mob/user) + var/message = " has tried to elevate permissions!" + message_admins(key_name_admin(user) + message) + log_admin(key_name(user) + message) + diff --git a/code/modules/admin/admin_ranks.dm b/code/modules/admin/admin_ranks.dm index baa8a291974..c39464e3ef0 100644 --- a/code/modules/admin/admin_ranks.dm +++ b/code/modules/admin/admin_ranks.dm @@ -13,9 +13,7 @@ GLOBAL_PROTECT(protected_ranks) /datum/admin_rank/New(init_name, init_rights, init_exclude_rights, init_edit_rights) if(IsAdminAdvancedProcCall()) - var/msg = " has tried to elevate permissions!" - message_admins("[key_name_admin(usr)][msg]") - log_admin("[key_name(usr)][msg]") + alert_to_permissions_elevation_attempt(usr) if (name == "NoRank") //only del if this is a true creation (and not just a New() proc call), other wise trialmins/coders could abuse this to deadmin other admins QDEL_IN(src, 0) CRASH("Admin proc call creation of admin datum") @@ -35,9 +33,7 @@ GLOBAL_PROTECT(protected_ranks) /datum/admin_rank/Destroy() if(IsAdminAdvancedProcCall()) - var/msg = " has tried to elevate permissions!" - message_admins("[key_name_admin(usr)][msg]") - log_admin("[key_name(usr)][msg]") + alert_to_permissions_elevation_attempt(usr) return QDEL_HINT_LETMELIVE . = ..() @@ -47,9 +43,7 @@ GLOBAL_PROTECT(protected_ranks) // Adds/removes rights to this admin_rank /datum/admin_rank/proc/process_keyword(group, group_count, datum/admin_rank/previous_rank) if(IsAdminAdvancedProcCall()) - var/msg = " has tried to elevate permissions!" - message_admins("[key_name_admin(usr)][msg]") - log_admin("[key_name(usr)][msg]") + alert_to_permissions_elevation_attempt(usr) return var/list/keywords = splittext(group, " ") var/flag = 0 diff --git a/code/modules/admin/holder2.dm b/code/modules/admin/holder2.dm index 8cb57ff8f83..4df4e19b709 100644 --- a/code/modules/admin/holder2.dm +++ b/code/modules/admin/holder2.dm @@ -50,9 +50,7 @@ GLOBAL_PROTECT(href_token) /datum/admins/New(list/datum/admin_rank/ranks, ckey, force_active = FALSE, protected) if(IsAdminAdvancedProcCall()) - var/msg = " has tried to elevate permissions!" - message_admins("[key_name_admin(usr)][msg]") - log_admin("[key_name(usr)][msg]") + alert_to_permissions_elevation_attempt(usr) if (!target) //only del if this is a true creation (and not just a New() proc call), other wise trialmins/coders could abuse this to deadmin other admins QDEL_IN(src, 0) CRASH("Admin proc call creation of admin datum") @@ -79,17 +77,13 @@ GLOBAL_PROTECT(href_token) /datum/admins/Destroy() if(IsAdminAdvancedProcCall()) - var/msg = " has tried to elevate permissions!" - message_admins("[key_name_admin(usr)][msg]") - log_admin("[key_name(usr)][msg]") + alert_to_permissions_elevation_attempt(usr) return QDEL_HINT_LETMELIVE . = ..() /datum/admins/proc/activate() if(IsAdminAdvancedProcCall()) - var/msg = " has tried to elevate permissions!" - message_admins("[key_name_admin(usr)][msg]") - log_admin("[key_name(usr)][msg]") + alert_to_permissions_elevation_attempt(usr) return GLOB.deadmins -= target GLOB.admin_datums[target] = src @@ -101,9 +95,7 @@ GLOBAL_PROTECT(href_token) /datum/admins/proc/deactivate() if(IsAdminAdvancedProcCall()) - var/msg = " has tried to elevate permissions!" - message_admins("[key_name_admin(usr)][msg]") - log_admin("[key_name(usr)][msg]") + alert_to_permissions_elevation_attempt(usr) return GLOB.deadmins[target] = src GLOB.admin_datums -= target @@ -119,9 +111,7 @@ GLOBAL_PROTECT(href_token) /datum/admins/proc/associate(client/client) if(IsAdminAdvancedProcCall()) - var/msg = " has tried to elevate permissions!" - message_admins("[key_name_admin(usr)][msg]") - log_admin("[key_name(usr)][msg]") + alert_to_permissions_elevation_attempt(usr) return if(!istype(client)) @@ -163,9 +153,7 @@ GLOBAL_PROTECT(href_token) /datum/admins/proc/disassociate() if(IsAdminAdvancedProcCall()) - var/msg = " has tried to elevate permissions!" - message_admins("[key_name_admin(usr)][msg]") - log_admin("[key_name(usr)][msg]") + alert_to_permissions_elevation_attempt(usr) return if(owner) GLOB.admins -= owner