DESKTOP-G961P6V\Zhh 2 years ago
parent
commit
c04d54ba5d
  1. 17
      src/Shentun.Peis.Domain/Data/CustomerAuditPropertySetter.cs
  2. 4
      src/Shentun.Peis.Domain/DataHelper.cs
  3. 2
      test/Shentun.Peis.TestBase/Security/FakeCurrentPrincipalAccessor.cs

17
src/Shentun.Peis.Domain/Data/CustomerAuditPropertySetter.cs

@ -1,4 +1,5 @@
using System;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -24,16 +25,20 @@ namespace Shentun.Peis.Data
{ {
protected ICurrentUser CurrentUser { get; } protected ICurrentUser CurrentUser { get; }
protected ICurrentTenant CurrentTenant { get; } protected ICurrentTenant CurrentTenant { get; }
private readonly IConfiguration _configuration;
protected IClock Clock { get; } protected IClock Clock { get; }
public CustomerAuditPropertySetter( public CustomerAuditPropertySetter(
ICurrentUser currentUser, ICurrentUser currentUser,
ICurrentTenant currentTenant, ICurrentTenant currentTenant,
IClock clock)
IClock clock,
IConfiguration configuration)
{ {
CurrentUser = currentUser; CurrentUser = currentUser;
CurrentTenant = currentTenant; CurrentTenant = currentTenant;
Clock = clock; Clock = clock;
_configuration = configuration;
} }
public void SetCreationProperties(object targetObject) public void SetCreationProperties(object targetObject)
@ -71,10 +76,12 @@ namespace Shentun.Peis.Data
{ {
if (!CurrentUser.Id.HasValue) if (!CurrentUser.Id.HasValue)
{ {
var defaultCreatorId = _configuration.GetValue<string>("AdminId");
#region 无登录操作 #region 无登录操作
if (targetObject is IMayHaveCreator mayHaveCreatorObjectNoLogin) if (targetObject is IMayHaveCreator mayHaveCreatorObjectNoLogin)
{ {
ObjectHelper.TrySetProperty(mayHaveCreatorObjectNoLogin, x => x.CreatorId, () => Guid.Parse("3a0c4180-107c-0c89-b25b-0bd34666dcec"));
ObjectHelper.TrySetProperty(mayHaveCreatorObjectNoLogin, x => x.CreatorId, () => Guid.Parse(defaultCreatorId));
} }
#endregion #endregion
return; return;
@ -135,9 +142,9 @@ namespace Shentun.Peis.Data
{ {
//modificationAuditedObject.LastModifierId = null; //modificationAuditedObject.LastModifierId = null;
//return; //return;
var defaultCreatorId = _configuration.GetValue<string>("AdminId");
#region 无登录操作 #region 无登录操作
modificationAuditedObject.LastModifierId = Guid.Parse("3a0c4180-107c-0c89-b25b-0bd34666dcec");
modificationAuditedObject.LastModifierId = Guid.Parse(defaultCreatorId);
return; return;
#endregion #endregion
} }

4
src/Shentun.Peis.Domain/DataHelper.cs

@ -449,7 +449,7 @@ namespace Shentun.Peis
/// <exception cref="ArgumentException"></exception> /// <exception cref="ArgumentException"></exception>
public static void CheckIntIsGeaterThanZero(int value, string parameterName, string ExceptionMessage = "只能为大于0的值") public static void CheckIntIsGeaterThanZero(int value, string parameterName, string ExceptionMessage = "只能为大于0的值")
{ {
if (value > 0)
if (value <= 0)
{ {
throw new UserFriendlyException($"{parameterName}{ExceptionMessage}"); throw new UserFriendlyException($"{parameterName}{ExceptionMessage}");
} }
@ -496,7 +496,7 @@ namespace Shentun.Peis
/// <exception cref="ArgumentException"></exception> /// <exception cref="ArgumentException"></exception>
public static void CheckDecimalIsGeaterThanZero(decimal value, string parameterName, string ExceptionMessage = "值只能大于0") public static void CheckDecimalIsGeaterThanZero(decimal value, string parameterName, string ExceptionMessage = "值只能大于0")
{ {
if (value > 0)
if (value <= 0)
{ {
throw new UserFriendlyException($"{parameterName}{ExceptionMessage}"); throw new UserFriendlyException($"{parameterName}{ExceptionMessage}");
} }

2
test/Shentun.Peis.TestBase/Security/FakeCurrentPrincipalAccessor.cs

@ -27,7 +27,7 @@ public class FakeCurrentPrincipalAccessor : ThreadCurrentPrincipalAccessor
new ClaimsIdentity( new ClaimsIdentity(
new List<Claim> new List<Claim>
{ {
new Claim(AbpClaimTypes.UserId,"2e701e62-0953-4dd3-910b-dc6cc93ccb0d"),
new Claim(AbpClaimTypes.UserId,"3a0c4180-107c-0c89-b25b-0bd34666dcec"),
new Claim(AbpClaimTypes.UserName,"admin"), new Claim(AbpClaimTypes.UserName,"admin"),
new Claim(AbpClaimTypes.Email,"admin@abp.io") new Claim(AbpClaimTypes.Email,"admin@abp.io")
} }

Loading…
Cancel
Save