/// <summary> /// Get a key value pair collection with the specific functionality values and parameters for specific feature /// </summary> /// <param name="feature"></param> /// <returns></returns> public Dictionary<string, string> GetValuesParametersByFeature(EnumFeatures.Features feature) { var allSettings = GetAllKeyValuesSettings(); var auxfunctionsByFeature = default(Dictionary<string, string>); if (allSettings.Any()) { switch (feature) { case EnumFeatures.Features.ScriptRunner: auxfunctionsByFeature = FilterDictionaryKeyValueByParameterStarWith("ScriptRunnerValuesParameters"); break; } if (!object.ReferenceEquals(auxfunctionsByFeature, null) && auxfunctionsByFeature.Any()) { auxfunctionsByFeature = PrepareDictionariesWithStrings(auxfunctionsByFeature); } } return auxfunctionsByFeature; }
public static bool IsActionAccessible( IPrincipal user, EnumFeatures feature, EnumActions action) { //return true; return(((SmartPrincipal)user).IsInFeatureAction(feature, action)); }
public bool IsInFeature(EnumFeatures feature) { if (RoleFeatures == null) { EmployeeHelper employeeHelper = new EmployeeHelper(); RoleFeatures = employeeHelper.GetRoleFeaturesForEmployee(ID); } if (RoleFeatures == null) { return(false); } return(RoleFeatures.FirstOrDefault(o => o.Feature.FeatureName == feature.ToString()) != null); }
public bool IsInFeatureAction(EnumFeatures feature, EnumActions action) { if (RoleFeatures == null) { EmployeeHelper employeeHelper = new EmployeeHelper(); RoleFeatures = employeeHelper.GetRoleFeaturesForEmployee(ID); } if (RoleFeatures == null) { return(false); } RoleFeature rf; switch (action) { case EnumActions.Add: rf = RoleFeatures.FirstOrDefault(o => o.Feature.FeatureName.Contains(feature.ToString()) && o.NewAccessInd == true); return(rf != null); case EnumActions.Edit: rf = RoleFeatures.FirstOrDefault(o => o.Feature.FeatureName.Contains(feature.ToString()) && o.EditAccessInd == true); return(rf != null); case EnumActions.Delete: rf = RoleFeatures.FirstOrDefault(o => o.Feature.FeatureName.Contains(feature.ToString()) && o.DeleteAccessInd == true); return(rf != null); case EnumActions.Save: rf = RoleFeatures.FirstOrDefault(o => o.Feature.FeatureName.Contains(feature.ToString()) && (o.NewAccessInd == true || o.EditAccessInd == true)); return(rf != null); case EnumActions.Search: rf = RoleFeatures.FirstOrDefault(o => o.Feature.FeatureName.Contains(feature.ToString()) && o.ViewAccessInd == true); return(rf != null); case EnumActions.Print: rf = RoleFeatures.FirstOrDefault(o => o.Feature.FeatureName.Contains(feature.ToString()) && o.NewAccessInd == true); return(rf != null); default: return(IsInFeature(feature)); } }
//Created By SK. public static GridBuilder <T> BuildGrid <T>( this GridBuilder <T> gridbuilder, string gridName, string ajaxController, string action, object routedValue, string indexID, string[] hiddenColumns = null, bool allowInsert = true, bool allowEdit = true, bool allowDelete = true, EnumFeatures feature = EnumFeatures.Exempt) where T : class { bool isEditable = true; bool isVisible = true; allowEdit &= (feature == EnumFeatures.Exempt) ? true : AccessControl.IsActionAccessible(HttpContext.Current.User, feature, EnumActions.Edit); allowInsert &= (feature == EnumFeatures.Exempt) ? true : AccessControl.IsActionAccessible(HttpContext.Current.User, feature, EnumActions.Add); allowDelete &= (feature == EnumFeatures.Exempt) ? true : AccessControl.IsActionAccessible(HttpContext.Current.User, feature, EnumActions.Delete); GridBuilder <T> retVal = gridbuilder.Name(gridName).DataKeys(k => k.Add("ID")) .Scrollable(sc => sc.Height("*")) .Resizable(rs => rs.Columns(true)) .EnableCustomBinding(true) .Pageable(paging => paging.PageSize(ConfigurationHelper.GetsmARTDetailGridPageSize()) .Style(Telerik.Web.Mvc.UI.GridPagerStyles.NextPreviousAndNumeric) .Total(100)) .DataBinding(bindings => bindings.Ajax() .Select(action, ajaxController, routedValue) .Insert("_Insert", ajaxController, new { isNew = (indexID.Equals("0") ? true : false) }) .Update("_Update", ajaxController, new { isNew = (indexID.Equals("0") ? true : false) }) .Delete("_Delete", ajaxController, new { MasterID = indexID, isNew = (indexID.Equals("0") ? true : false) }) ); if (isEditable && isVisible) { if (allowInsert) { retVal.Editable(editing => editing.Enabled(isEditable).Mode(Telerik.Web.Mvc.UI.GridEditMode.PopUp).Window(w => w.Modal(true))).ToolBar(commands => commands.Insert()); } retVal.Editable(editing => editing.Enabled(isEditable).Mode(Telerik.Web.Mvc.UI.GridEditMode.PopUp).Window(w => w.Modal(true))); } else { retVal.Editable(editing => editing.Enabled(false)); } Type typeT = typeof(T); PropertyInfo[] properties = typeT.GetProperties(); //// Add keys //GridDataKeyFactory<T> dataKeys = new GridDataKeyFactory<T>(retVal); //foreach (PropertyInfo property in properties) // if (IsAttributePresent<KeyAttribute>(property)) // dataKeys.Add(property.Name); // Add Columns GridColumnFactory <T> columns = new GridColumnFactory <T>(retVal); foreach (PropertyInfo property in properties) { bool IsColumnVisible = !IsAttributePresent <HiddenInputAttribute>(property); if (hiddenColumns != null && hiddenColumns.Contains(property.Name)) { continue; } GridBoundColumnBuilder <T> gridBoundBuilder = columns.Bound(property.Name).Visible(IsColumnVisible); //Set numeric column to right align. if (property.PropertyType == typeof(decimal) || property.PropertyType == typeof(double)) { gridBoundBuilder.HtmlAttributes(new { style = "text-align: right;" }).Format("{0:0.00}"); } if (IsAttributePresent <ClientTemplateHtmlAttribute>(property)) { gridBoundBuilder.ClientTemplate(property.TemplateHtmlForProperty()); } } if (isEditable && isVisible) { columns.Command(commands => { if (allowEdit) { commands.Edit().ButtonType(Telerik.Web.Mvc.UI.GridButtonType.Image); } if (allowDelete) { commands.Delete().ButtonType(Telerik.Web.Mvc.UI.GridButtonType.Image); } } ); } return(retVal); }
public static MvcHtmlString AuthorizedButton(this HtmlHelper html, string Id, string value, string type = "button", object htmlAttributes = null, EnumFeatures feature = EnumFeatures.All, EnumActions action = EnumActions.All) { bool isVisible = true; bool isEditable = true; //TODO: Check for access control if (action != EnumActions.All) { isVisible = AccessControl.IsActionAccessible(html.ViewContext.HttpContext.User as SmartPrincipal, feature, action); //Visable then check readonly // if Readonly then isEditable =false. } TagBuilder builder = new TagBuilder("input"); builder.GenerateId(Id); builder.MergeAttribute("value", value); builder.MergeAttribute("type", type); builder.MergeAttributes(new RouteValueDictionary(htmlAttributes)); if (!isVisible) { builder.MergeAttribute("style", "display: none;"); } if (!isEditable) { builder.MergeAttribute("disabled", "disabled"); } builder.MergeAttribute("background-image", "url('/Content/Images/weighing.png')"); // Render tag return(MvcHtmlString.Create(builder.ToString(TagRenderMode.SelfClosing))); }