Orchard as a component in mvc 3 app

Topics: General
May 16, 2011 at 8:00 AM

Hi,

I need to build an MVC 3 application. In that application I need some CMS functionality. It is a web application. The web application has a front end that is available to all users. This is something I want to build in orchard. Secondly, after logging in, I need exta menu items that contain custom functionality. This functionality is not CMS related and I want to build it in plain MVC3. Is there somewhere a good tutorial that explains how one should do this?

Regards,
Patrick

May 16, 2011 at 11:42 AM

When you say "not CMS related" what do you really mean? The term "Content Management" covers pretty much any admin UI on a website one way or another. Everything Is Content ;)

What I'm suggesting is that you use Orchard as a basis for your app, and implement your custom features as module(s). Orchard modules are basically MVC areas but with a ton of optional extra features that Orchard makes available for you. This is how Orchard is designed to be used and in the long run it'll be much easier than trying to "slot in" Orchard merely for page and blog editing (which is what I assume you're limiting your definition of CMS to).

May 16, 2011 at 12:31 PM

That is indeed what I want to do.

I think a CMS is right for the content part of a website. But when I want to for instance develop an online banking application, I only want to build the website part in Orchard and the online banking part in MVC3. But I want to integrate them to give the user a seamless experience. When the user is not logged in, he/she should only see the general content and when the user is logged it he/she should get some extra menus where the user has authorization on and from there it should get into the banking application while staying on 1 site.

(The banking application is just an example, Im not building a banking application).

 

May 16, 2011 at 2:23 PM

You could build a banking application in Orchard. What I'm getting at is that "content management" is a very broad term.

If you build your features as Orchard modules, they are MVC3 - and everything from Orchard is optional (although it'd help you a lot to use Orchard's membership and security services for instance)

May 16, 2011 at 2:33 PM

So it is possible to include your own storage model under a orchard module? Maybe I have the wrong understanding that everything is pushed in a generic datamodel. Is there any sample how to do this? Secondly, is it possible to give a user specific authorization to a module? So that only when that user is logged in it shows up in its menu?
Furthermore is it possible to extend the account information with for instance Company name, gender, birthdate etc?

If this is just as easy, than you are right, Orchard is the way to go.

Patrick

May 16, 2011 at 2:55 PM

The data perisistence layer in Orchard is NHibernate. Your module can have its own Migrations that set up new tables or modify existing ones (e.g. when you are updating the module). So you can define whatever storage model you like for your custom tables. There are plenty of examples - have you read through the documentation on orchardproject.net, particularly the "hello world" module sample and also the article on 1-N and N-N relationships?

Then there's the content management system; it still isn't a generic datamodel, it's a whole set of one-to-one joined tables. A module will add new content parts; these parts stored their data in individual tables which are then "welded" onto the content item at runtime. So it's a lot more complex in there than it seems.

There's also a system of roles and permissions. You can add your own custom permissions, and then use these to control whether menu items appear or not.

Users are just represented by a content item. You could look at the Profile module for an example of extended the User content item with additional data, although it may not be exactly what you need. But yes, you can attach new parts and fields to the User content type.

May 16, 2011 at 3:32 PM

OK, I understand now how building modules could help me out with the custom functionality and the extra info at the users. The only thing is that I can not see how I can do advanced access control. Do you have a sample of that?

Patrick

May 16, 2011 at 3:45 PM

In your controller actions you can check for specific permissions. The built-in modules all do this. And you can write an INavigationProvider that will populate a menu based on certain permissions which you can specified. Do you mean anything else when you say "advanced access control"?

May 16, 2011 at 3:49 PM
Edited May 16, 2011 at 3:51 PM

I did not explained correct what I mean. I understand that I can check for permissions in the controller. But how can I prevent something from showing up in the menu when you don't have access to it?

Patrick

edit: I think what I'm looking for is discussed in this thread: http://orchard.codeplex.com/discussions/242714

May 16, 2011 at 4:19 PM

If you provide menu items with INavigationProvider, you can pass permissions objects along with it which are required for the menu to show up.

May 17, 2011 at 6:21 PM

Thanks for your reply. Is there somewhere documentation on how one should implement the INavigationProvider to make sure a menu item is only shown to for instance an admin user and not to normal users?

Coordinator
May 17, 2011 at 6:28 PM

There are many examples in the code. One is Orchard.Tags.AdminMenu.

May 17, 2011 at 6:39 PM
Edited May 17, 2011 at 6:47 PM

Sorry, I'm not understanding exactly how I'm going to translate this into what I need. But I hope you can help me out. Lets say I want to add the Dashboard to the main menu, but only when the admin is logged in, how do I do that? Or lets say a Blog, I want to add a blog that is only accessible (and shows up only in the menu) for someone that is logged in with the role "blogger".

Coordinator
May 17, 2011 at 6:49 PM

Oh sorry, I thought you meant for admin menu items. For the front end, you'll have to check the permissions explicitly when adding the item. You can do that by injecting a IAuthorizationService and calling TryCheckAccess on it (see MenuItemPartDriver for an example).

May 17, 2011 at 6:56 PM
Edited May 17, 2011 at 6:57 PM

I hope I manage to figure out how I should do this with the hints you gave me.

Wouldnt it be easyer to have in the menu section of the admin page a way to specify roles to front end menu items?

Coordinator
May 17, 2011 at 7:04 PM

It sure would be easier but that's a new feature (that is implemented by the advanced menu if I'm not mistaken). We take contributions ;)

May 17, 2011 at 7:28 PM
still_the_same wrote:

Sorry, I'm not understanding exactly how I'm going to translate this into what I need. But I hope you can help me out. Lets say I want to add the Dashboard to the main menu, but only when the admin is logged in, how do I do that? Or lets say a Blog, I want to add a blog that is only accessible (and shows up only in the menu) for someone that is logged in with the role "blogger".

There's an issue with this currently. There's no "View" permission, so you can't restrict content items from being viewed by anyone, as long as they use the built-in RoutePart. There are some hackish ways to work around this problem depending on the scenario. However, for anything that you write your own Controller for, you can require any permissions you like. So for anything security-critical you need to be writing your own routes / controllers (which of course you'd be doing ordinarily in MVC 3 anyway). The key thing is that you are looking at two fairly separate areas of functionality when you want to both hide a menu item and restrict access to that URL.

May 18, 2011 at 3:27 PM

Thanks for all answers. My main problem is that I'm not that confident in Orchard to figure out how to hack-it-to-work. In an upcomming project I would like to use Orchard. Would it be possible for someone to create a very simple demo-solution that just has one module that only is available and visible for the users in role "testrole". This would really help me decide if Orchard is the way to go (the rest of the things I need work as I want).

Patrick

May 18, 2011 at 3:39 PM

Well ... the only way to get confident enough is to actually start playing around with it yourself. And it's not as simple as "module is or isn't available to x role" - it's on a case-by-case basis regarding where it surfaces menus and controllers. There are plenty of examples of this built into Orchard's core modules so the best demo you can get is Orchard itself.