public MenuItem(string name, string displayName, string description, IPermissionAttribute permission, string controller, string action, string routeValues) { Controller = controller; Action = action; DisplayName = displayName; Tooltip = description; Permission = permission; Name = name; ParameterObject = (Dictionary <string, object>)(string.IsNullOrWhiteSpace(routeValues) ? new Dictionary <string, object>() : new JavaScriptSerializer().DeserializeObject(routeValues)); }
/// <summary> /// Initializes a new instance of <see cref="PermissionModel"/> for Controller /// </summary> /// <param name="attribute">The attribute.</param> /// <param name="controllerType">Type of the controller.</param> public PermissionModel(IPermissionAttribute attribute, Type controllerType) { this.Permission = attribute.Permission; this.Area = attribute.Area.IsNullOrWhiteSpace() ? RoleEngineHelper.GetControllerArea(controllerType) : attribute.Area; this.Controller = attribute.Controller.IsNullOrWhiteSpace() ? RoleEngineHelper.GetControllerName(controllerType) : attribute.Controller; this.Action = attribute.Action; this.Group = attribute.Group; this.Description = attribute.Description; this.PermissionType = attribute.PermissionType; }
public PropertyDescriptor(I18NManager i18NManager, Type parent, PropertyInfo propertyInfo) { _i18NManager = i18NManager; _parent = parent; _propertyInfo = propertyInfo; var uihint = propertyInfo.GetAttribute <UIHintAttribute>(false); if (uihint != null) { TemplateHint = uihint.UIHint; } Show = propertyInfo.GetAttribute <NoRenderAttribute>(false) == null; Hidden = propertyInfo.GetAttribute <HiddenAttribute>(false) != null; PropertyType = propertyInfo.PropertyType; if (propertyInfo.GetGetMethod(false) != null) { _accessor = new DynamicPropertyGetAccessor(propertyInfo); } var sort = propertyInfo.GetAttribute <SortAttribute>(false); Sort = sort == null ? propertyInfo.Name : sort.Sort; _valueConverter = propertyInfo.GetCustomAttributes(false).OfType <IValueConverter>().FirstOrDefault() ?? new DefaultValueConverter(); _bounded = propertyInfo.GetCustomAttributes(false).OfType <IBounded>().FirstOrDefault(); var p = propertyInfo.GetCustomAttributes(false).OfType <IPermissionAttribute>(); Permission = new CompositePermission(p, true); var validatePropertyName = propertyInfo.PropertyType.GetAttribute <ValidatePropertyNameAttribute>(false); this.ValidatePropertyName = propertyInfo.Name; if (validatePropertyName != null) { ValidatePropertyName += "." + validatePropertyName.ValidatePropertyName; } }
/// <summary> /// Initializes a new instance of the <see cref="PermissionModel" /> class for Action /// </summary> /// <param name="attribute">The attribute</param> /// <param name="controllerAttribute">The controller attribute if any</param> /// <param name="controllerType">Type of the controller</param> /// <param name="methodInfo">The method information</param> public PermissionModel(IPermissionAttribute attribute, IPermissionAttribute controllerAttribute, Type controllerType, MemberInfo methodInfo) { // if the Action is decorated by ActivePermissionAttribute // it will be considered a new permission (unless it map to an existing permission) // get permission decoration from ActivePermissionAttribute // if ActivePermissionAttribute does not provide the information // then get from MethodInfo or controllerAttribute // not inherit from controller, the action must define its own this.Permission = attribute.Permission; // inherit from controller if not defined // Area can be "" (root area) => here we check null only this.Area = attribute.Area ?? RoleEngineHelper.GetControllerArea(controllerType); // inherit from controller if not defined // Controller must be specified if (attribute.Controller.IsNotNullOrEmpty()) { this.Controller = attribute.Controller; } else { this.Controller = controllerAttribute == null || controllerAttribute.Controller.IsNullOrWhiteSpace() ? RoleEngineHelper.GetControllerName(controllerType) : controllerAttribute.Controller; } if (attribute.Action.IsNotNullOrEmpty()) { this.Action = attribute.Action; } else { string actionName = null; // todo later //if (methodInfo.IsDefined(typeof(ActionNameAttribute))) // actionName = methodInfo.GetCustomAttribute<ActionNameAttribute>()?.Name; if (actionName.IsNullOrEmpty()) { actionName = methodInfo.Name; } this.Action = actionName; } // the Action does not define the group => inherit from controller this.Group = attribute.Group.IsNullOrWhiteSpace() ? controllerAttribute?.Group : attribute.Group; this.Description = attribute.Description; this.PermissionType = attribute.PermissionType; //// if AllowSuperAdminOnlyEnum.Inherit then get from controller //this.PermissionType = attribute.PermissionType == PermissionType.Inherit ? // (controllerAttribute?.PermissionType ?? PermissionType.Inherit) : // attribute.PermissionType; }
public MenuItem(string name, string displayName, string description, IPermissionAttribute permission) : this(name, displayName, description, permission, "", "", null) { }