public static bool IsActionAccessible( IPrincipal user, EnumFeatures feature, EnumActions action) { //return true; return(((SmartPrincipal)user).IsInFeatureAction(feature, action)); }
/* DATABASE METHODS ***********************************************************************************************************************************/ public bool isExists(EnumActions action, Guid?id, object value) { var result = action == EnumActions.Create ? db.UserAccountRoles.AsNoTracking().Where(x => x.Name.ToLower() == value.ToString().ToLower()).FirstOrDefault() : db.UserAccountRoles.AsNoTracking().Where(x => x.Name.ToLower() == value.ToString().ToLower() && x.Id != id).FirstOrDefault(); return(result != 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)); } }
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))); }