Search code examples
tridion

setting IsEditable=false for item disables save/close button but not save button?


I developed a data extender class that acts on GetItem and CheckOutItem commands to do some business-specific validation to determine whether the user should have access to modify the item or not (basically if it's past the initial "author" task in workflow, no one can edit it. by default Tridion allows "reviewers" in workflow to edit the item, which is a no-no in our business).

I am relatively certain this worked at one point, but now does not. I'm exploring what might have changed, but I thought I'd ask here in case anyone has an idea.

If the item can't be modified, I'm setting the IsEditable attribute to false. This does in fact disable the Save and Close button and Save and New button, but for some reason the Save button is enabled. I don't quite understand why there could be a difference. (I'm looking to see if someone extended the save button somehow, but I don't see that being done). Any thoughts on how the Save button would enable when the others aren't?

thanks for any suggestions,

~Warner

public override XmlTextReader ProcessResponse(XmlTextReader reader, PipelineContext context)
{
    using (new Tridion.Logging.Tracer())
    {
        string command = context.Parameters["command"].ToString();
        if (command == CHECKOUT_COMMAND || command == GETITEM_COMMAND)
        {
            XmlDocument xmlDoc = ExtenderUtil.GetExtenderAsXmlDocument(reader);
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
            nsmgr.AddNamespace("tcm", Constants.TcmNamespace);
            try
            {
                //is this a page or component?
                XmlNode thisItemNode = null;
                thisItemNode = xmlDoc.SelectSingleNode("//tcm:Component", nsmgr) ?? xmlDoc.SelectSingleNode("//tcm:Page", nsmgr);
                if (thisItemNode == null) return ExtenderUtil.GetExtenderAsXmlTextReader(xmlDoc);
                // need to impersonate system admin in order to get workflow version of item later
                Session sessionSystemAdmin = Util.SystemAdminSession;
                XmlAttribute idAttribute = thisItemNode.Attributes.GetNamedItem("ID") as XmlAttribute;
                //if ID attribute is null, we don't have the actual object being used (just a referenced item. so, we'll ignore it)
                if (idAttribute != null)
                {
                    string itemId = idAttribute.Value;
                    VersionedItem tridionObject = Util.ObtainValidTridionIdentifiableObject(sessionSystemAdmin, itemId) as VersionedItem;
                    //logic has been moved to separate method, just for maintainablility...
                    //the logic may change when workflow code is finished.
                    bool allowSave = IsItemValidForEdit(tridionObject, nsmgr);
                    if (!allowSave)
                    {
                        //not the WIP ("author") task... make item read-only
                        Logger.WriteVerbose("setting iseditable to false for item: " + itemId);
                        XmlAttribute isEditableAttribute = thisItemNode.Attributes.GetNamedItem("IsEditable") as XmlAttribute;
                        isEditableAttribute.Value = "false";
                    }
                }
            }
            catch (Exception e)
            {
                Logger.WriteError("problem with get item data extender", ErrorCode.CMS_DATAEXTENDER_GETITEM_FAILURE, e);
            }
            return ExtenderUtil.GetExtenderAsXmlTextReader(xmlDoc);
        }
        else
        {
            return reader;
        }
    }
}

Solution

  • The solution is to really look over the entire solution and be absolutely positive that nobody snuck something in recently that messes with the Save button and is magically enabling it behind the scenes. I've re-edited the code to show how I initially had it. And it does work. It will disable the save, save/close, save/new buttons and make all fields disabled. I'm sorry that I wasted Frank's time. Hopefully having this here for historical purposes may come in handy for someone else with similar requirements in the future.