Exemple #1
0
        /// <summary>
        /// Set the dault page locations for actions ( create/edit/list/manage ).
        /// </summary>
        /// <param name="viewSettings"></param>
        public static void CheckAndDefaultSettings(ModelSettings settings)
        {
            if (settings == null)
            {
                return;
            }

            var permissions  = settings.Permissions;
            var viewSettings = settings.View;

            if (settings.Permissions != null)
            {
                if (string.IsNullOrEmpty(permissions.RolesForEdit))
                {
                    permissions.RolesForEdit = permissions.RolesForCreate;
                }
            }

            if (settings.View != null)
            {
                if (string.IsNullOrEmpty(viewSettings.PageLocationForCreate))
                {
                    viewSettings.PageLocationForCreate = "Pages/Create";
                }
                if (string.IsNullOrEmpty(viewSettings.PageLocationForEdit))
                {
                    viewSettings.PageLocationForEdit = "Pages/Edit";
                }
                if (string.IsNullOrEmpty(viewSettings.PageLocationForDetails))
                {
                    viewSettings.PageLocationForDetails = "Pages/Details";
                }
                if (string.IsNullOrEmpty(viewSettings.PageLocationForIndex))
                {
                    viewSettings.PageLocationForIndex = "Pages/List";
                }
                if (string.IsNullOrEmpty(viewSettings.PageLocationForManage))
                {
                    viewSettings.PageLocationForManage = "Pages/Manage";
                }
                if (string.IsNullOrEmpty(viewSettings.ActionForCreationSuccess))
                {
                    viewSettings.ActionForCreationSuccess = "Details";
                }
            }
        }
 /// <summary>
 /// Converts a widgetattribute to a widget definition.
 /// </summary>
 /// <param name="attribute"></param>
 /// <returns></returns>
 public static ModelSettings Convert(ModelAttribute attribute)
 {
     ModelSettings model = new ModelSettings();
     model.Id = attribute.Id;
     model.Name = attribute.Name;
     model.DisplayName = attribute.DisplayName;
     model.Author = attribute.Author;
     model.Email = attribute.Email;
     model.DeclaringType = attribute.DeclaringType;
     model.DeclaringAssembly = attribute.DeclaringAssembly;
     model.SortIndex = attribute.SortIndex;            
     model.Url = attribute.Url;
     model.Version = attribute.Version;
     model.IsPagable = attribute.IsPagable;
     model.IsSystemModel = attribute.IsSystemModel;
     model.IO.IsExportable = attribute.IsExportable;
     model.IO.IsImportable = attribute.IsImportable;
     model.IO.FormatsForExport = attribute.FormatsForExport;
     model.IO.FormatsForImport = attribute.FormatsForImport;
     model.View.UrlForCreate = attribute.UrlForCreate;
     model.View.UrlForIndex = attribute.UrlForIndex;
     model.View.UrlForManage = attribute.UrlForManage;
     model.View.HeadingForCreate = attribute.HeadingForCreate;
     model.View.HeadingForDetails = attribute.HeadingForDetails;
     model.View.HeadingForEdit = attribute.HeadingForEdit;
     model.View.HeadingForIndex = attribute.HeadingForIndex;
     model.View.HeadingForManage = attribute.HeadingForManage;
     model.Permissions.RolesForModel = attribute.RolesForModel;
     model.Permissions.RolesForCreate = attribute.RolesForCreate;
     model.Permissions.RolesForView = attribute.RolesForView;
     model.Permissions.RolesForIndex = attribute.RolesForIndex;
     model.Permissions.RolesForManage = attribute.RolesForManage;
     model.Permissions.RolesForDelete = attribute.RolesForDelete;
     model.Permissions.RolesForImport = attribute.RolesForImport;
     return model;
 }
        public void CanNotUseModelPermissions()
        {
            var permissionsMap = new Dictionary<Type, ModelSettings>();
            var permissions = new ModelPermissionSettings()
            {
                RolesForCreate = "Admin",
                RolesForView = "Admin",
                RolesForIndex = "Admin",
                RolesForDelete = "Admin",
                RolesForManage = "Admin",
                RolesForImport = "Admin"
            };
            permissionsMap[typeof(Link)] = new ModelSettings()
            {
                Permissions = permissions  
            };

            var securityHelper = new EntitySettingsHelper();
            securityHelper.Init(permissionsMap);

            Auth.Init(new AuthWin("Admin", new UserPrincipal(1, "kishore", "moderator", "custom", true)));

            // Check everything is false.
            Assert.IsFalse(securityHelper.HasAccessToCreate<Link>());
            Assert.IsFalse(securityHelper.HasAccessToDelete<Link>());
            Assert.IsFalse(securityHelper.HasAccessToImport<Link>());
            Assert.IsFalse(securityHelper.HasAccessToIndex<Link>());
            Assert.IsFalse(securityHelper.HasAccessToManage<Link>());
            Assert.IsFalse(securityHelper.HasAccessToView<Link>());
        }