示例#1
0
        public void SitkaAdministratorsCanAccessAllFeaturesAndUnassignedCantAccessAnyFeatures()
        {
            //If we start getting exceptions, then this should become an acceptance test
            var baseFeatureClass = typeof(FirmaBaseFeature);
            var types            = AppDomain.CurrentDomain.GetAssemblies().SelectMany(s => s.GetTypes()).Where(p => baseFeatureClass.IsAssignableFrom(p) && p.Name != baseFeatureClass.Name && !p.IsAbstract);
            var listOfErrors     = new List <string>();

            foreach (var type in types)
            {
                var obj = FirmaBaseFeature.InstantiateFeature(type);
                if (!obj.GrantedRoles.Contains(Role.SitkaAdmin) && obj.GrantedRoles.Count != 0)
                {
                    var errorMessage = $"Feature {type.FullName} is not available to Administrators";
                    listOfErrors.Add(errorMessage);
                }

                //Validate Unassigned does NOT have access
                if (obj.GrantedRoles.Contains(Role.Unassigned))
                {
                    string errorMessage = $"Feature {type.FullName} is available to the Unassigned role";
                    listOfErrors.Add(errorMessage);
                }
            }

            if (listOfErrors.Count > 0)
            {
                string message = string.Format("{0}{0}{1}", Environment.NewLine, string.Join(Environment.NewLine, listOfErrors));
                Approvals.Verify(message);
            }
        }
        public static bool DoesRoleHavePermissionsForFeature(IRole role, Type type)
        {
            var firmaBaseFeature = FirmaBaseFeature.InstantiateFeature(type);

            if (IsContextFeatureByInheritance(firmaBaseFeature))
            {
                return(true);
            }
            else
            {
                return(firmaBaseFeature.GrantedRoles.Contains(role) || (role == null));
            }
        }