Exemplo n.º 1
0
        public bool HasPermission <TUserPermission>(TUserPermission permission)
            where TUserPermission : Enum, IConvertible
        {
            var principal = principalService.GetCurrentPrincipal();

            var user = userRepository.GetByUsername(principal.Identity.Name);

            if (user == null)
            {
                return(false);
            }

            var permissions = EnumHelper.ConvertTo <TUserPermission>(user.Permissions);
            var userType    = (UserType)user.Type;

            switch (userType)
            {
            case UserType.Super:
            case UserType.Octacom:
                return(true);

            case UserType.Administrator:
                // Administrators should have ViewAudit permission if they want to access the Audit page.
                // It's not activated by default. Only super users have access with no restriction.
                return(Convert.ToInt32(permission) != ((int)UserPermission.ViewAudits));

            default:
                return(permissions.HasFlag(permission));
            }
        }