Skip to content

Commit

Permalink
add CanNotEditAttribute, fix long token bug
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliang-wt committed Jun 7, 2022
1 parent 4dc6528 commit ca0f505
Show file tree
Hide file tree
Showing 22 changed files with 27 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public override void DoAdd()

public override void DoEdit(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.GroupCode"))
{
FC.Remove("Entity.GroupCode");
}

base.DoEdit(updateAllFields);
Wtm.RemoveGroupCache(LoginUserInfo.CurrentTenant).Wait();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public override void DoAdd()

public override void DoEdit(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.RoleCode"))
{
FC.Remove("Entity.RoleCode");
}
base.DoEdit(updateAllFields);
Wtm.RemoveRoleCache(Wtm.LoginUserInfo.CurrentTenant).Wait();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ public override async Task DoAddAsync()

public override async Task DoEditAsync(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.ITCode"))
{
FC.Remove("Entity.ITCode");
}
using (var trans = DC.BeginTransaction())
{
if (SelectedRolesCodes != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public override void DoAdd()

public override void DoEdit(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.GroupCode"))
{
FC.Remove("Entity.GroupCode");
}

base.DoEdit(updateAllFields);
Wtm.RemoveGroupCache(LoginUserInfo.CurrentTenant).Wait();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public override void DoAdd()

public override void DoEdit(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.RoleCode"))
{
FC.Remove("Entity.RoleCode");
}
base.DoEdit(updateAllFields);
Wtm.RemoveRoleCache(Wtm.LoginUserInfo.CurrentTenant).Wait();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ public override async Task DoAddAsync()

public override async Task DoEditAsync(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.ITCode"))
{
FC.Remove("Entity.ITCode");
}
using (var trans = DC.BeginTransaction())
{
if (SelectedRolesCodes != null)
Expand Down
2 changes: 1 addition & 1 deletion demo/WalkingTec.Mvvm.Demo/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"Address": "https://api.github.com"
},
"mainhost": {
//"Address": "https://localhost:5001"
// "Address": "https://localhost:5001"
}
},
"AppSettings": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public override void DoAdd()

public override void DoEdit(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.GroupCode"))
{
FC.Remove("Entity.GroupCode");
}

base.DoEdit(updateAllFields);
Wtm.RemoveGroupCache(LoginUserInfo.CurrentTenant).Wait();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public override void DoAdd()

public override void DoEdit(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.RoleCode"))
{
FC.Remove("Entity.RoleCode");
}
base.DoEdit(updateAllFields);
Wtm.RemoveRoleCache(Wtm.LoginUserInfo.CurrentTenant).Wait();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ public override async Task DoAddAsync()

public override async Task DoEditAsync(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.ITCode"))
{
FC.Remove("Entity.ITCode");
}
using (var trans = DC.BeginTransaction())
{
if (SelectedRolesCodes != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public override void DoAdd()

public override void DoEdit(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.GroupCode"))
{
FC.Remove("Entity.GroupCode");
}

base.DoEdit(updateAllFields);
Wtm.RemoveGroupCache(LoginUserInfo.CurrentTenant).Wait();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public override void DoAdd()

public override void DoEdit(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.RoleCode"))
{
FC.Remove("Entity.RoleCode");
}
base.DoEdit(updateAllFields);
Wtm.RemoveRoleCache(Wtm.LoginUserInfo.CurrentTenant).Wait();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ public override async Task DoAddAsync()

public override async Task DoEditAsync(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.ITCode"))
{
FC.Remove("Entity.ITCode");
}
using (var trans = DC.BeginTransaction())
{
if (SelectedRolesCodes != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public override void DoAdd()

public override void DoEdit(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.GroupCode"))
{
FC.Remove("Entity.GroupCode");
}

base.DoEdit(updateAllFields);
Wtm.RemoveGroupCache(LoginUserInfo.CurrentTenant).Wait();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public override void DoAdd()

public override void DoEdit(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.RoleCode"))
{
FC.Remove("Entity.RoleCode");
}
base.DoEdit(updateAllFields);
Wtm.RemoveRoleCache(Wtm.LoginUserInfo.CurrentTenant).Wait();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ public override async Task DoAddAsync()

public override async Task DoEditAsync(bool updateAllFields = false)
{
if (FC.ContainsKey("Entity.ITCode"))
{
FC.Remove("Entity.ITCode");
}
using (var trans = DC.BeginTransaction())
{
if (SelectedRolesCodes != null)
Expand Down
13 changes: 13 additions & 0 deletions src/WalkingTec.Mvvm.Core/Attributes/CanNotEditAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace WalkingTec.Mvvm.Core
{
/// <summary>
/// 标记模型上的字段不能被修改
/// </summary>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class CanNotEditAttribute : Attribute
{

}
}
11 changes: 9 additions & 2 deletions src/WalkingTec.Mvvm.Core/BaseCRUDVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,8 @@ private void DoEditPrepare(bool updateAllFields)
if (!itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco)) && (updateAllFields == true || setnames.Contains(itempro.Name.ToLower())))
{
var notmapped = itempro.GetCustomAttribute<NotMappedAttribute>();
if (itempro.Name != "ID" && notmapped == null && itempro.PropertyType.IsList() == false)
var cannotedit = itempro.GetCustomAttribute<CanNotEditAttribute>();
if (itempro.Name != "ID" && notmapped == null && itempro.PropertyType.IsList() == false && cannotedit == null)
{
DC.UpdateProperty(i, itempro.Name);
}
Expand Down Expand Up @@ -661,7 +662,13 @@ private void DoEditPrepare(bool updateAllFields)
string name = f.Replace($"{this.GetParentStr().ToLower()}entity.", "");
try
{
DC.UpdateProperty(Entity, pros.Where(x => x.Name.ToLower() == name).Select(x => x.Name).FirstOrDefault());
var itempro = pros.Where(x => x.Name.ToLower() == name).FirstOrDefault();
var notmapped = itempro.GetCustomAttribute<NotMappedAttribute>();
var cannotedit = itempro.GetCustomAttribute<CanNotEditAttribute>();
if (itempro.Name != "ID" && notmapped == null && itempro.PropertyType.IsList() == false && cannotedit == null)
{
DC.UpdateProperty(Entity, itempro.Name);
}
}
catch (Exception)
{
Expand Down
1 change: 1 addition & 0 deletions src/WalkingTec.Mvvm.Core/Models/FrameworkGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class FrameworkGroup : TreePoco<FrameworkGroup>,ITenant
[Required(ErrorMessage = "Validate.{0}required")]
[RegularExpression("^[0-9]*$", ErrorMessage = "Validate.{0}number")]
[StringLength(100, ErrorMessage = "Validate.{0}stringmax{1}")]
[CanNotEdit]
public string GroupCode { get; set; }

[Display(Name = "_Admin.GroupName")]
Expand Down
1 change: 1 addition & 0 deletions src/WalkingTec.Mvvm.Core/Models/FrameworkRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class FrameworkRole : BasePoco,ITenant
[Required(ErrorMessage = "Validate.{0}required")]
[RegularExpression("^[0-9]*$", ErrorMessage = "Validate.{0}number")]
[StringLength(100, ErrorMessage = "Validate.{0}stringmax{1}")]
[CanNotEdit]
public string RoleCode { get; set; }

[Display(Name = "_Admin.RoleName")]
Expand Down
1 change: 1 addition & 0 deletions src/WalkingTec.Mvvm.Core/Models/FrameworkUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public abstract class FrameworkUserBase : BasePoco,ITenant
[Display(Name = "_Admin.Account")]
[Required(ErrorMessage = "Validate.{0}required")]
[StringLength(50,ErrorMessage = "Validate.{0}stringmax{1}")]
[CanNotEdit]
public string ITCode { get; set; }

[Display(Name = "_Admin.Password")]
Expand Down
1 change: 1 addition & 0 deletions src/WalkingTec.Mvvm.Core/WTMContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ public LoginUserInfo DoLogin(string username, string password, string tenant)
{
user.LoadBasicInfoAsync(this).Wait();
}
user.RemoteToken = null;
var authService = HttpContext.RequestServices.GetService(typeof(ITokenService)) as ITokenService;
var token = authService.IssueTokenAsync(user).Result;
user.RemoteToken = token.AccessToken;
Expand Down

0 comments on commit ca0f505

Please sign in to comment.