mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-26 03:40:56 +08:00
Updated UT and displaying last updated by correctly
This commit is contained in:
@@ -138,6 +138,7 @@ namespace Orchard.Core.Tests.Common.Providers {
|
||||
Filters.Add(new ActivatingFilter<CommonPart>("test-item"));
|
||||
Filters.Add(new ActivatingFilter<ContentPart<CommonPartVersionRecord>>("test-item"));
|
||||
Filters.Add(new ActivatingFilter<TestUser>("User"));
|
||||
Filters.Add(new ActivatingFilter<AlternateTestUser>("AlternateUser"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +147,11 @@ namespace Orchard.Core.Tests.Common.Providers {
|
||||
public string UserName { get { return "x"; } }
|
||||
public string Email { get { return "y"; } }
|
||||
}
|
||||
class AlternateTestUser : ContentPart, IUser {
|
||||
public new int Id { get { return 6655322; } }
|
||||
public string UserName { get { return "y"; } }
|
||||
public string Email { get { return "x"; } }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OwnerShouldBeNullAndZeroByDefault() {
|
||||
@@ -359,14 +365,22 @@ namespace Orchard.Core.Tests.Common.Providers {
|
||||
public void EditingShouldSetModifiedUtc() {
|
||||
var contentManager = _container.Resolve<IContentManager>();
|
||||
|
||||
var user = contentManager.New<IUser>("User");
|
||||
_authn.Setup(x => x.GetAuthenticatedUser()).Returns(user);
|
||||
|
||||
var createUtc = _clock.UtcNow;
|
||||
var item = contentManager.Create<ICommonPart>("test-item", VersionOptions.Draft, init => { });
|
||||
contentManager.Publish(item.ContentItem);
|
||||
|
||||
Assert.That(item.CreatedUtc, Is.EqualTo(createUtc));
|
||||
Assert.That(item.ModifiedUtc, Is.EqualTo(createUtc));
|
||||
Assert.That(item.VersionModifiedBy, Is.EqualTo(user.UserName));
|
||||
Assert.That(item.PublishedUtc, Is.EqualTo(createUtc));
|
||||
|
||||
// Switch user
|
||||
var secondUser = contentManager.New<IUser>("AlternateUser");
|
||||
_authn.Setup(x => x.GetAuthenticatedUser()).Returns(secondUser);
|
||||
|
||||
_clock.Advance(TimeSpan.FromMinutes(1));
|
||||
var editUtc = _clock.UtcNow;
|
||||
|
||||
@@ -377,6 +391,7 @@ namespace Orchard.Core.Tests.Common.Providers {
|
||||
Assert.That(item.ModifiedUtc, Is.EqualTo(editUtc));
|
||||
Assert.That(item.PublishedUtc, Is.EqualTo(createUtc));
|
||||
Assert.That(updater.ModelErrors.Count, Is.EqualTo(0));
|
||||
Assert.That(item.VersionModifiedBy, Is.EqualTo(secondUser.UserName));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -127,12 +127,12 @@
|
||||
<ProjectReference Include="..\Orchard.Web\Core\Orchard.Core.csproj">
|
||||
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
|
||||
<Name>Orchard.Core</Name>
|
||||
<Private>false</Private>
|
||||
<Private>True</Private>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard\Orchard.Framework.csproj">
|
||||
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
||||
<Name>Orchard.Framework</Name>
|
||||
<Private>false</Private>
|
||||
<Private>True</Private>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -176,7 +176,7 @@ namespace Orchard.Core.Common.Handlers {
|
||||
}
|
||||
private string GetUserName() {
|
||||
var user = _authenticationService.GetAuthenticatedUser();
|
||||
return (user == null) ? string.Empty : user.UserName;
|
||||
return user == null ? string.Empty : user.UserName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace Orchard.Core.Common {
|
||||
.Column<DateTime>("CreatedUtc")
|
||||
.Column<DateTime>("PublishedUtc")
|
||||
.Column<DateTime>("ModifiedUtc")
|
||||
.Column<string>("ModifiedBy")
|
||||
);
|
||||
|
||||
SchemaBuilder.CreateTable("IdentityPartRecord",
|
||||
@@ -58,7 +59,7 @@ namespace Orchard.Core.Common {
|
||||
.Attachable()
|
||||
.WithDescription("Automatically generates a unique identity for the content item, which is required in import/export scenarios where one content item references another."));
|
||||
|
||||
return 4;
|
||||
return 5;
|
||||
}
|
||||
|
||||
public int UpdateFrom1() {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
@*
|
||||
Model:
|
||||
ContentPart
|
||||
*@
|
||||
|
||||
@using Orchard.ContentManagement
|
||||
@using Orchard.Core.Common.Models;
|
||||
@{
|
||||
CommonPart commonPart = Model.ContentPart;
|
||||
string lastModifiedBy = commonPart.As<CommonPart>() == null ? null : commonPart.As<CommonPart>().VersionModifiedBy;
|
||||
}
|
||||
|
||||
@T("By {0}", lastModifiedBy ?? T("unknown").ToString())
|
||||
@@ -1,14 +0,0 @@
|
||||
@*
|
||||
Model:
|
||||
ContentPart
|
||||
*@
|
||||
|
||||
@using Orchard.ContentManagement;
|
||||
@using Orchard.Core.Common.Models;
|
||||
@using Orchard.Security;
|
||||
@{
|
||||
CommonPart commonPart = Model.ContentPart;
|
||||
// owner isn't really who last modified this, is it?
|
||||
IUser owner = commonPart.As<CommonPart>() == null ? null : commonPart.As<CommonPart>().Owner;
|
||||
}
|
||||
@T("By {0}", owner == null ? T("unknown").ToString() : Convert.ToString(Html.ItemDisplayText(owner)))
|
||||
@@ -8,5 +8,5 @@
|
||||
<li>@if (modifiedUtc.HasValue) {
|
||||
@T("Last modified: {0}", Display.DateTimeRelative(DateTimeUtc: modifiedUtc.Value))} |
|
||||
</li>
|
||||
<li>@Display.CommonMetadataOwner(ContentPart: Model.ContentPart)</li>
|
||||
<li>@Display.CommonMetadataLastModified(ContentPart: Model.ContentPart)</li>
|
||||
</ul>
|
||||
@@ -292,7 +292,7 @@
|
||||
<Content Include="Common\Views\Fields.Common.Text.cshtml" />
|
||||
<Content Include="Common\Views\Parts.Common.Body.SummaryAdmin.cshtml" />
|
||||
<Content Include="Common\Views\Parts.Common.Metadata.cshtml" />
|
||||
<Content Include="Common\Views\CommonMetadataOwner.cshtml" />
|
||||
<Content Include="Common\Views\CommonMetadataLastModified.cshtml" />
|
||||
<Content Include="Containers\Module.txt" />
|
||||
<Content Include="Contents\Styles\images\menu.content.png" />
|
||||
<Content Include="Contents\Styles\menu.content-admin.css" />
|
||||
|
||||
@@ -13,5 +13,6 @@ namespace Orchard.ContentManagement.Aspects {
|
||||
DateTime? VersionCreatedUtc { get; set; }
|
||||
DateTime? VersionPublishedUtc { get; set; }
|
||||
DateTime? VersionModifiedUtc { get; set; }
|
||||
string VersionModifiedBy { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user