Shifting settings. Settings are now saved into the infoset rather than a record. No migration, no record.

This commit is contained in:
Bertrand Le Roy 2013-10-08 21:50:02 -07:00
parent f7998bc95c
commit 5166c16c73
7 changed files with 26 additions and 61 deletions

View File

@ -6,10 +6,9 @@ using Orchard.SecureSocketsLayer.Models;
namespace Orchard.SecureSocketsLayer.Handlers {
public class SslSettingsPartHandler : ContentHandler {
public SslSettingsPartHandler(IRepository<SslSettingsPartRecord> repository) {
public SslSettingsPartHandler() {
T = NullLocalizer.Instance;
Filters.Add(new ActivatingFilter<SslSettingsPart>("Site"));
Filters.Add(StorageFilter.For(repository));
}
public Localizer T { get; set; }

View File

@ -1,20 +0,0 @@
using Orchard.Data.Migration;
namespace Orchard.SecureSocketsLayer {
public class Migrations : DataMigrationImpl {
public int Create() {
SchemaBuilder.CreateTable("SslSettingsPartRecord",
table => table
.ContentPartRecord()
.Column<bool>("CustomEnabled")
.Column<bool>("SecureEverything")
.Column<string>("Urls", c => c.Unlimited())
.Column<string>("SecureHostName")
.Column<string>("InsecureHostName")
);
return 1;
}
}
}

View File

@ -1,31 +1,39 @@
using System;
using Orchard.ContentManagement;
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
namespace Orchard.SecureSocketsLayer.Models {
public class SslSettingsPart : ContentPart<SslSettingsPartRecord> {
public class SslSettingsPart : ContentPart {
public string Urls
{
get { return Record.Urls; }
set { Record.Urls = value; }
get { return this.As<InfosetPart>().Get<SslSettingsPart>("Urls"); }
set { this.As<InfosetPart>().Set<SslSettingsPart>("Urls", value); }
}
public bool SecureEverything {
get { return Record.SecureEverything; }
set { Record.SecureEverything = value; }
get {
var attributeValue = this.As<InfosetPart>().Get<SslSettingsPart>("SecureEverything");
return !String.IsNullOrWhiteSpace(attributeValue) && Convert.ToBoolean(attributeValue);
}
set { this.As<InfosetPart>().Set<SslSettingsPart>("SecureEverything", value.ToString()); }
}
public bool CustomEnabled {
get { return Record.CustomEnabled; }
set { Record.CustomEnabled = value; }
get {
var attributeValue = this.As<InfosetPart>().Get<SslSettingsPart>("CustomEnabled");
return !String.IsNullOrWhiteSpace(attributeValue) && Convert.ToBoolean(attributeValue);
}
set { this.As<InfosetPart>().Set<SslSettingsPart>("CustomEnabled", value.ToString()); }
}
public string SecureHostName {
get { return Record.SecureHostName; }
set { Record.SecureHostName = value; }
get { return this.As<InfosetPart>().Get<SslSettingsPart>("SecureHostName"); }
set { this.As<InfosetPart>().Set<SslSettingsPart>("SecureHostName", value); }
}
public string InsecureHostName {
get { return Record.InsecureHostName; }
set { Record.InsecureHostName = value; }
get { return this.As<InfosetPart>().Get<SslSettingsPart>("InsecureHostName"); }
set { this.As<InfosetPart>().Set<SslSettingsPart>("InsecureHostName", value); }
}
}
}

View File

@ -1,11 +0,0 @@
using Orchard.ContentManagement.Records;
namespace Orchard.SecureSocketsLayer.Models {
public class SslSettingsPartRecord : ContentPartRecord {
public virtual string Urls { get; set; }
public virtual bool SecureEverything { get; set; }
public virtual bool CustomEnabled { get; set; }
public virtual string SecureHostName { get; set; }
public virtual string InsecureHostName { get; set; }
}
}

View File

@ -82,11 +82,9 @@
<Compile Include="Drivers\SslSettingsPartDriver.cs" />
<Compile Include="Filters\SecureSocketsLayersFilter.cs" />
<Compile Include="Handlers\SslSettingsPartHandler.cs" />
<Compile Include="Migrations.cs" />
<Compile Include="Models\SslSettingsPart.cs" />
<Compile Include="Models\SslSettingsPartRecord.cs" />
<Compile Include="Services\ISecureSocketsLayerService.cs" />
<Compile Include="Services\SecuredSocketsLayerService.cs" />
<Compile Include="Services\SecureSocketsLayerService.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\EditorTemplates\Parts\SecureSocketsLayer.Settings.cshtml" />

View File

@ -150,7 +150,7 @@ namespace Orchard.SecureSocketsLayer.Services {
return requestContext;
}
private static bool IsRequestProtected(string path, string appPath, SslSettingsPartRecord settings) {
private static bool IsRequestProtected(string path, string appPath, SslSettingsPart settings) {
var match = false;
var sr = new StringReader(settings.Urls ?? "");
string pattern;
@ -183,17 +183,8 @@ namespace Orchard.SecureSocketsLayer.Services {
: string.Equals(requestPath, pattern, StringComparison.OrdinalIgnoreCase);
}
private SslSettingsPartRecord GetSettings() {
return _cacheManager.Get("SslSettings", ctx => {
var settings = _workContextAccessor.GetContext().CurrentSite.As<SslSettingsPart>();
return new SslSettingsPartRecord {
CustomEnabled = settings.CustomEnabled,
Urls = settings.Urls,
SecureEverything = settings.SecureEverything,
InsecureHostName = settings.InsecureHostName,
SecureHostName = settings.SecureHostName
};
});
private SslSettingsPart GetSettings() {
return _cacheManager.Get("SslSettings", ctx => _workContextAccessor.GetContext().CurrentSite.As<SslSettingsPart>());
}
private string MakeInsecure(string path) {

View File

@ -67,10 +67,10 @@ namespace Orchard.ContentManagement.FieldStorage.InfosetStorage {
partElement.Add(fieldElement);
}
if (string.IsNullOrEmpty(valueName)) {
fieldElement.Value = value;
fieldElement.Value = value ?? "";
}
else {
fieldElement.SetAttributeValue(XmlConvert.EncodeLocalName(valueName), value);
fieldElement.SetAttributeValue(XmlConvert.EncodeLocalName(valueName), value ?? "");
}
}
}