Pages

31 August, 2017

Automatically create new version for Lock & Edit without workflow

Sitecore will create a new version on Lock and Edit if the item is tied to a workflow. For our case, version has to be created even without using workflow. As mentioned by Dylan here, we can override the default behavior of Sitecore. Here we overridden the “Checkout” command which is executed on Lock & Edit.

Added a setting called EnableAddVersionWithoutWorkflow as a flag to enable this feature. If it is true, it will add a version and lock the new version for the user.

Note: By default, only a non-admin user will see the lock and edit button for an item.

if (!item.Locking.IsLocked()) {
  Log.Audit(this, "Start editing: {0}", new string[] {
    AuditFormatter.FormatItem(item)
  });
  if (Context.User.IsAdministrator) {
    item.Locking.Lock();
  }
  //Add new version if the custom flag is true
  else if (bool.Parse(Settings.GetSetting("EnableAddVersionWithoutWorkflow", "false"))) {
    Error.AssertObject(item, "item");
    if (StandardValuesManager.IsStandardValuesHolder(item)) {
      this.Lock(item);
    }
    Item item2 = item.Versions.AddVersion();
    if (item2 != null) {
      item = this.Lock(item2);
    }
  }
  //Add new version if the custom flag is true
  else {
    item = Context.Workflow.StartEditing(item);
  }
  Context.ClientPage.SendMessage(this, string.Concat(new object[] {
    "item:startediting(id=",
    item.ID,
    ",version=",
    item.Version,
    ",language=",
    item.Language,
    ")"
  }));

02 August, 2017

Access denied when attaching new media item.

When a Sitecore non-admin user tries to attach a media item, access denied error appears. 
This is due to incorrect Security settings in Sitecore. My Sitecore Version:  8.1 (rev. 160519)

Solution by Kasaku

3272 11:36:34 ERROR Application error.
Exception: System.Web.HttpUnhandledException
Message: Exception of type 'System.Web.HttpUnhandledException' was thrown.
Source: System.Web
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Nested Exception

Exception: System.Reflection.TargetInvocationException
Message: Exception has been thrown by the target of an invocation.
Source: mscorlib
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder
   , Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Sitecore.Web.UI.Sheer.ClientPage.OnLoad(EventArgs e)
   at Sitecore.Shell.Applications.Dialogs.Attach.AttachPage2.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Nested Exception

Exception: Sitecore.Exceptions.AccessDeniedException
Message: Application access denied.
Source: Sitecore.Kernel
   at Sitecore.Diagnostics.Assert.HasAccess(Boolean accessAllowed, String message)
   at Sitecore.Shell.Applications.Dialogs.Attach.AttachForm.OnLoad(EventArgs e)
blockquote { margin: 0; } blockquote p { padding: 15px; background: #eee; border-radius: 5px; } blockquote p::before { content: '\201C'; } blockquote p::after { content: '\201D'; }