diff options
author | 杨宇千 <crupest@outlook.com> | 2019-08-05 18:58:56 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-08-05 18:58:56 +0800 |
commit | 57151c879376374425adb04fb68dad2cf7930df8 (patch) | |
tree | b5f26eabcfa547e76dd7e70ffe0763f3fadf0ad5 /Timeline/Entities/UserUtility.cs | |
parent | 0c0e0c963458aae3ba9589622fc688388833fa9c (diff) | |
download | timeline-57151c879376374425adb04fb68dad2cf7930df8.tar.gz timeline-57151c879376374425adb04fb68dad2cf7930df8.tar.bz2 timeline-57151c879376374425adb04fb68dad2cf7930df8.zip |
3 things.
1. Exchange Models and Entities namespace.
2. Fix the bug that input with missing field leads to 500.
3. Write unit tests.
Diffstat (limited to 'Timeline/Entities/UserUtility.cs')
-rw-r--r-- | Timeline/Entities/UserUtility.cs | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/Timeline/Entities/UserUtility.cs b/Timeline/Entities/UserUtility.cs deleted file mode 100644 index 14cdb2d6..00000000 --- a/Timeline/Entities/UserUtility.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Linq; -using Timeline.Models; -using Timeline.Services; - -namespace Timeline.Entities -{ - public static class UserUtility - { - public const string UserRole = UserRoles.User; - public const string AdminRole = UserRoles.Admin; - - public static string[] UserRoleArray { get; } = new string[] { UserRole }; - public static string[] AdminRoleArray { get; } = new string[] { UserRole, AdminRole }; - - public static string[] IsAdminToRoleArray(bool isAdmin) - { - return isAdmin ? AdminRoleArray : UserRoleArray; - } - - public static bool RoleArrayToIsAdmin(string[] roles) - { - return roles.Contains(AdminRole); - } - - public static string[] RoleStringToRoleArray(string roleString) - { - return roleString.Split(',').ToArray(); - } - - public static string RoleArrayToRoleString(string[] roles) - { - return string.Join(',', roles); - } - - public static string IsAdminToRoleString(bool isAdmin) - { - return RoleArrayToRoleString(IsAdminToRoleArray(isAdmin)); - } - - public static bool RoleStringToIsAdmin(string roleString) - { - return RoleArrayToIsAdmin(RoleStringToRoleArray(roleString)); - } - - public static UserInfo CreateUserInfo(User user) - { - if (user == null) - throw new ArgumentNullException(nameof(user)); - return new UserInfo(user.Name, RoleStringToIsAdmin(user.RoleString)); - } - - internal static UserCache CreateUserCache(User user) - { - if (user == null) - throw new ArgumentNullException(nameof(user)); - return new UserCache { Username = user.Name, Administrator = RoleStringToIsAdmin(user.RoleString), Version = user.Version }; - } - } -} |