MetaData Review Changes

--HG--
branch : dev
This commit is contained in:
khavas
2010-05-19 15:12:05 -07:00
parent 106eff8d3e
commit 04a2e0c3c3
18 changed files with 78 additions and 139 deletions

View File

@@ -25,6 +25,7 @@ namespace Orchard.Tests.ContentManagement{
typeof(ContentTypeRecord),
typeof(ContentItemRecord),
typeof(ContentTypePartRecord),
typeof(ContentTypePartNameRecord),
typeof(ContentItemVersionRecord));
}

View File

@@ -1,25 +0,0 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TeamSystem.Data.UnitTesting;
namespace Orchard.Tests.ContentManagement
{
[TestClass()]
public class DatabaseSetup
{
[AssemblyInitialize()]
public static void IntializeAssembly(TestContext ctx)
{
// Setup the test database based on setting in the
// configuration file
DatabaseTestClass.TestService.DeployDatabaseProject();
DatabaseTestClass.TestService.GenerateData();
}
}
}

View File

@@ -64,8 +64,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\machine.migrations\Machine.Migrations.NHibernate.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="Microsoft.VisualStudio.TeamSystem.Data.UnitTesting, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="Moq, Version=4.0.812.4, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\moq\Moq.dll</HintPath>
@@ -136,7 +134,6 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="ContentManagement\ContentTypeMetaDataTests.cs" />
<Compile Include="ContentManagement\DatabaseSetup.cs" />
<Compile Include="ContentManagement\DefaultContentManagerTests.cs">
<SubType>Code</SubType>
</Compile>

View File

@@ -1,14 +1,8 @@
using System.Linq;

using Orchard.UI.Navigation;
namespace Orchard.MetaData {
public class AdminMenu : INavigationProvider {
//private readonly IBlogService _blogService;
public AdminMenu() {
//_blogService = blogService;
}
public string MenuName { get { return "admin"; } }

View File

@@ -1,41 +1,46 @@
using System.Web.Mvc;
using Orchard.ContentManagement.MetaData.Services;
using Orchard.Themes;
using Orchard.Data;
using Orchard.ContentManagement.Records;
using Orchard.ContentManagement.MetaData.Records;
using Orchard.Localization;
using Orchard.MetaData.ViewModels;
using Orchard.UI.Admin;
namespace Orchard.MetaData.Controllers
{
[Themed]
[Admin]
public class MetaDataController : Controller
{
private readonly IRepository<ContentTypeRecord> _ctps;
private readonly IContentTypeService _contentTypeService;
public IOrchardServices Services { get; set; }
public MetaDataController(IRepository<ContentTypeRecord> ctps, IContentTypeService contentTypeService){
_ctps = ctps;
public MetaDataController(IOrchardServices services, IContentTypeService contentTypeService)
{
_contentTypeService = contentTypeService;
Services = services;
T = NullLocalizer.Instance;
}
private Localizer T { get; set; }
//
// GET: /ContentTypeList/
public ActionResult ContentTypeList(string id) {
if (!Services.Authorizer.Authorize(Permissions.ManageMetaData, T("Not allowed to manage MetaData")))
return new HttpUnauthorizedResult();
var contentTypes = _contentTypeService.GetContentTypes();
var contentTypePartNames = _contentTypeService.GetContentTypePartNames();
var model = new ContentTypesIndexViewModel();
foreach(ContentTypeRecord contentType in contentTypes) {
var contentTypeEntry = new ContentTypeEntry() {Name = contentType.Name,DisplayName = contentType.Name};
foreach(var contentType in contentTypes) {
var contentTypeEntry = new ContentTypeEntry {Name = contentType.Name,DisplayName = contentType.Name};
if (contentType.Name==id) {
foreach(ContentTypePartNameRecord contentTypePartNameRecord in contentTypePartNames) {
var contentTypePartEntry = new ContentTypePartEntry() { Name = contentTypePartNameRecord.PartName };
foreach(var contentTypePartNameRecord in contentTypePartNames) {
var contentTypePartEntry = new ContentTypePartEntry { Name = contentTypePartNameRecord.PartName };
foreach(var contentTypePartEntryTest in contentType.ContentParts) {
if (contentTypePartEntryTest.PartName==contentTypePartEntry.Name) {
if (contentTypePartEntryTest.PartName.PartName==contentTypePartEntry.Name) {
contentTypePartEntry.Selected = true;
}
}
@@ -44,8 +49,7 @@ namespace Orchard.MetaData.Controllers
model.SelectedContentType = contentTypeEntry;
}
model.ContentTypes.Add(contentTypeEntry);
};
}
return View(model);
}
@@ -55,13 +59,14 @@ namespace Orchard.MetaData.Controllers
[HttpPost]
public ActionResult Save(string id, FormCollection collection)
{
ContentTypeRecord contentTypeRecord = _contentTypeService.GetContentTypeRecord(id);
if (!Services.Authorizer.Authorize(Permissions.ManageMetaData, T("Not allowed to manage MetaData")))
return new HttpUnauthorizedResult();
var contentTypeRecord = _contentTypeService.GetContentTypeRecord(id);
//using a while loop because we are removing items from the collection
while (contentTypeRecord.ContentParts.Count>0) {
_contentTypeService.UnMapContentTypeToContentPart(contentTypeRecord.Name, contentTypeRecord.ContentParts[0].PartName);
_contentTypeService.UnMapContentTypeToContentPart(contentTypeRecord.Name, contentTypeRecord.ContentParts[0].PartName.PartName);
}
//foreach(var contentTypePartNameRecord in contentTypeRecord.ContentParts) {
// _contentTypeService.UnMapContentTypeToContentPart(contentTypeRecord.Name,contentTypePartNameRecord.PartName);
//}
foreach(var formKey in collection.AllKeys) {
if (formKey.Contains("part_")) {
var partName = formKey.Replace("part_", "");
@@ -69,7 +74,7 @@ namespace Orchard.MetaData.Controllers
}
}
return RedirectToAction("ContentTypeList", new { id = id });
return RedirectToAction("ContentTypeList", new { id });
}

View File

@@ -1,20 +1,10 @@
using System.Collections.Generic;
using System.Linq;
using Orchard.Security.Permissions;
namespace Orchard.MetaData {
public class Permissions : IPermissionProvider {
public static readonly Permission ManageMetaData = new Permission { Description = "Manage MetaData", Name = "ManageMetaData" };//q: Should edit_MetaData be ManageMetaData?
public static readonly Permission PublishOthersMetaDataPost = new Permission { Description = "Publish or unpublish MetaData post for others", Name = "PublishOthersMetaDataPost", ImpliedBy = new[] { ManageMetaData } };
public static readonly Permission PublishMetaDataPost = new Permission { Description = "Publish or unpublish MetaData post", Name = "PublishMetaDataPost", ImpliedBy = new[] { PublishOthersMetaDataPost } };
public static readonly Permission EditOthersMetaDataPost = new Permission { Description = "Edit any MetaData posts", Name = "EditOthersMetaDataPost", ImpliedBy = new[] { PublishOthersMetaDataPost } };
public static readonly Permission EditMetaDataPost = new Permission { Description = "Edit own MetaData posts", Name = "EditMetaDataPost", ImpliedBy = new[] { EditOthersMetaDataPost, PublishMetaDataPost } };
public static readonly Permission DeleteOthersMetaDataPost = new Permission { Description = "Delete MetaData post for others", Name = "DeleteOthersMetaDataPost", ImpliedBy = new[] { ManageMetaData } };
public static readonly Permission DeleteMetaDataPost = new Permission { Description = "Delete MetaData post", Name = "DeleteMetaDataPost", ImpliedBy = new[] { DeleteOthersMetaDataPost } };
public static readonly Permission MetaListOthersMetaData = new Permission { ImpliedBy = new[] { EditOthersMetaDataPost, PublishOthersMetaDataPost, DeleteOthersMetaDataPost } };
public static readonly Permission MetaListMetaData = new Permission { ImpliedBy = new[] { EditMetaDataPost, PublishMetaDataPost, DeleteMetaDataPost } };
public string ModuleName {
get {
@@ -25,12 +15,6 @@ namespace Orchard.MetaData {
public IEnumerable<Permission> GetPermissions() {
return new Permission[] {
ManageMetaData,
EditMetaDataPost,
EditOthersMetaDataPost,
PublishMetaDataPost,
PublishOthersMetaDataPost,
DeleteMetaDataPost,
DeleteOthersMetaDataPost,
};
}
@@ -40,22 +24,6 @@ namespace Orchard.MetaData {
Name = "Administrator",
Permissions = new[] {ManageMetaData}
},
new PermissionStereotype {
Name = "Editor",
Permissions = new[] {PublishOthersMetaDataPost,EditOthersMetaDataPost,DeleteOthersMetaDataPost}
},
new PermissionStereotype {
Name = "Moderator",
//Permissions = new[] {}
},
new PermissionStereotype {
Name = "Author",
Permissions = new[] {PublishMetaDataPost,EditMetaDataPost,DeleteMetaDataPost}
},
new PermissionStereotype {
Name = "Contributor",
Permissions = new[] {EditMetaDataPost}
},
};
}

View File

@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following

View File

@@ -15,13 +15,13 @@
<% foreach (var item in Model.ContentTypes) { %>
<%
string contentTypeClass = "";
var contentTypeClass = "";
if (Model.SelectedContentType!=null && Model.SelectedContentType.Name == item.Name)
{
contentTypeClass = "SelectedContentPart";
}else{
contentTypeClass = "UnSelectedContentPart";
}
contentTypeClass = "SelectedContentPart";
}else{
contentTypeClass = "UnSelectedContentPart";
}
%>
<tr class="<%=contentTypeClass %>">
<td>

View File

@@ -3,9 +3,6 @@ using System.Linq;
using System.Web;
using Orchard.Comments.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.MetaData.Records;
using Orchard.ContentManagement.Records;
using Orchard.Core.Common.Models;
using Orchard.Core.Navigation.Models;
using Orchard.Core.Settings.Models;

View File

@@ -56,7 +56,7 @@ namespace Orchard.ContentManagement.Drivers {
{
var contentPartInfo = new List<ContentPartInfo>() {
new ContentPartInfo()
{partName = typeof(TContent).Name,Factory = () => new TContent()}
{PartName = typeof(TContent).Name,Factory = () => new TContent()}
};
return contentPartInfo;

View File

@@ -25,10 +25,12 @@ namespace Orchard.ContentManagement.MetaData
protected override void Activating(ActivatingContentContext context) {
var contentTypeRecord = _contentTypeService.GetContentTypeRecord(context.ContentType) ?? new ContentTypeRecord();
if (contentTypeRecord.ContentParts != null){
foreach (var contentTypePartRecord in contentTypeRecord.ContentParts){
var record = contentTypePartRecord;
var contentPart = _contentPartInfos.Single(x => x.partName == record.PartName).Factory();
//var record = contentTypePartRecord;
var contentPart = _contentPartInfos.Single(x => x.PartName == contentTypePartRecord.PartName.PartName).Factory();
context.Builder.Weld(contentPart);
}
}

View File

@@ -4,7 +4,7 @@ namespace Orchard.ContentManagement.MetaData
{
public class ContentPartInfo
{
public string partName;
public Func<ContentPart> Factory;
public string PartName { get; set; }
public Func<ContentPart> Factory { get; set; }
}
}

View File

@@ -1,11 +0,0 @@
using System.Web.Mvc;
using Orchard.ContentManagement;
using Orchard.ContentManagement.MetaData.Records;
namespace Orchard.ContentManagement.MetaData.Models
{
public class ContentTypePart : ContentPart<ContentTypePartRecord>
{
}
}

View File

@@ -1,6 +1,6 @@
namespace Orchard.ContentManagement.MetaData.Records {
public class ContentTypePartRecord {
public virtual int Id { get; set; }
public virtual string PartName { get; set; }
public virtual ContentTypePartNameRecord PartName { get; set; }
}
}

View File

@@ -11,22 +11,34 @@ namespace Orchard.ContentManagement.MetaData.Services
[UsedImplicitly]
public class ContentTypeService : IContentTypeService
{
private readonly IRepository<ContentTypeRecord> _contentTypeRecord;
private readonly IRepository<ContentTypePartNameRecord> _contentTypePartNameRecord;
private readonly IRepository<ContentTypePartRecord> _contentTypePartRecord;
private readonly IRepository<ContentTypeRecord> _contentTypeRepository;
private readonly IRepository<ContentTypePartNameRecord> _contentTypePartNameRepository;
private readonly IRepository<ContentTypePartRecord> _contentTypePartRepository;
public ContentTypeService(IRepository<ContentTypePartRecord> contentTypePartRecord, IRepository<ContentTypeRecord> contentTypeRecord, IRepository<ContentTypePartNameRecord> contentTypePartNameRecord)
public ContentTypeService(IRepository<ContentTypePartRecord> contentTypePartRepository, IRepository<ContentTypeRecord> contentTypeRepository, IRepository<ContentTypePartNameRecord> contentTypePartNameRepository)
{
_contentTypeRecord = contentTypeRecord;
_contentTypePartNameRecord = contentTypePartNameRecord;
_contentTypePartRecord = contentTypePartRecord;
_contentTypeRepository = contentTypeRepository;
_contentTypePartNameRepository = contentTypePartNameRepository;
_contentTypePartRepository = contentTypePartRepository;
}
public ContentTypePartNameRecord GetContentPartNameRecord(string name) {
return _contentTypePartNameRepository.Fetch(x => x.PartName == name).Single();
}
public void MapContentTypeToContentPart(string contentType, string contentPart) {
var contentTypeRecord = GetContentTypeRecord(contentType) ?? new ContentTypeRecord();
contentTypeRecord.Name = contentType;
var contentTypePartNameRecord =
_contentTypePartNameRepository.Fetch(x => x.PartName == contentPart).SingleOrDefault();
if (contentTypePartNameRecord==null) {
contentTypePartNameRecord=new ContentTypePartNameRecord(){PartName = contentPart};
_contentTypePartNameRepository.Update(contentTypePartNameRecord);
contentTypePartNameRecord =
_contentTypePartNameRepository.Fetch(x => x.PartName == contentPart).SingleOrDefault();
}
var contentTypePartRecord = new ContentTypePartRecord() {
PartName = contentPart
PartName = contentTypePartNameRecord
};
if (contentTypeRecord.ContentParts==null) {
contentTypeRecord.ContentParts = new List<ContentTypePartRecord> { contentTypePartRecord };
@@ -35,15 +47,17 @@ namespace Orchard.ContentManagement.MetaData.Services
contentTypeRecord.ContentParts.Add(contentTypePartRecord);
}
_contentTypeRecord.Update(contentTypeRecord);
_contentTypeRepository.Update(contentTypeRecord);
}
public void UnMapContentTypeToContentPart(string contentType, string contentPart) {
var contentTypeRecord = GetContentTypeRecord(contentType) ?? new ContentTypeRecord();
var contentTypePartRecord = contentTypeRecord.ContentParts.Single(x => x.PartName == contentPart);
var contentTypePartNameRecord = _contentTypePartNameRepository.Fetch(x => x.PartName == contentPart).Single();
var contentTypePartRecord = contentTypeRecord.ContentParts.SingleOrDefault(x => x.PartName == contentTypePartNameRecord);
if (contentTypePartRecord != null)
{
_contentTypePartRecord.Delete(contentTypePartRecord);
_contentTypePartRepository.Delete(contentTypePartRecord);
contentTypeRecord.ContentParts.Remove(contentTypePartRecord);
}
}
@@ -52,7 +66,7 @@ namespace Orchard.ContentManagement.MetaData.Services
var contentTypeRecord = GetContentTypeRecord(contentType) ?? new ContentTypeRecord();
if (contentTypeRecord.ContentParts.Count==0)
return false;
var contentTypePart = contentTypeRecord.ContentParts.Single(x => x.PartName == contentPart);
var contentTypePart = contentTypeRecord.ContentParts.Single(x => x.PartName.PartName == contentPart);
return contentTypePart != null;
}
@@ -62,27 +76,19 @@ namespace Orchard.ContentManagement.MetaData.Services
PartName = contentTypePartName
};
_contentTypePartNameRecord.Update(contentTypePartNameRecord);
_contentTypePartNameRepository.Update(contentTypePartNameRecord);
}
public ContentTypeRecord GetContentTypeRecord(string contentTypeName) {
var contentTypeCount = _contentTypeRecord.Table.Count(x => x.Name == contentTypeName);
if (contentTypeCount > 0) {
var contentTypeRecord = _contentTypeRecord.Table.Single(x => x.Name == contentTypeName);
return contentTypeRecord;
}
else {
return null;
}
return _contentTypeRepository.Fetch(x => x.Name == contentTypeName).SingleOrDefault();
}
public IEnumerable<ContentTypeRecord> GetContentTypes() {
return _contentTypeRecord.Table.ToList();
return _contentTypeRepository.Table.ToList();
}
public IEnumerable<ContentTypePartNameRecord> GetContentTypePartNames() {
return _contentTypePartNameRecord.Table.ToList();
return _contentTypePartNameRepository.Table.ToList();
}
}

View File

@@ -12,5 +12,6 @@ namespace Orchard.ContentManagement.MetaData.Services
bool ValidateContentTypeToContentPartMapping(string contentType, string contentPart);
IEnumerable<ContentTypeRecord> GetContentTypes();
IEnumerable<ContentTypePartNameRecord> GetContentTypePartNames();
ContentTypePartNameRecord GetContentPartNameRecord(string name);
}
}

View File

@@ -1,6 +1,9 @@
using Orchard.Data.Conventions;
namespace Orchard.ContentManagement.Records {
public abstract class ContentPartRecord {
public virtual int Id { get; set; }
[CascadeAllDeleteOrphan]
public virtual ContentItemRecord ContentItemRecord { get; set; }
}
}

View File

@@ -185,7 +185,6 @@
<Compile Include="ContentManagement\Handlers\VersionContentContext.cs" />
<Compile Include="ContentManagement\MetaData\ContentPartHandler.cs" />
<Compile Include="ContentManagement\MetaData\ContentPartInfo.cs" />
<Compile Include="ContentManagement\MetaData\Models\ContentTypePart.cs" />
<Compile Include="ContentManagement\MetaData\Services\ContentTypeService.cs" />
<Compile Include="ContentManagement\MetaData\Services\IContentTypeService.cs" />
<Compile Include="ContentManagement\MetaData\Records\ContentTypePartRecord.cs" />
@@ -465,6 +464,9 @@
<None Include="app.config" />
<None Include="ContentManagement\Diagram.cd" />
</ItemGroup>
<ItemGroup>
<Folder Include="ContentManagement\MetaData\Models\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.