Couldn't create content. Current user, <usename>, does not have EditContent permission.

Topics: Customizing Orchard
May 9, 2013 at 12:25 AM
Edited May 9, 2013 at 12:46 AM
Hi there,

How do you recommend troubleshooting this error. "Couldn't create content. Current user, dealer1, does not have EditContent permission."

dealer1 is in the Dealer role

Image

the Dealer role has the appropriate permissions for Crane Parts

Image

the Dealer has the appropriate permissions for Content

Image

the Dealer is not able to create content.

Image

What are we missing here?

Cheers.
Shaun.

P.S.

The problem partially resolves when we comment on this code:
 if (!Services.Authorizer.Authorize(Permissions.EditContent
    ,contentItem
    ,T("Couldn't create content")))
    return new HttpUnauthorizedResult();
Commenting this out only partially resolves it though. That is, we receive the "Your content has been created." Meanwhile, checking the DB reveals that content has actually NOT been created. Bummer.
May 9, 2013 at 4:58 AM
Hooray! We figured it out.

The problem involved routing. The Create.cshtml view creates a <form> via the following code:
@using (Html.BeginFormAntiForgeryPost(Url.Action("Create", new { ReturnUrl = Request.QueryString["ReturnUrl"] }))) {
    @Html.ValidationSummary()
    // Model is a Shape, calling Display() so that it is rendered using the most specific template for its Shape type
    @Display(Model)
}
The following method creates a form with a particular formAction.
 public static MvcForm BeginFormAntiForgeryPost(this HtmlHelper htmlHelper, string formAction) {
    return htmlHelper.BeginFormAntiForgeryPost(formAction, FormMethod.Post, new RouteValueDictionary());
}
Our problem was that the resultant form action was
action="/OrchardLocal/Admin/Contents/Create"
and we needed it to be
action="/OrchardLocal/Admin/Contents/Create/CraneProduct"
To resolve this we needed to change our routing from this...
new RouteDescriptor {
                    Priority = 5,
                    Route = new Route(
                        "DealerDashboard/Create",
                        new RouteValueDictionary {
                            {"area", "BigFont.DealerDashboard"},
                            {"controller", "Home"},
                            {"action", "Create"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "BigFont.DealerDashboard"}
                        },
                        new MvcRouteHandler())
                }
to this...
new RouteDescriptor {
                    Priority = 5,
                    Route = new Route(
                        "DealerDashboard/Create/{id}",
                        new RouteValueDictionary {
                            {"area", "BigFont.DealerDashboard"},
                            {"controller", "Home"},
                            {"action", "Create"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "BigFont.DealerDashboard"}
                        },
                        new MvcRouteHandler())
                }
All it took was adding /{id}, and then it worked. Persistence is a beautiful thing.

Cheers,
Shaun.