This project is read-only.

Modify Content Summary list to show who last modified content item

Topics: Core, Customizing Orchard, General, Troubleshooting
Oct 16, 2012 at 9:56 PM

I'm sure it's well known that showing the owner instead of the last user who modified/published an item is not as expected.

I'd like to fix that; does Orchard actually keep this transaction? or is this a bug in the design?



Oct 16, 2012 at 11:04 PM
Edited Oct 16, 2012 at 11:53 PM

For those interested; I added support for it (since not knowing how) by:

Modfying the "Editor" function in the "/Core/Common/OwnerEditor/OwnerEditorDriver.cs" file to update the owner if it's different than the currently logged in user.

I did this in two places; to handle an admin user versus a non-admin user.

If the TryCheckAccess returns false; then I used a condition to check to see if the updater is null.  If the updater is NOT null; then I set the part.Owner = currentUser.

Since the above will not execute for an Admin user (because it doesn't fail).

I put a line of code after the "TryUpdateModel" - which transfers the edit box values; to then modify what the new model.Owner is to the currentUser.UserName.  Now that the two values may be different - it will properly update the part.Owner.

Now I can accurately see who has been making edits.

One optimization could be that instead of setting model.Owner to the currentUser.UserName; you can just set the part.Owner to currentUser; now the system will not have to lookup an already known valid user.

thanks - let me know if there's a better way.


Oct 16, 2012 at 11:58 PM

What do you mean it's not as expected? What's your expectation? Owner does not mean last person to modify the item. If that's what you want, you should add a new part for it.

Oct 17, 2012 at 12:20 AM

Well when the text says "last updated by:" - I would expect that it should say the last person to edit it; Is there a way to pull that information without modfying the owner? (can't seem to locate a way).

Even in the code itself for the OwnerEditor - the deverloper put in comments about whether or not owner should be used; since it was that developers intent to show the last person to edit it; but since that didn't exist; just put it in there using the owner with a note to fix later.

So an easy question is: does Orchard currently support a way to track this; I didn't see anything obvious in the database; and based on the comments in the code; it was really the intent to show who was the last person to publish the item; but he/she didn't know how.

Any insight would be great.

Are you thinking a new field should be added to common called "updatedby" and then set that field; then modify the rendering to support this new field.  Sounds easy enough; but in either case I'd still need to modify the driver to support this?


Oct 17, 2012 at 12:56 AM

It's that text that would need to be changed then... Except that I can't find a trace of it, and when I look at any content item, it says "owner", not "last modified by". I can't find that comment you are referring to either. And I was there at the design meetings, and it was never intended to be the last modifier. Can you point me to your sources?

You would not need to modify the driver to support this, as it should be implemented in a *new* part.

Oct 17, 2012 at 1:42 AM
Edited Oct 17, 2012 at 1:45 AM

I'm not %100 sure on how to-do this as a seperate part without having to copy/paste everything that the admincontroller already does as well as the admin cshtml.

The file I saw this in is: "/Core/Common/Views/CommonMetadataOwner.cshtml".

This will help my understanding of Orchard alot - is there a way for me to add a "PublishedBy" field to CommonPart via let's say a new module; and then leverage everything that the already admin controller etc has; so that my module only needs to handle the publish event; and then my new module would have a copy of the admin edit templates in order to show it at the proper places etc.

I know how I'd do this from scratch - but that would be alot of work; I'd like to have my module only perform actions on this one new field on an exsting part and let all the existing stuff still do what it does.

Any help with that will greatly help with my knowledge of exactly what does it take to override a shapes behavior but still use the existing code by calling the necessary functions.

Is there a way to-do this strictly from the UI and cshtml files within my themes folder? (e.g. by adding the field to CommonPart and then changing any CSHTML files both for the admin and rendering templates. Do Admin templates support alternates as well?)



Oct 17, 2012 at 4:27 AM

Well, you could add a field to the existing part, but this should really be a property. Of course, you can't add a new property to a part that is defined in another module. That's why I was saying it should be a separate part. I strongly recommend against cutting corners in general, and in particular doing any work that is not related to rendering from the views or from the theme.

Oct 17, 2012 at 3:58 PM

yeah - got me there; just didn't know how much effort to put into it; since it's most likely going to get added to commonpart eventually.

I'll put this on my to-do list; although I must admit - I really like how it works now that I update the owner.  I'll transition it so that it's not noticable when I do the switchover.

thanks - great information!

Oct 17, 2012 at 4:20 PM

Maybe file a bug then.