mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 04:43:35 +08:00
- Site Settings Package implementation.
- General site settings admin. - Modifying RolesBasedAuthentication service to use injected CurrentSite to look up the Super User name from the site settings when checking for permissions. --HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4041295
This commit is contained in:
@@ -70,6 +70,13 @@
|
||||
<Compile Include="Common\Records\CommonRecord.cs" />
|
||||
<Compile Include="Common\Records\RoutableRecord.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Settings\AdminMenu.cs" />
|
||||
<Compile Include="Settings\Controllers\AdminController.cs" />
|
||||
<Compile Include="Settings\Models\SiteDriver.cs" />
|
||||
<Compile Include="Settings\Models\SiteModel.cs" />
|
||||
<Compile Include="Settings\Records\SiteSettingsRecord.cs" />
|
||||
<Compile Include="Settings\Services\SiteService.cs" />
|
||||
<Compile Include="Settings\ViewModels\SettingsIndexViewModel.cs" />
|
||||
<Compile Include="XmlRpc\Controllers\HomeController.cs" />
|
||||
<Compile Include="XmlRpc\Controllers\LiveWriterController.cs" />
|
||||
<Compile Include="XmlRpc\IXmlRpcHandler.cs" />
|
||||
@@ -86,6 +93,7 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Common\Package.txt" />
|
||||
<Content Include="Settings\Package.txt" />
|
||||
<Content Include="Settings\Views\Admin\Index.aspx" />
|
||||
<Content Include="Web.config" />
|
||||
<Content Include="XmlRpc\Package.txt" />
|
||||
<Content Include="XmlRpc\Views\Home\Index.aspx" />
|
||||
@@ -97,10 +105,10 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Settings\Controllers\" />
|
||||
<Folder Include="Settings\Models\" />
|
||||
<Folder Include="Settings\Services\" />
|
||||
<Folder Include="Settings\Views\Admin\" />
|
||||
<Content Include="Settings\Views\Web.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="XmlRpc\Views\Web.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||
|
13
src/Orchard.Web/Core/Settings/AdminMenu.cs
Normal file
13
src/Orchard.Web/Core/Settings/AdminMenu.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
namespace Orchard.Core.Settings {
|
||||
public class AdminMenu : INavigationProvider {
|
||||
public string MenuName { get { return "admin"; } }
|
||||
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
builder.Add("Settings", "11",
|
||||
menu => menu
|
||||
.Add("General", "2.0", item => item.Action("Index", "Admin", new { area = "Settings" })));
|
||||
}
|
||||
}
|
||||
}
|
42
src/Orchard.Web/Core/Settings/Controllers/AdminController.cs
Normal file
42
src/Orchard.Web/Core/Settings/Controllers/AdminController.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Core.Settings.Models;
|
||||
using Orchard.Core.Settings.ViewModels;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Settings;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Core.Settings.Controllers {
|
||||
[ValidateInput(false)]
|
||||
public class AdminController : Controller {
|
||||
private readonly ISiteService _siteService;
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public AdminController(ISiteService siteService, INotifier notifier) {
|
||||
_siteService = siteService;
|
||||
_notifier = notifier;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ActionResult Index() {
|
||||
var model = new Orchard.Core.Settings.ViewModels.SettingsIndexViewModel {
|
||||
SiteSettings = _siteService.GetSiteSettings().As<SiteModel>() };
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[AcceptVerbs(HttpVerbs.Post)]
|
||||
public ActionResult Index(FormCollection input) {
|
||||
var viewModel = new SettingsIndexViewModel { SiteSettings = _siteService.GetSiteSettings().As<SiteModel>() };
|
||||
UpdateModel(viewModel.SiteSettings, input.ToValueProvider());
|
||||
try {
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
_notifier.Error("Editing Settings failed: " + exception.Message);
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
src/Orchard.Web/Core/Settings/Models/SiteDriver.cs
Normal file
17
src/Orchard.Web/Core/Settings/Models/SiteDriver.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Orchard.Core.Settings.Records;
|
||||
using Orchard.Data;
|
||||
using Orchard.Models.Driver;
|
||||
|
||||
namespace Orchard.Core.Settings.Models {
|
||||
public class SiteDriver : ModelDriverWithRecord<SiteSettingsRecord> {
|
||||
public SiteDriver(IRepository<SiteSettingsRecord> repository)
|
||||
: base(repository) {
|
||||
}
|
||||
|
||||
protected override void New(NewModelContext context) {
|
||||
if (context.ModelType == "site") {
|
||||
context.Builder.Weld<SiteModel>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
16
src/Orchard.Web/Core/Settings/Models/SiteModel.cs
Normal file
16
src/Orchard.Web/Core/Settings/Models/SiteModel.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Orchard.Core.Settings.Records;
|
||||
using Orchard.Models;
|
||||
using Orchard.Settings;
|
||||
|
||||
namespace Orchard.Core.Settings.Models {
|
||||
public sealed class SiteModel : ModelPartWithRecord<SiteSettingsRecord>, ISite {
|
||||
public string SiteName {
|
||||
get { return Record.SiteName; }
|
||||
set { Record.SiteName = value; }
|
||||
}
|
||||
public string SuperUser {
|
||||
get { return Record.SuperUser; }
|
||||
set { Record.SuperUser = value; }
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
using Orchard.Models.Records;
|
||||
|
||||
namespace Orchard.Core.Settings.Records {
|
||||
public class SiteSettingsRecord : ModelPartRecord {
|
||||
public virtual string SiteUrl { get; set; }
|
||||
public virtual string SiteName { get; set; }
|
||||
public virtual string SuperUser { get; set; }
|
||||
}
|
||||
}
|
38
src/Orchard.Web/Core/Settings/Services/SiteService.cs
Normal file
38
src/Orchard.Web/Core/Settings/Services/SiteService.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Orchard.Core.Settings.Models;
|
||||
using Orchard.Core.Settings.Records;
|
||||
using Orchard.Data;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Models;
|
||||
using Orchard.Settings;
|
||||
using System.Web;
|
||||
|
||||
namespace Orchard.Core.Settings.Services {
|
||||
public class SiteService : ISiteService {
|
||||
private readonly IRepository<SiteSettingsRecord> _siteSettingsRepository;
|
||||
private readonly IModelManager _modelManager;
|
||||
|
||||
public SiteService(IRepository<SiteSettingsRecord> siteSettingsRepository, IModelManager modelManager) {
|
||||
_siteSettingsRepository = siteSettingsRepository;
|
||||
_modelManager = modelManager;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
#region Implementation of ISiteService
|
||||
|
||||
public ISite GetSiteSettings() {
|
||||
string applicationName = HttpContext.Current.Request.ApplicationPath;
|
||||
SiteSettingsRecord record = _siteSettingsRepository.Get(x => x.SiteUrl == applicationName);
|
||||
if (record == null) {
|
||||
SiteModel site = _modelManager.New("site").As<SiteModel>();
|
||||
site.Record.SiteUrl = applicationName;
|
||||
_modelManager.Create(site);
|
||||
return site;
|
||||
}
|
||||
return _modelManager.Get(record.Id).As<ISite>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.Core.Settings.Models;
|
||||
|
||||
namespace Orchard.Core.Settings.ViewModels {
|
||||
public class SettingsIndexViewModel : AdminViewModel {
|
||||
public SiteModel SiteSettings { get; set; }
|
||||
}
|
||||
}
|
35
src/Orchard.Web/Core/Settings/Views/Admin/Index.aspx
Normal file
35
src/Orchard.Web/Core/Settings/Views/Admin/Index.aspx
Normal file
@@ -0,0 +1,35 @@
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Orchard.Core.Settings.ViewModels.SettingsIndexViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head id="Head1" runat="server">
|
||||
<title>Edit Site Settings</title>
|
||||
<% Html.Include("Head"); %>
|
||||
</head>
|
||||
<body>
|
||||
<% Html.Include("Header"); %>
|
||||
<div class="yui-u">
|
||||
<h2 class="separator">
|
||||
Edit Site Settings</h2>
|
||||
</div>
|
||||
<div class="yui-u">
|
||||
<%using (Html.BeginForm()) { %>
|
||||
<ol>
|
||||
<%= Html.ValidationSummary() %>
|
||||
|
||||
<li class="clearLayout">
|
||||
<label for="SiteName">Site Name:</label>
|
||||
<input id="SiteName" class="inputText inputTextLarge roundCorners" name="SiteName" type="text" value="<%= Model.SiteSettings.SiteName %>" />
|
||||
<label for="SuperUser">Super User Name:</label>
|
||||
<input id="SuperUser" class="inputText inputTextLarge roundCorners" name="SuperUser" type="text" value="<%= Model.SiteSettings.SuperUser %>" />
|
||||
<%-- <input id="MediaPath" name="MediaPath" type="hidden" value="<%=Model.MediaPath %>" />--%>
|
||||
<input class="button" type="submit" value="Save" />
|
||||
<%=Html.ActionLink("Cancel", "Index", new{}, new{@class="button"}) %>
|
||||
</li>
|
||||
</ol>
|
||||
<%}/*EndForm*/%>
|
||||
</div>
|
||||
<% Html.Include("Footer"); %>
|
||||
</body>
|
||||
</html>
|
34
src/Orchard.Web/Core/Settings/Views/Web.config
Normal file
34
src/Orchard.Web/Core/Settings/Views/Web.config
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<system.web>
|
||||
<httpHandlers>
|
||||
<add path="*" verb="*"
|
||||
type="System.Web.HttpNotFoundHandler"/>
|
||||
</httpHandlers>
|
||||
|
||||
<!--
|
||||
Enabling request validation in view pages would cause validation to occur
|
||||
after the input has already been processed by the controller. By default
|
||||
MVC performs request validation before a controller processes the input.
|
||||
To change this behavior apply the ValidateInputAttribute to a
|
||||
controller or action.
|
||||
-->
|
||||
<pages
|
||||
validateRequest="false"
|
||||
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
|
||||
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
|
||||
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
|
||||
<controls>
|
||||
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
|
||||
</controls>
|
||||
</pages>
|
||||
</system.web>
|
||||
|
||||
<system.webServer>
|
||||
<validation validateIntegratedModeConfiguration="false"/>
|
||||
<handlers>
|
||||
<remove name="BlockViewHandler"/>
|
||||
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
|
||||
</handlers>
|
||||
</system.webServer>
|
||||
</configuration>
|
34
src/Orchard.Web/Core/XmlRpc/Views/Web.config
Normal file
34
src/Orchard.Web/Core/XmlRpc/Views/Web.config
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<system.web>
|
||||
<httpHandlers>
|
||||
<add path="*" verb="*"
|
||||
type="System.Web.HttpNotFoundHandler"/>
|
||||
</httpHandlers>
|
||||
|
||||
<!--
|
||||
Enabling request validation in view pages would cause validation to occur
|
||||
after the input has already been processed by the controller. By default
|
||||
MVC performs request validation before a controller processes the input.
|
||||
To change this behavior apply the ValidateInputAttribute to a
|
||||
controller or action.
|
||||
-->
|
||||
<pages
|
||||
validateRequest="false"
|
||||
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
|
||||
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
|
||||
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
|
||||
<controls>
|
||||
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
|
||||
</controls>
|
||||
</pages>
|
||||
</system.web>
|
||||
|
||||
<system.webServer>
|
||||
<validation validateIntegratedModeConfiguration="false"/>
|
||||
<handlers>
|
||||
<remove name="BlockViewHandler"/>
|
||||
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
|
||||
</handlers>
|
||||
</system.webServer>
|
||||
</configuration>
|
@@ -5,6 +5,7 @@ using Orchard.Roles.Models.NoRecord;
|
||||
using Orchard.Roles.Records;
|
||||
using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
using Orchard.Settings;
|
||||
|
||||
namespace Orchard.Roles.Services {
|
||||
public class RolesBasedAuthorizationService : IAuthorizationService {
|
||||
@@ -16,6 +17,7 @@ namespace Orchard.Roles.Services {
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
public ISite CurrentSite { get; set; }
|
||||
|
||||
#region Implementation of IAuthorizationService
|
||||
|
||||
@@ -24,7 +26,9 @@ namespace Orchard.Roles.Services {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (String.Equals(user.UserName, "Administrator", StringComparison.OrdinalIgnoreCase)) {
|
||||
if (String.Equals(user.UserName, "Administrator", StringComparison.OrdinalIgnoreCase) ||
|
||||
((!String.IsNullOrEmpty(CurrentSite.SuperUser) &&
|
||||
String.Equals(user.UserName, CurrentSite.SuperUser, StringComparison.OrdinalIgnoreCase)))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user