diff options
author | crupest <crupest@outlook.com> | 2020-01-29 23:13:15 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-01-29 23:13:15 +0800 |
commit | dd0097af5c4ccbe25a1faca2286d729c93fd4116 (patch) | |
tree | c9131a7b95fffd64bf2c26527d7f62fbdefa7e2c /Timeline/Services/UserRoleConvert.cs | |
parent | 401a0c86054711bf5ebdce7d7717c9b59bffc2fa (diff) | |
download | timeline-dd0097af5c4ccbe25a1faca2286d729c93fd4116.tar.gz timeline-dd0097af5c4ccbe25a1faca2286d729c93fd4116.tar.bz2 timeline-dd0097af5c4ccbe25a1faca2286d729c93fd4116.zip |
...
Diffstat (limited to 'Timeline/Services/UserRoleConvert.cs')
-rw-r--r-- | Timeline/Services/UserRoleConvert.cs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Timeline/Services/UserRoleConvert.cs b/Timeline/Services/UserRoleConvert.cs new file mode 100644 index 00000000..4fa4a7b8 --- /dev/null +++ b/Timeline/Services/UserRoleConvert.cs @@ -0,0 +1,44 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using Timeline.Entities;
+
+namespace Timeline.Services
+{
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "No need.")]
+ public static class UserRoleConvert
+ {
+ public const string UserRole = UserRoles.User;
+ public const string AdminRole = UserRoles.Admin;
+
+ public static string[] ToArray(bool administrator)
+ {
+ return administrator ? new string[] { UserRole, AdminRole } : new string[] { UserRole };
+ }
+
+ public static string[] ToArray(string s)
+ {
+ return s.Split(',').ToArray();
+ }
+
+ public static bool ToBool(IReadOnlyCollection<string> roles)
+ {
+ return roles.Contains(AdminRole);
+ }
+
+ public static string ToString(IReadOnlyCollection<string> roles)
+ {
+ return string.Join(',', roles);
+ }
+
+ public static string ToString(bool administrator)
+ {
+ return administrator ? UserRole + "," + AdminRole : UserRole;
+ }
+
+ public static bool ToBool(string s)
+ {
+ return s.Contains("admin", StringComparison.InvariantCulture);
+ }
+ }
+}
|