Exemplo n.º 1
0
 public PermissionDisplay(string groupName, string name, string description, myFacilityPermissions permission
                          /*string moduleName*/)
 {
     Permission  = permission;
     GroupName   = groupName;
     ShortName   = name ?? throw new ArgumentNullException(nameof(name));
     Description = description ?? throw new ArgumentNullException(nameof(description));
     //ModuleName = moduleName;
 }
 public HasPermissionAttribute(myFacilityPermissions permission) : base(permission.ToString())
 {
 }
        /// <summary>
        /// This returns true if the current user has the permission
        /// </summary>
        /// <param name="user"></param>
        /// <param name="permission"></param>
        /// <returns></returns>
        public static bool myFacilityUserHasThisPermission(this ClaimsPrincipal user, myFacilityPermissions permission)
        {
            var permissionClaim =
                user?.Claims.SingleOrDefault(x => x.Type == PermissionConstants.PackedPermissionClaimType);

            return(permissionClaim?.Value.UnpackPermissionsFromString().ToArray().UserHasThisPermission(permission) == true);
        }
Exemplo n.º 4
0
 /// <summary>
 /// This is the main checker of whether a user permissions allows them to access something with the given permission
 /// </summary>
 /// <param name="usersPermissions"></param>
 /// <param name="permissionToCheck"></param>
 /// <returns></returns>
 public static bool UserHasThisPermission(this myFacilityPermissions[] usersPermissions, myFacilityPermissions permissionToCheck)
 {
     return(usersPermissions.Contains(permissionToCheck) || usersPermissions.Contains(myFacilityPermissions.AccessAll));
 }