public IEnumerable <string> GetEmailListByPrivilege(ClientPrivilege privs) { var clients = Client.FindByPrivilege(privs); IEnumerable <string> result = clients.Select(c => c.Email); return(result); }
public static bool HasPriv(this IPrivileged item, string[] privType) { ClientPrivilege cp = 0; foreach (string p in privType) cp |= (ClientPrivilege)Enum.Parse(typeof(ClientPrivilege), p, true); return item.HasPriv(cp); }
public static AuthInfo Create(string location, bool showButton, ClientPrivilege authTypes) { return(new AuthInfo() { Location = location, AuthTypes = authTypes, ShowButton = showButton }); }
public static IEnumerable <IPriv> GetPrivs(ClientPrivilege privs) { foreach (var p in _privs) { if ((privs & p.PrivFlag) > 0) { yield return(p); } } }
public static ClientPrivilege CalculatePriv(IEnumerable <IPriv> privs) { ClientPrivilege result = 0; if (privs != null) { privs.Select(x => { result |= x.PrivFlag; return(x); }).ToList(); } return(result); }
/// <summary> /// Authorizes requests using LNF privileges and/or a list of LNF ClientIDs. /// </summary> /// <param name="requiredPrivilege">The privilege required for access.</param> /// <param name="allowedClientIDs">An array of ClientID integers that are allowed access.</param> /// <param name="modelType">The model that will be passed to the view if access is denied. Defaults to LNF.Web.Mvc.AccessDeniedModel. The class must a have public contstructor that takes a single LNF.Data.ClientItem parameter.</param> /// <param name="accessDeniedViewName">The name of the view to display for unauthorized requests. Defaults to "AccessDenied". If null the request will redirect to the login page.</param> public LNFAuthorizeAttribute(ClientPrivilege requiredPrivilege = 0, int[] allowedClientIDs = null, Type modelType = null, string accessDeniedViewName = "AccessDenied") { if (modelType != null && !modelType.IsSubclassOf(typeof(BaseModel))) { throw new ArgumentException("The type must inherit LNF.Web.Mvc.BaseModel.", "modelType"); } ModelType = modelType ?? typeof(AccessDeniedModel); RequiredPrivilege = requiredPrivilege; AllowedClientIDs = allowedClientIDs; AccessDeniedViewName = accessDeniedViewName; }
/// <summary> /// Returns all active clients not associated with the specified resource /// </summary> public static DataTable SelectAvailClients(int resourceId) { ClientPrivilege p = ClientPrivilege.LabUser | ClientPrivilege.Staff; var dt = DataCommand.Create() .Param(new { Action = "SelectAvailClients", ResourceID = resourceId, Privs = (int)p }) .FillDataTable("sselScheduler.dbo.procResourceClientSelect"); dt.PrimaryKey = new[] { dt.Columns["ClientID"] }; return(dt); }
public ClientPrivilege SelectAuthTypes(string fileName) { ClientPrivilege result = 0; DataRow[] rows = _AppPages.Select(string.Format("FileName = '{0}'", fileName)); if (rows.Length > 0) { //just use the first one, the AuthTypes will always be the same for duplicates (same as the last one added). result = (ClientPrivilege)Utility.ConvertTo(rows[0]["AuthTypes"], 0); } return(result); }
public static ClientPrivilege CalculatePriv(IEnumerable <string> privs) { ClientPrivilege result = 0; if (privs != null) { foreach (var p in _privs.Where(x => privs.Contains(x.PrivType))) { result |= p.PrivFlag; } } return(result); }
public static ClientPrivilege CalculatePriv(IEnumerable <int> privs) { ClientPrivilege result = 0; if (privs != null) { foreach (var p in privs) { result |= (ClientPrivilege)p; } } return(result); }
public IEnumerable <Client> GetAllClients(int priv = 0) { IQueryable <Data.ClientInfo> query; ClientPrivilege p = (ClientPrivilege)priv; if (priv == 0) { query = DataSession.Query <Data.ClientInfo>(); } else { query = DataSession.Query <Data.ClientInfo>().Where(x => (x.Privs & p) > 0); } return(CreateClients(query)); }
public void CheckAuth() { if (_AppPages == null) { return; } foreach (DataRow dr in _AppPages.Rows) { ClientPrivilege authTypes = (ClientPrivilege)Utility.ConvertTo(dr["AuthTypes"], 0); if (authTypes == 0) { dr["Visible"] = true; } else { dr["Visible"] = CurrentUser.HasPriv(authTypes); } } }
private string GetSitePrivileges(DataRow dr) { string result = "<b>Privileges: </b>"; ClientPrivilege val = (ClientPrivilege)dr.Field <int>("Privs"); string list = val.ToString(); //creates a comma separated list of enum names if (list == null) { result += "none"; } else { result += list; } return(result); }
public static bool HasPriv(this ClientPrivilege priv1, ClientPrivilege priv2) { return((priv1 & priv2) > 0); }
public bool HasPriv(ClientPrivilege privs) => CurrentUser.HasPriv(privs);
public static void RemovePriv(this IPrivileged item, ClientPrivilege privs) { if (item == null) return; item.Privs &= ~privs; }
public void AddPage(int groupId, string fileName, string buttonText, string toolTip, ClientPrivilege authTypes) { AddPage(groupId, fileName, string.Empty, buttonText, toolTip, authTypes); }
public static IPriv FindByClientPrivilege(ClientPrivilege priv) { return(_privs.FirstOrDefault(x => x.PrivFlag == priv)); }
public static int CalculatePriv(ClientPrivilege privs) { return((int)privs); }
public static string[] GetPrivTypes(ClientPrivilege privs) { return(privs.ToString().Split(',').Select(x => x.Trim()).ToArray()); }
public static bool HasPriv(this IPrivileged item, string privType) { if (item == null) return false; ClientPrivilege cp = (ClientPrivilege)Enum.Parse(typeof(ClientPrivilege), privType, true); return item.HasPriv(cp); }
public IEnumerable <IClient> GetActiveClients(DateTime sd, DateTime ed, ClientPrivilege privs = 0) { return(Get <List <ClientItem> >("webapi/data/client/active/range", QueryStrings(new { sd = sd.ToString("yyyy-MM-dd"), ed = ed.ToString("yyyy-MM-dd"), privs = (int)privs }))); }
public static bool HasPriv(string privType, ClientPrivilege privs) { IPriv p = FindByPrivType(privType); return(HasPriv(p.PrivFlag, privs)); }
private bool DisplayButton(Button btn, ClientPrivilege auths) { btn.Visible = CurrentUser.HasPriv(auths); return(btn.Visible); }
public static IHtmlString PageMenuLink <T>(this HtmlHelper <T> helper, string linkText, string actionName, string controllerName, ClientPrivilege requiredPriv = 0) where T : BaseModel { IProvider provider = helper.ViewData.Model.Provider; string currentPage = helper.ViewData.Model.CurrentPage; if (requiredPriv == 0 || helper.CurrentUser(provider).HasPriv(requiredPriv)) { return(helper.ActionLink(linkText, actionName, controllerName, null, new { @class = "nav-menu-item" + ((currentPage == controllerName) ? " nav-selected" : string.Empty) })); } else { return(new HtmlString(string.Empty)); } }
public IEnumerable <IClient> FindByPrivilege(ClientPrivilege priv, bool?active = true) { throw new NotImplementedException(); }
public void AddPage(int groupId, string fileName, string queryString, string buttonText, string toolTip, ClientPrivilege authTypes) { //It is possible that the same page is added mulitple times (different QueryStrings or any other reason, maybe we just want two buttons, etc). //When this is the case, the AuthTypes for the last added duplicate AppPage will be the one used. DataRow nr = _AppPages.NewRow(); nr["GroupID"] = groupId; nr["FileName"] = fileName; nr["QueryString"] = queryString; nr["ButtonText"] = buttonText; nr["ToolTip"] = toolTip; nr["AuthTypes"] = 0; nr["Visible"] = true; _AppPages.Rows.Add(nr); DataRow[] rows = _AppPages.Select(string.Format("FileName = '{0}'", fileName)); foreach (DataRow dr in rows) { dr["AuthTypes"] = (int)authTypes; } }
public static IQueryable <ClientInfo> SelectClientInfoByPriv(this ISession session, ClientPrivilege priv) { var query = session.Query <ClientInfo>().Where(x => (x.Privs & priv) > 0); return(query); }
public IEnumerable <string> GetEmailListByPrivilege(ClientPrivilege privs) { return(Provider.Mail.GetEmailListByPrivilege(privs)); }
public IEnumerable <IClient> GetActiveClients(ClientPrivilege privs = 0) { return(Get <List <ClientItem> >("webapi/data/client/active", QueryStrings(new { privs = (int)privs }))); }