-
Notifications
You must be signed in to change notification settings - Fork 1
/
Permissions.cs
93 lines (71 loc) · 2.95 KB
/
Permissions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
namespace Erpmi.Security
{
public static class Permissions
{
public static ReadOnlyCollection<Permission> AllPermissions;
public const string UsersPermissionGroupName = "User Permissions";
public static Permission ViewUsers = new Permission("View Users", "users.view", UsersPermissionGroupName, "Permission to view other users account details");
public static Permission ManageUsers = new Permission("Manage Users", "users.manage", UsersPermissionGroupName, "Permission to create, delete and modify other users account details");
public const string RolesPermissionGroupName = "Role Permissions";
public static Permission ViewRoles = new Permission("View Roles", "roles.view", RolesPermissionGroupName, "Permission to view available roles");
public static Permission ManageRoles = new Permission("Manage Roles", "roles.manage", RolesPermissionGroupName, "Permission to create, delete and modify roles");
public static Permission AssignRoles = new Permission("Assign Roles", "roles.assign", RolesPermissionGroupName, "Permission to assign roles to users");
static Permissions()
{
List<Permission> allPermissions = new List<Permission>()
{
ViewUsers,
ManageUsers,
ViewRoles,
ManageRoles,
AssignRoles
};
AllPermissions = allPermissions.AsReadOnly();
}
public static Permission GetPermissionByName(string permissionName)
{
return AllPermissions.Where(p => p.Name == permissionName).FirstOrDefault();
}
public static Permission GetPermissionByValue(string permissionValue)
{
return AllPermissions.Where(p => p.Value == permissionValue).FirstOrDefault();
}
public static string[] GetAllPermissionValues()
{
return AllPermissions.Select(p => p.Value).ToArray();
}
public static string[] GetAdministrativePermissionValues()
{
return new string[] { ManageUsers, ManageRoles, AssignRoles };
}
}
public class Permission
{
public Permission()
{ }
public Permission(string name, string value, string groupName, string description = null)
{
Name = name;
Value = value;
GroupName = groupName;
Description = description;
}
public string Name { get; set; }
public string Value { get; set; }
public string GroupName { get; set; }
public string Description { get; set; }
public override string ToString()
{
return Value;
}
public static implicit operator string(Permission permission)
{
return permission.Value;
}
}
}