Working With Custom Hooks: OnUndoCheckOutAsset
The undo check out action replaces the checked out version of an asset with the state it was in when it was last checked in. This custom hook can save you from falling into the traps sometimes associated with this action.
In the context of the Ingeniux CMS platform, assets refer to content items like images, PDF documents, and even sometimes code that are stored in the CMS and published out to a publishing target. Assets differ from page types and components – which are created, edited, and managed directly in the CMS Site Tree – in that they are uploaded, or brought into the CMS, from outside of the platform. Once uploaded, they are stored in the Asset Management System (and usually placed into an Asset Schema) where they can be managed, edited in certain ways, and have metadata assigned to them.
Checking out a content item creates a working copy that is assigned to users for editing. The checked out version of a content item cannot be published until it is checked in – it will also have no history saved until it is checked in again.
When a check out action is undone, the checked out version of the asset is permanently lost - it reverts to the last checked in version of the asset.
How To Trigger the Hook
This method is triggered through the following actions:
- Right-clicking an Asset that is checked out and has no descendants and selecting Undo Checkout from the context menu.
- Right-clicking an Asset that is checked out and has descendants and selecting Undo Checkout > [Page] or [Page and Children] from the context menu.
- A CSAPI call to the UndoCheckout() method.
When to Use This Custom Hook
When the undo checkout action is taken on a content item, any changes that were made to that content item since it was checked out are lost. Once this action is taken, the loss of content is irreversible. For this reason, administrators might want to restrict or further control the use of this action.
Avoid using the method UndoCheckout() within these hooks to protect from infinite loops in your code.
Prevent Undo Checkout for restricted user group
Preventing the use of this action is the most obvious reason to use this hook. This example prevents the undo checkout action to be taken by certain groups, hard coded here as a group ID.
You will need to get the groups that the user is in and compare them to the group that should be prevented. If that group appears in the list, throw an exception. Any exception thrown will cancel the transaction and prevent the Undo Checkout from happening.
var groupUsers = session.UserManager.UserGroup("UserGroups/97").Users(out int count);
List<IUser> users = new List<IUser>();
if (groupUsers != null)
foreach (var user in groupUsers)
if (user != null)
var user = session.UserManager.CurrentUser;
if (users != null && users.Any())
//cancel action if belongs to the group
if (user != null && users.Contains(user))
throw new Exception("Denied Undo Check out - User Belongs to a restricted Group");
throw new Exception("Denied User Group for Check out");
Ways to Extend the Functionality Further
You might consider enhancing this script by having another way of building a list of groups that cannot use the action, such as a CSV or a naming convention for the group. Other reasons might also apply, such as whether the content item has ever been checked in before or if certain actions have been taken on the asset, such as translation input that could be a costly loss.