diff options
author | crupest <crupest@outlook.com> | 2020-11-12 21:38:43 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-11-12 21:38:43 +0800 |
commit | e4c4a284571d51dcda373a0a1c047e634b17882d (patch) | |
tree | 2343fba4753576fd33a79e2f2d4fe1484e11f557 /BackEnd/Timeline/Models | |
parent | b81a66ff49f5d9305108e92a009449ee5994862e (diff) | |
download | timeline-e4c4a284571d51dcda373a0a1c047e634b17882d.tar.gz timeline-e4c4a284571d51dcda373a0a1c047e634b17882d.tar.bz2 timeline-e4c4a284571d51dcda373a0a1c047e634b17882d.zip |
...
Diffstat (limited to 'BackEnd/Timeline/Models')
-rw-r--r-- | BackEnd/Timeline/Models/Http/UserInfo.cs | 21 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/User.cs | 28 |
2 files changed, 35 insertions, 14 deletions
diff --git a/BackEnd/Timeline/Models/Http/UserInfo.cs b/BackEnd/Timeline/Models/Http/UserInfo.cs index d92a12c4..26b04e90 100644 --- a/BackEnd/Timeline/Models/Http/UserInfo.cs +++ b/BackEnd/Timeline/Models/Http/UserInfo.cs @@ -2,7 +2,9 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.Routing;
+using System.Collections.Generic;
using Timeline.Controllers;
+using Timeline.Services;
namespace Timeline.Models.Http
{
@@ -27,6 +29,12 @@ namespace Timeline.Models.Http /// True if the user is a administrator.
/// </summary>
public bool? Administrator { get; set; } = default!;
+#pragma warning disable CA2227 // Collection properties should be read only
+ /// <summary>
+ /// The permissions of the user.
+ /// </summary>
+ public List<string> Permissions { get; set; } = default!;
+#pragma warning restore CA2227 // Collection properties should be read only
#pragma warning disable CA1707 // Identifiers should not contain underscores
/// <summary>
/// Related links.
@@ -54,6 +62,14 @@ namespace Timeline.Models.Http public string Timeline { get; set; } = default!;
}
+ public class UserPermissionsValueConverter : ITypeConverter<UserPermissions, List<string>>
+ {
+ public List<string> Convert(UserPermissions source, List<string> destination, ResolutionContext context)
+ {
+ return source.ToStringList();
+ }
+ }
+
public class UserInfoLinksValueResolver : IValueResolver<User, UserInfo, UserInfoLinks>
{
private readonly IActionContextAccessor _actionContextAccessor;
@@ -84,7 +100,10 @@ namespace Timeline.Models.Http {
public UserInfoAutoMapperProfile()
{
- CreateMap<User, UserInfo>().ForMember(u => u._links, opt => opt.MapFrom<UserInfoLinksValueResolver>());
+ CreateMap<UserPermissions, List<string>>()
+ .ConvertUsing<UserPermissionsValueConverter>();
+ CreateMap<User, UserInfo>()
+ .ForMember(u => u._links, opt => opt.MapFrom<UserInfoLinksValueResolver>());
}
}
}
diff --git a/BackEnd/Timeline/Models/User.cs b/BackEnd/Timeline/Models/User.cs index f08a62db..1e90cd1d 100644 --- a/BackEnd/Timeline/Models/User.cs +++ b/BackEnd/Timeline/Models/User.cs @@ -1,21 +1,23 @@ using System;
+using Timeline.Services;
namespace Timeline.Models
{
- public class User
+ public record User
{
- public string? UniqueId { get; set; }
- public string? Username { get; set; }
- public string? Nickname { get; set; }
- public bool? Administrator { get; set; }
+ public long Id { get; set; }
+ public string UniqueId { get; set; } = default!;
- #region secret
- public long? Id { get; set; }
- public string? Password { get; set; }
- public long? Version { get; set; }
- public DateTime? UsernameChangeTime { get; set; }
- public DateTime? CreateTime { get; set; }
- public DateTime? LastModified { get; set; }
- #endregion secret
+ public string Username { get; set; } = default!;
+ public string Nickname { get; set; } = default!;
+
+ [Obsolete("Use permissions instead.")]
+ public bool Administrator { get; set; }
+ public UserPermissions Permissions { get; set; } = default!;
+
+ public DateTime UsernameChangeTime { get; set; }
+ public DateTime CreateTime { get; set; }
+ public DateTime LastModified { get; set; }
+ public long Version { get; set; }
}
}
|