static bool IsOn(this IUser user, string serviceName, string objectName, PrivilegeRole role) { serviceName = serviceName ?? ""; objectName = objectName ?? ""; var privilege = user.Privileges?.FirstOrDefault(p => p.ServiceName.IsEquals(serviceName) && p.ObjectName.IsEquals(objectName) && p.ObjectIdentity.IsEquals("")); if (privilege == null && !objectName.Equals("")) { privilege = user.Privileges?.FirstOrDefault(p => p.ServiceName.IsEquals(serviceName) && p.ObjectName.IsEquals("") && p.ObjectIdentity.IsEquals("")); } return(privilege != null && privilege.Role.ToEnum <PrivilegeRole>().Equals(role)); }
/// <summary> /// Gets the default actions of the privilege role /// </summary> /// <param name="role">The privilege role</param> /// <returns></returns> public static List <Action> GetActions(this PrivilegeRole role) => role.Equals(PrivilegeRole.Administrator) ? new List <Action> { Action.Full } : role.Equals(PrivilegeRole.Moderator) ? new List <Action> { Action.CheckIn, Action.CheckOut, Action.Comment, Action.Vote, Action.Approve, Action.Restore, Action.Rollback, Action.Delete, Action.Update, Action.Create, Action.View, Action.Download } : role.Equals(PrivilegeRole.Editor) ? new List <Action> { Action.CheckIn, Action.CheckOut, Action.Comment, Action.Vote, Action.Restore, Action.Rollback, Action.Delete, Action.Update, Action.Create, Action.View, Action.Download } : role.Equals(PrivilegeRole.Contributor) ? new List <Action> { Action.CheckIn, Action.CheckOut, Action.Comment, Action.Vote, Action.Create, Action.View, Action.Download } : role.Equals(PrivilegeRole.Viewer) ? new List <Action> { Action.View, Action.Download } : role.Equals(PrivilegeRole.Downloader) ? new List <Action> { Action.Download } : new List <Action>();
public static void initCacheLogin(string userName, string PersonName, long Code, long accountID, long personID) { if (_cacheUser.ContainsKey(userName)) { return; } lock (_cacheUser) { CacheUser c = new CacheUser(); using (LV.Core.DAL.EntityFramework.EFDALContainer ef = new Core.DAL.EntityFramework.EFDALContainer()) { var obj = new object[1] { accountID }; c.PersonID = personID; c.AccountID = accountID; c.PersonName = PersonName; c.Code = Code; DataSet model = ef.Repository.ExecuteStoreScalar("usp_GetPerApplication", obj); DataTable dt = model.Tables[0]; Dictionary <byte, string> PermissionList = GetPermission(); c.PrivilegeRole = new List <PrivilegeRole>(); List <Application> functionPermision = new List <Application>(); foreach (DataRow item in dt.Rows) { PrivilegeRole p = new PrivilegeRole(); p.AppFuncID = item.IsNull("AppFuncID") ? 0 : item.Field <long>("AppFuncID"); p.PermVals = item.IsNull("PermVals") ? (byte)0 : item.Field <byte>("PermVals"); p.PersPer = GetPerListValue(p.PermVals, PermissionList); c.PrivilegeRole.Add(p); Application application = new Application(); application.AppFunctions = item.Field <string>("AppFunctions"); application.Badge = item.Field <string>("Badge"); application.IsLongTile = item.IsNull("IsLongTile") ? false : item.Field <bool>("IsLongTile"); application.AppFuncID = item.IsNull("AppFuncID") ? 0 : item.Field <long>("AppFuncID"); application.IconPath = item.Field <string>("IconPath"); application.LandingPageURL = item.Field <string>("LandingPageURL"); application.PAppFuncID = item.IsNull("PAppFuncID") ? 0 : item.Field <long>("PAppFuncID"); application.Idx = item.IsNull("Idx") ? (byte)0 : item.Field <byte>("Idx"); application.AppTitle = item.Field <string>("AppTitle").Replace("|n|", ""); application.AppDesc = item.Field <string>("AppDesc"); application.ColorSchema = item.Field <string>("ColorSchema"); application.NotDisplayed = item.IsNull("NotDisplayed") ? false : item.Field <bool>("NotDisplayed"); application.FuncType = item.Field <string>("FuncType"); functionPermision.Add(application); } //Danh sach role cua user c.roleList = (from h in ef.Repository.GetQuery <PersonRole>() join i in ef.Repository.GetQuery <Person>() on h.PersonID equals i.PersonID join j in ef.Repository.GetQuery <refRole>() on h.RoleID equals j.RoleID where h.PersonID == Code select new RoleList { RoleID = h.RoleID, RoleName = j.RoleName, IsPrimaryRole = h.IsPrimaryRole, }).ToList(); var ApplicationList = ef.Repository.GetQuery <Application>().ToList(); foreach (var role in c.roleList) { List <Realms> applicationByRole = (from h in ef.Repository.GetQuery <Realms>() where h.RoleID == role.RoleID select h).ToList(); role.application = (from h in functionPermision join k in applicationByRole on h.AppFuncID equals k.AppFuncID select h).ToList(); } // //var applicationList = _cacheGolbal.Application.ToList(); //var results = c.FunctionPermision.DistinctBy(x => x.PAppFuncID).ToList(); //c.treeFunction = new List<TreeViewObject>(); //foreach (var item in results) //{ // var row = applicationList.Where(x => x.AppFuncID == item.PAppFuncID).FirstOrDefault(); // while (row.PAppFuncID != null) // { // if (row != null) // { // var check = c.FunctionPermision.Where(x => x.AppFuncID == row.AppFuncID).FirstOrDefault(); // if (check == null) // { // c.FunctionPermision.Add(row); // } // row = applicationList.Where(x => x.AppFuncID == row.PAppFuncID).FirstOrDefault(); // if (row == null) // { // break; // } // } // else // { // break; // } // } // if (row.PAppFuncID == null) // { // var check = c.FunctionPermision.Where(x => x.AppFuncID == row.AppFuncID).FirstOrDefault(); // if (check == null) // { // c.FunctionPermision.Add(row); // } // } //} //var parent = c.FunctionPermision.Where(x => x.PAppFuncID == null).ToList(); //foreach (var item in parent) //{ // Application application = new Application(); // application.AppFunctions = item.AppFunctions; // application.Badge = item.Badge; // application.IsLongTile = item.IsLongTile; // application.AppFuncID = item.AppFuncID; // application.IconPath = item.IconPath; // application.LandingPageURL = item.LandingPageURL; // application.PAppFuncID = item.PAppFuncID; // application.Idx = item.Idx; // application.AppTitle = item.AppTitle.Replace("|n|", ""); // application.AppDesc = item.AppDesc; // application.ColorSchema = item.ColorSchema; // application.NotDisplayed = item.NotDisplayed; // application.FuncType = item.FuncType; // var trs = new TreeViewObject() { application = application }; // buildTree(trs, c.FunctionPermision); // c.treeFunction.Add(trs); //} _cacheUser.Add(userName, c); } } }