Copied to clipboard

Flag this post as spam?

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


  • manila 238 posts 540 karma points
    Oct 26, 2017 @ 11:25
    manila
    0

    Umbraco angular logResource.getUserLog returns 404 error

    I am trying to build a custom dashboard listing last edits made by a user.

    I am following the tutorial https://our.umbraco.org/documentation/Tutorials/Creating-a-Custom-Dashboard/#i-know-what-you-did-last-tuesday

    It uses logResource and its getUserLog method.

    logResource.getUserLog("save", new Date()).then(function (response) {
        console.log(response);
        var logEntries = [];
        alert('its here!');
    });
    

    And also I can see the method getUserLogs described in the umbraco api reference: https://our.umbraco.org/apidocs/ui/#/api/umbraco.resources.logResource

    However when I'm running this method I'm getting 404 error on

     Request error: The URL returned a 404 (not found):
     /umbraco/backoffice/UmbracoApi/Log/GetCurrentUserLog 
    

    Am I missing any umbraco extension or so?

    View:

    <div class="redirecturlsearch" ng-controller="Umbraco.Dashboard.LastEditsController as vm">
        <umb-editor-sub-header>
            <h1>Last edits</h1>
            <h3>User: {{vm.UserName}}</h3>
    
            <h2>We know what you edited last week...</h2>
            <ul class="unstyled">
                <li ng-repeat="logEntry in vm.LogEntries"><i class="{{logEntry.Content.icon}}"></i> <a href="#">{{logEntry.Content.name}}</a> - <span class="text-muted">(Edited on: {{logEntry.timestamp  | date:'medium'}})</span></li>
            </ul>
    
        </umb-editor-sub-header>
    </div>
    
  • Marc Goodson 995 posts 6568 karma points MVP 4x c-trib
    Oct 26, 2017 @ 19:27
    Marc Goodson
    0

    Hi manila

    Which version of Umbraco are you using?

    As the logResource had a bug up until Umbraco 7.6.4 preventing multiple parameters being passed to the GetCurrentUserLog endpoint:

    see http://issues.umbraco.org/issue/U4-9489

    and that may be the problem you are encountering?

    regards

    Marc

  • manila 238 posts 540 karma points
    Oct 30, 2017 @ 15:03
    manila
    0

    Version 7.5.14

    I don't think this is the issues as my error returns 404 so it cannot find the url at all.

    The url is build in a function defined in resources.js

    getUserLog: function (type, since) {            
            return umbRequestHelper.resourcePromise(
               $http.get(
                   umbRequestHelper.getApiUrl(
                       "logApiBaseUrl",
                       "GetCurrentUserLog",
                       [{ logtype: type, sinceDate: since }])),
               'Failed to retrieve user data for id ' + id);
        }
    

    It looks like it gets wrong the url to action it builds.

  • Marc Goodson 995 posts 6568 karma points MVP 4x c-trib
    Oct 31, 2017 @ 10:54
    Marc Goodson
    100

    Hi manila

    Yes, I think that is the bug, and what is resolved by the fix, essentially the logAPIBaseUrl GetCurrentUserLog isn't expecting the parameters to be passed in that way... eg as a single dictionary, the method above should be:

              umbRequestHelper.getApiUrl(
                         "logApiBaseUrl",
                         "GetCurrentUserLog",
                        [{ logtype: type}, {sinceDate: since }])),
                 'Failed to retrieve log data for current user of type ' + type + ' since ' + since);
          }
    

    (so if you change that in your resource.js file all should be ok)

    Two things are wrong:

    1) The sinceDate and logType need to be passed as seperate values, not a single dictionary

    2) if you look at the error message 'Failed to retrieve user data for id, it's writing out an + id variable that doesn't exist - the error message has been copied and pasted from a different endpoint!

    regards

    Marc

  • manila 238 posts 540 karma points
    Nov 01, 2017 @ 08:45
    manila
    0

    You are right! Thanks

  • manila 238 posts 540 karma points
    Nov 01, 2017 @ 09:13
    manila
    0

    Well, still it doesn't look as it suppose I think.

    No matter what date I pass to the function it seems to be ignoring it and returns some items but for sure not all the items which have been edited by the user within even the time period it takes into account.

    Eg.

    I'm passing 10 Oct 2017 or 1 Nov 2017 and it returns some items (always same items no matter the date) since 26 Oct but not the all content/ media that have been edited.

    So it looks like the since parameter is ignored whatsoever and the items array returned are based on something else.

    (new Date(2017,9,11) in the example below gives Date 2017-10-10T23:00:00.000Z)

    logResource.getUserLog("save", new Date(2017,9,11)).then(function (response) {
        console.log(response);
        var logEntries = [];
        //alert('its here!');
    
        // loop through the response, and filter out save log entries we are not interested in
        angular.forEach(response, function (item) {
        //    // if no entity exists -1 is returned for the nodeId (eg saving a macro would create a log entry without a nodeid)
            if (item.nodeId > 0) {
                //this is the only way to tell them apart - whether the comment includes the words Content or Media!!
                if (item.comment.match("(\\bContent\\b|\\bMedia\\b)")) {
                    if (item.comment.indexOf("Media") > -1) {
                        //log entry is a media item
                        item.entityType = "Media";
                        item.editUrl = "media/media/edit/" + item.nodeId;
                    }
                    if (item.comment.indexOf("Content") > -1) {
                        //log entry is a media item
                        item.entityType = "Document";
                        item.editUrl = "content/content/edit/" + item.nodeId;
                    }
                    //use entityResource to retrieve details of the content/media item
                    entityResource.getById(item.nodeId, item.entityType).then(function (ent) {
                        console.log(ent);
                        item.Content = ent;
                    });
                    logEntries.push(item);
                }
            }
            console.log(logEntries);
            vm.LogEntries = logEntries;
        });
    });
    
  • Thomas Hansen 116 posts 331 karma points
    Jul 19, 2019 @ 18:22
    Thomas Hansen
    0

    Did you get this to work ?

    i Umbraco 8, i'm getting this:

    Message":"No HTTP resource was found that matches the request URI 'http://eight.local/umbraco/backoffice/UmbracoApi/Log/GetLog?logtype=save&sinceDate=2019-07-19T18%3A19%3A06.095Z'.","MessageDetail":"No action was found on the controller 'Log' that matches the name 'GetLog'.
    

    ...

  • Kasper Skov 6 posts 76 karma points
    Sep 09, 2019 @ 15:08
    Kasper Skov
    0

    Thomas did you resolve the issue in version 8? I'm having the same headache.

  • manila 238 posts 540 karma points
    Sep 09, 2019 @ 19:53
    manila
    0

    Unfortunately not. And I am not working on this project any more so cannot see if there was any follow up or not.

  • Marc Goodson 995 posts 6568 karma points MVP 4x c-trib
    Sep 09, 2019 @ 21:37
    Marc Goodson
    0

    In V8 there is the GetPagedCurrentUserLog method... but this only works as expected in 8.1.4 and above:

    github.com/umbraco/Umbraco-CMS/issues/6000

Please Sign in or register to post replies

Write your reply to:

Draft