Resolve audit log user IDs

This script calls the Jira user API, resolves user IDs in the Jira audit log and replaces them with the display names.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Resolve audit log user IDs
// @namespace    http://schuppentier.org/
// @version      2024-02-19
// @description  This script calls the Jira user API, resolves user IDs in the Jira audit log and replaces them with the display names.
// @author       You
// @match        https://*.atlassian.net/auditing/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=atlassian.net
// @grant        none
// @require      https://bowercdn.net/c/arrive-2.4.1/minified/arrive.min.js
// @license      MIT
// ==/UserScript==

/* jshint esversion: 8 */

(function() {
    'use strict';

    const resolveUserId = async (userId) => {
        const userResponse = await fetch(`/rest/api/3/user?accountId=${userId}`);
        const userObject = await userResponse.json();
        const userDisplayName = userObject.displayName;
        return userDisplayName;
    };

    document.arrive("span.delta-from, span.delta-to", async (elem) => {
        const detailsRow = elem.closest("tr.record-row-details");
        const recordRow = detailsRow.previousElementSibling;
        const summary = recordRow.querySelector("td.summary").innerText;
        if (summary != "Project roles changed") {
            return;
        }

        const fromElem = detailsRow.querySelector("span.delta-from");
        const toElem = detailsRow.querySelector("span.delta-to");

        var fromUserIds = new Set(fromElem.innerText.split(",").map(item => item.trim()));
        var toUserIds = new Set(toElem.innerText.split(",").map(item => item.trim()));

        const duplicateUserIds = fromUserIds.intersection(toUserIds);

        fromUserIds = fromUserIds.difference(duplicateUserIds);
        toUserIds = toUserIds.difference(duplicateUserIds);

        const fromUserNames = await Promise.all(fromUserIds.map(resolveUserId));
        const toUserNames = await Promise.all(toUserIds.map(resolveUserId));

        fromElem.innerText = fromUserNames.join(", ");
        toElem.innerText = toUserNames.join(", ");
    });
})();