Beispiel #1
0
        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);
 }
Beispiel #3
0
 public static AuthInfo Create(string location, bool showButton, ClientPrivilege authTypes)
 {
     return(new AuthInfo()
     {
         Location = location,
         AuthTypes = authTypes,
         ShowButton = showButton
     });
 }
Beispiel #4
0
 public static IEnumerable <IPriv> GetPrivs(ClientPrivilege privs)
 {
     foreach (var p in _privs)
     {
         if ((privs & p.PrivFlag) > 0)
         {
             yield return(p);
         }
     }
 }
Beispiel #5
0
        public static ClientPrivilege CalculatePriv(IEnumerable <IPriv> privs)
        {
            ClientPrivilege result = 0;

            if (privs != null)
            {
                privs.Select(x => { result |= x.PrivFlag; return(x); }).ToList();
            }
            return(result);
        }
Beispiel #6
0
        /// <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;
        }
Beispiel #7
0
        /// <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);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        public static ClientPrivilege CalculatePriv(IEnumerable <int> privs)
        {
            ClientPrivilege result = 0;

            if (privs != null)
            {
                foreach (var p in privs)
                {
                    result |= (ClientPrivilege)p;
                }
            }
            return(result);
        }
Beispiel #11
0
        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));
        }
Beispiel #12
0
 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);
         }
     }
 }
Beispiel #13
0
        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);
        }
Beispiel #14
0
 public static bool HasPriv(this ClientPrivilege priv1, ClientPrivilege priv2)
 {
     return((priv1 & priv2) > 0);
 }
Beispiel #15
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;
 }
Beispiel #17
0
 public void AddPage(int groupId, string fileName, string buttonText, string toolTip, ClientPrivilege authTypes)
 {
     AddPage(groupId, fileName, string.Empty, buttonText, toolTip, authTypes);
 }
Beispiel #18
0
 public static IPriv FindByClientPrivilege(ClientPrivilege priv)
 {
     return(_privs.FirstOrDefault(x => x.PrivFlag == priv));
 }
Beispiel #19
0
 public static int CalculatePriv(ClientPrivilege privs)
 {
     return((int)privs);
 }
Beispiel #20
0
 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);
 }
Beispiel #22
0
 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 })));
 }
Beispiel #23
0
        public static bool HasPriv(string privType, ClientPrivilege privs)
        {
            IPriv p = FindByPrivType(privType);

            return(HasPriv(p.PrivFlag, privs));
        }
Beispiel #24
0
 private bool DisplayButton(Button btn, ClientPrivilege auths)
 {
     btn.Visible = CurrentUser.HasPriv(auths);
     return(btn.Visible);
 }
Beispiel #25
0
        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));
            }
        }
Beispiel #26
0
 public IEnumerable <IClient> FindByPrivilege(ClientPrivilege priv, bool?active = true)
 {
     throw new NotImplementedException();
 }
Beispiel #27
0
        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;
            }
        }
Beispiel #28
0
        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));
 }
Beispiel #30
0
 public IEnumerable <IClient> GetActiveClients(ClientPrivilege privs = 0)
 {
     return(Get <List <ClientItem> >("webapi/data/client/active", QueryStrings(new { privs = (int)privs })));
 }