Exploring is admin panel open or not

Topics: Administration, Core, Customizing Orchard, General, Troubleshooting, Writing modules
Dec 10, 2012 at 9:42 AM
Edited Dec 10, 2012 at 11:01 AM

How can I explore in code what page is opened right now ,"admin panel" or "front-end"?

Besides I would like not to be able to edit custom forms submissions in admin panel. Is it possible? Where can I disable this feature for custom forms?

Developer
Dec 10, 2012 at 10:43 AM

You can use the following code to determine whether you're in the back end:

var isBackend = AdminFilter.IsApplied(requestContext);

AdminFilter lives in the Orchard.UI.Admin namespace. Depending on where you are in code, there are several ways to get your hands on a RequestContext:

  1. You get one passed in as an argument
  2. Inject one via the class constructor
  3. New up a new instance, passing in the current HttpContext.

If you have ReSharper installed you can find all usages of the IsApplied method, which will show you many usages.

Dec 10, 2012 at 11:06 AM

Ok. Thanks!

And I would like not to be able to edit custom forms submissions in admin panel. Is it possible? Where can I disable this feature for custom forms?

Developer
Dec 10, 2012 at 11:15 AM

Sorry, that I don't know, although I do see some permission checks in the AdminController:

if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage customForm")))
                return new HttpUnauthorizedResult();

So that looks to me like if the user is not a site owner, he is not able to list or edit custom forms.

 

Dec 10, 2012 at 2:29 PM
Edited Dec 10, 2012 at 2:45 PM

Yes. But there is another issue. I want to be able to open custom forms submissions Edit link, but I would like to see there something else than edit capability. For example, I have custom form consisting of two textboxes ("FirstName" and "LastName"). I fill this form and click Submit. Then I go to admin panel -> Forms (in left menu) -> there is only one custom form "Contact Us". Then I click Submissions -> there I can see one item. When click on name of this item the Edit page of this item is opened. And I can see two textboxes ("FirstName" and "LastName") as in front-end and two buttons ("Save" and "Publish Now"). I know it's an editor shape, but I would like to use another shape in this case. Is it possible?

Besides, all of my submitted items of Contact Us form are named as "Contact Form" (like content type name). I would like they to be named "FirstName LastName" for example.