A couple improvements regarding navigation

- Blogs can be added to the main menu
- Add permission checks to show/hide the menupart editors as needed
- Remove the unnecessary root node "main menu" when building the main menu

--HG--
branch : dev
This commit is contained in:
Suha Can
2010-02-11 11:10:14 -08:00
parent daefd9f624
commit c35c95546d
3 changed files with 17 additions and 3 deletions

View File

@@ -1,15 +1,30 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.Security;
namespace Orchard.Core.Navigation.Models { namespace Orchard.Core.Navigation.Models {
[UsedImplicitly] [UsedImplicitly]
public class MenuPartDriver : ContentPartDriver<MenuPart> { public class MenuPartDriver : ContentPartDriver<MenuPart> {
private readonly IAuthorizationService _authorizationService;
public MenuPartDriver(IAuthorizationService authorizationService) {
_authorizationService = authorizationService;
}
public virtual IUser CurrentUser { get; set; }
protected override DriverResult Editor(MenuPart part) { protected override DriverResult Editor(MenuPart part) {
if (!_authorizationService.TryCheckAccess(Permissions.ManageMainMenu, CurrentUser, part))
return null;
return ContentPartTemplate(part, "Parts/Navigation.EditMenuPart").Location("primary", "9"); return ContentPartTemplate(part, "Parts/Navigation.EditMenuPart").Location("primary", "9");
} }
protected override DriverResult Editor(MenuPart part, IUpdateModel updater) { protected override DriverResult Editor(MenuPart part, IUpdateModel updater) {
if (!_authorizationService.TryCheckAccess(Permissions.ManageMainMenu, CurrentUser, part))
return null;
updater.TryUpdateModel(part, Prefix, null, null); updater.TryUpdateModel(part, Prefix, null, null);
return ContentPartTemplate(part, "Parts/Navigation.EditMenuPart").Location("primary", "9"); return ContentPartTemplate(part, "Parts/Navigation.EditMenuPart").Location("primary", "9");
} }

View File

@@ -8,7 +8,7 @@ namespace Orchard.Core.Navigation.Models {
[UsedImplicitly] [UsedImplicitly]
public class MenuPartHandler : ContentHandler { public class MenuPartHandler : ContentHandler {
public MenuPartHandler(IRepository<MenuPartRecord> menuPartRepository) { public MenuPartHandler(IRepository<MenuPartRecord> menuPartRepository) {
Filters.Add(new ActivatingFilter<MenuPart>("blogpost")); Filters.Add(new ActivatingFilter<MenuPart>("blog"));
Filters.Add(new ActivatingFilter<MenuPart>("page")); Filters.Add(new ActivatingFilter<MenuPart>("page"));
Filters.Add(StorageFilter.For(menuPartRepository)); Filters.Add(StorageFilter.For(menuPartRepository));

View File

@@ -19,8 +19,7 @@ namespace Orchard.Core.Navigation.Services {
foreach (var menuPart in menuParts) { foreach (var menuPart in menuParts) {
if (menuPart != null ) { if (menuPart != null ) {
MenuPart part = menuPart; MenuPart part = menuPart;
builder.Add("main menu", "1", builder.Add(menu => menu
menu => menu
.Add(part.MenuText, part.MenuPosition)); .Add(part.MenuText, part.MenuPosition));
} }
} }