Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gleb Kaplan 49 posts 125 karma points
    May 09, 2016 @ 11:09
    Gleb Kaplan
    0

    Adding Courier events into audit log.

    For a while we have been experiencing difficulties with Courier auditing, as there is no way to log Courier deployments out of the box.

    Unfortunately it seems like all Courier events are executed in a background thread without access to current user context. That prevents developer from simply subscribing to an event and logging from there, as described here.

    I came up with a quick and simple solution, although it requires modification in Courier files.

    1) Create API controller as below:

    public class CourierController : UmbracoAuthorizedApiController
    {
        [HttpGet]
        public void AuditLog(Guid itemid)
        {
            var audit = Services.AuditService;
            var item = Services.ContentService.GetById(itemid);
            audit.Add(AuditType.Publish, "Deployed using Courier", Security.CurrentUser.Id, item.Id);
        }
    }
    

    2) Add call to the controller from within Umbraco\Plugins\courier\dialogs\CommitItem.aspx

        jQuery(document).ready(function () {
            jQuery("#buttons input").click(function () {
    
                //LOG AUDIT EVENT
                jQuery.ajax({
                    type: "GET",
                    url: "/umbraco/backoffice/api/Courier/AuditLog?itemid=<%=Request["itemid"]%>"
                });
    
               //END LOG AUDIT EVENT
    
               jQuery("#buttons").hide();
                    jQuery(".bar").show();
                    var msg = jQuery("#loadingMsg").html();
                    if (msg != '')
                        jQuery(".bar").find("small").text(msg);
            });
        });
    

    After the deployment you will be able to see Courier events in the audit trail:

    enter image description here

    As you can see, any deployment attempt will be audited immediately once a user clicks the "Deploy" button, even if the deployment was not successful. You can improve the solution, by moving the call to API so it will be performed only after successful deployment.

Please Sign in or register to post replies

Write your reply to:

Draft