mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Shifting ContentItemPermissionsPart
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentPermissions.Models;
|
||||
|
||||
namespace Orchard.ContentPermissions.Handlers {
|
||||
public class ContentPermissionsPartHandler : ContentHandler {
|
||||
|
||||
public ContentPermissionsPartHandler(IRepository<ContentPermissionsPartRecord> repository) {
|
||||
Filters.Add(StorageFilter.For(repository));
|
||||
}
|
||||
}
|
||||
}
|
@@ -5,24 +5,11 @@ using Orchard.ContentManagement.MetaData;
|
||||
namespace Orchard.ContentPermissions {
|
||||
public class Migrations : DataMigrationImpl {
|
||||
public int Create() {
|
||||
SchemaBuilder.CreateTable("ContentPermissionsPartRecord", table => table
|
||||
.ContentPartRecord()
|
||||
.Column<bool>("Enabled")
|
||||
.Column<string>("ViewContent", c => c.Unlimited())
|
||||
.Column<string>("ViewOwnContent", c => c.Unlimited())
|
||||
.Column<string>("PublishContent", c => c.Unlimited())
|
||||
.Column<string>("PublishOwnContent", c => c.Unlimited())
|
||||
.Column<string>("EditContent", c => c.Unlimited())
|
||||
.Column<string>("EditOwnContent", c => c.Unlimited())
|
||||
.Column<string>("DeleteContent", c => c.Unlimited())
|
||||
.Column<string>("DeleteOwnContent", c => c.Unlimited())
|
||||
);
|
||||
|
||||
ContentDefinitionManager.AlterPartDefinition("ContentPermissionsPart", p => p
|
||||
.Attachable()
|
||||
.WithDescription("Provides access control configuration on a per content item level."));
|
||||
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
public int UpdateFrom1() {
|
||||
|
@@ -1,53 +1,53 @@
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.ContentPermissions.Models {
|
||||
public class ContentPermissionsPart : ContentPart<ContentPermissionsPartRecord> {
|
||||
public class ContentPermissionsPart : ContentPart {
|
||||
/// <summary>
|
||||
/// Whether the access control should be applied for the content item
|
||||
/// </summary>
|
||||
public bool Enabled {
|
||||
get { return Record.Enabled; }
|
||||
set { Record.Enabled = value; }
|
||||
get { return this.Retrieve(x => x.Enabled); }
|
||||
set { this.Store(x => x.Enabled, value); }
|
||||
}
|
||||
|
||||
public string ViewContent {
|
||||
get { return Record.ViewContent; }
|
||||
set { Record.ViewContent = value; }
|
||||
get { return this.Retrieve(x => x.ViewContent); }
|
||||
set { this.Store(x => x.ViewContent, value); }
|
||||
}
|
||||
|
||||
public string ViewOwnContent {
|
||||
get { return Record.ViewOwnContent; }
|
||||
set { Record.ViewOwnContent = value; }
|
||||
get { return this.Retrieve(x => x.ViewOwnContent); }
|
||||
set { this.Store(x => x.ViewOwnContent, value); }
|
||||
}
|
||||
|
||||
public string PublishContent {
|
||||
get { return Record.PublishContent; }
|
||||
set { Record.PublishContent = value; }
|
||||
get { return this.Retrieve(x => x.PublishContent); }
|
||||
set { this.Store(x => x.PublishContent, value); }
|
||||
}
|
||||
|
||||
public string PublishOwnContent {
|
||||
get { return Record.PublishOwnContent; }
|
||||
set { Record.PublishOwnContent = value; }
|
||||
get { return this.Retrieve(x => x.PublishOwnContent); }
|
||||
set { this.Store(x => x.PublishOwnContent, value); }
|
||||
}
|
||||
|
||||
public string EditContent {
|
||||
get { return Record.EditContent; }
|
||||
set { Record.EditContent = value; }
|
||||
get { return this.Retrieve(x => x.EditContent); }
|
||||
set { this.Store(x => x.EditContent, value); }
|
||||
}
|
||||
|
||||
public string EditOwnContent {
|
||||
get { return Record.EditOwnContent; }
|
||||
set { Record.EditOwnContent = value; }
|
||||
get { return this.Retrieve(x => x.EditOwnContent); }
|
||||
set { this.Store(x => x.EditOwnContent, value); }
|
||||
}
|
||||
|
||||
public string DeleteContent {
|
||||
get { return Record.DeleteContent; }
|
||||
set { Record.DeleteContent = value; }
|
||||
get { return this.Retrieve(x => x.DeleteContent); }
|
||||
set { this.Store(x => x.DeleteContent, value); }
|
||||
}
|
||||
|
||||
public string DeleteOwnContent {
|
||||
get { return Record.DeleteOwnContent; }
|
||||
set { Record.DeleteOwnContent = value; }
|
||||
get { return this.Retrieve(x => x.DeleteOwnContent); }
|
||||
set { this.Store(x => x.DeleteOwnContent, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,30 +0,0 @@
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Data.Conventions;
|
||||
|
||||
namespace Orchard.ContentPermissions.Models {
|
||||
public class ContentPermissionsPartRecord : ContentPartRecord {
|
||||
|
||||
/// <summary>
|
||||
/// Whether the access control should be applied for the content item
|
||||
/// </summary>
|
||||
public virtual bool Enabled { get; set; }
|
||||
|
||||
[StringLengthMax]
|
||||
public virtual string ViewContent { get; set; }
|
||||
[StringLengthMax]
|
||||
public virtual string ViewOwnContent { get; set; }
|
||||
[StringLengthMax]
|
||||
public virtual string PublishContent { get; set; }
|
||||
[StringLengthMax]
|
||||
public virtual string PublishOwnContent { get; set; }
|
||||
[StringLengthMax]
|
||||
public virtual string EditContent { get; set; }
|
||||
[StringLengthMax]
|
||||
public virtual string EditOwnContent { get; set; }
|
||||
[StringLengthMax]
|
||||
public virtual string DeleteContent { get; set; }
|
||||
[StringLengthMax]
|
||||
public virtual string DeleteOwnContent { get; set; }
|
||||
|
||||
}
|
||||
}
|
@@ -94,9 +94,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Drivers\ContentPermissionsPartDriver.cs" />
|
||||
<Compile Include="Handlers\ContentPermissionsPartHandler.cs" />
|
||||
<Compile Include="Models\ContentPermissionsPart.cs" />
|
||||
<Compile Include="Models\ContentPermissionsPartRecord.cs" />
|
||||
<Compile Include="Permissions.cs" />
|
||||
<Compile Include="Security\AuthorizationEventHandler.cs" />
|
||||
<Compile Include="Migrations.cs" />
|
||||
@@ -120,6 +118,9 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Parts.ContentPermissions.SummaryAdmin.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Handlers\" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
|
@@ -127,5 +127,37 @@ namespace Upgrade.Controllers {
|
||||
|
||||
return new JsonResult { Data = contentItems.Last().Id };
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public JsonResult MigrateContentPermissionsPart(int id) {
|
||||
if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner))
|
||||
throw new AuthenticationException("");
|
||||
|
||||
var lastContentItemId = 0;
|
||||
// TypePadSettingsPartRecord
|
||||
_upgradeService.ExecuteReader("SELECT * FROM " + _upgradeService.GetPrefixedTableName("Orchard_ContentPermissions_ContentPermissionsPartRecord" + " WHERE Id > " + id),
|
||||
(reader, connection) => {
|
||||
lastContentItemId = (int) reader["Id"];
|
||||
var contentPermissionPart = _orchardServices.ContentManager.Get(lastContentItemId);
|
||||
|
||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "Enabled", reader["Enabled"].ToString());
|
||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "ViewContent", reader["ViewContent"].ToString());
|
||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "ViewOwnContent", reader["ViewOwnContent"].ToString());
|
||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "PublishContent", reader["PublishContent"].ToString());
|
||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "PublishOwnContent", reader["PublishOwnContent"].ToString());
|
||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "EditContent", reader["EditContent"].ToString());
|
||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "EditOwnContent", reader["EditOwnContent"].ToString());
|
||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "DeleteContent", reader["DeleteContent"].ToString());
|
||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "DeleteOwnContent", reader["DeleteOwnContent"].ToString());
|
||||
});
|
||||
|
||||
if (lastContentItemId == 0) {
|
||||
// delete the table only when there is no more content to process
|
||||
_upgradeService.ExecuteReader("DROP TABLE " + _upgradeService.GetPrefixedTableName("Orchard_ContentPermissions_ContentPermissionsPartRecord"), null);
|
||||
}
|
||||
|
||||
return new JsonResult { Data = lastContentItemId };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user