mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 21:13:35 +08:00
Further work updating security model
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045825
This commit is contained in:
@@ -3,6 +3,8 @@ using Orchard.Core.Settings.Models;
|
||||
using Orchard.Core.Settings.ViewModels;
|
||||
using Orchard.Localization;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
using Orchard.Settings;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
@@ -10,40 +12,43 @@ namespace Orchard.Core.Settings.Controllers {
|
||||
[ValidateInput(false)]
|
||||
public class AdminController : Controller, IUpdateModel {
|
||||
private readonly ISiteService _siteService;
|
||||
private readonly IContentManager _modelManager;
|
||||
private readonly INotifier _notifier;
|
||||
public IOrchardServices Services { get; private set; }
|
||||
|
||||
public AdminController(ISiteService siteService, IContentManager modelManager, INotifier notifier) {
|
||||
public AdminController(ISiteService siteService, IOrchardServices services) {
|
||||
_siteService = siteService;
|
||||
_modelManager = modelManager;
|
||||
_notifier = notifier;
|
||||
Services = services;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ActionResult Index(string tabName) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageSettings, T("Not authorized to manage settings")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var model = new SettingsIndexViewModel {
|
||||
Site = _siteService.GetSiteSettings().As<SiteSettings>()
|
||||
};
|
||||
model.ViewModel = _modelManager.BuildEditorModel(model.Site);
|
||||
model.ViewModel = Services.ContentManager.BuildEditorModel(model.Site);
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Index")]
|
||||
public ActionResult IndexPOST(string tabName) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageSettings, T("Not authorized to manage settings")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var viewModel = new SettingsIndexViewModel { Site = _siteService.GetSiteSettings().As<SiteSettings>() };
|
||||
viewModel.ViewModel = _modelManager.UpdateEditorModel(viewModel.Site.ContentItem, this);
|
||||
viewModel.ViewModel = Services.ContentManager.UpdateEditorModel(viewModel.Site.ContentItem, this);
|
||||
|
||||
if (!TryUpdateModel(viewModel)) {
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
_notifier.Information(T("Settings updated"));
|
||||
Services.Notifier.Information(T("Settings updated"));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
#region IUpdateModel Members
|
||||
|
||||
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
|
||||
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
|
||||
@@ -52,7 +57,5 @@ namespace Orchard.Core.Settings.Controllers {
|
||||
void IUpdateModel.AddModelError(string key, LocalizedString errorMessage) {
|
||||
ModelState.AddModelError(key, errorMessage.ToString());
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user