aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Models/Http/UserInfo.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-11-12 21:38:43 +0800
committercrupest <crupest@outlook.com>2020-11-12 21:38:43 +0800
commitee1b2b5b100268aa510257a1a2cd4cd03f9fc72b (patch)
tree221a2af5008e180e180f5400f127a0d404ed5158 /BackEnd/Timeline/Models/Http/UserInfo.cs
parent2c6b812382e04956793d90ba4148dd4aa7da3b70 (diff)
downloadtimeline-ee1b2b5b100268aa510257a1a2cd4cd03f9fc72b.tar.gz
timeline-ee1b2b5b100268aa510257a1a2cd4cd03f9fc72b.tar.bz2
timeline-ee1b2b5b100268aa510257a1a2cd4cd03f9fc72b.zip
...
Diffstat (limited to 'BackEnd/Timeline/Models/Http/UserInfo.cs')
-rw-r--r--BackEnd/Timeline/Models/Http/UserInfo.cs21
1 files changed, 20 insertions, 1 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>());
}
}
}