private Dictionary <P, long> GetCategoryAcl(P permission, K?categoryKey) { var acl = UserAcl(); var cat = PermissionCoordinator.GetPermissionCategory(permission); // In some senarios, we haven't set the categorykey yet. so we shouldn't get exception! // if (cat != null && categoryKey == null) // throw new Exception("The requested permission object[" + typeof(P).ToString() + "] has category[" + cat.Value.ToString() + "], but you passed a null categoryKey! This permission is only valid within an instance of a category."); // In some senarios, we pass the categoryKey always (by controller) but it shouldn't be used for permissions with no category. so we comment it and make the related key. //if (cat == null && categoryKey != null)//TODO : we can bypass this instead of exception throwing... // throw new Exception("The requested permission object[" + typeof(P).ToString() + "] has no any category, but you passed categoryKey[" + categoryKey.ToString() + "]!"); if (cat == null) { categoryKey = null; //In some senarios, we pass the categoryKey always (by controller) but it shouldn't be used for permissions with no category. } var key = new UserAclKey <C, K>(cat, categoryKey); if (acl.ContainsKey(key)) { return(acl[key]); } return(null);//مثلا زمانیکه در رسته استان تهران کلا دسترسی ای برای ایشان تعریف نشده است }
protected internal override object GetPermissionCategoryKey(long permissionObject, IEnumerable <long> permissions, object entityKey, string entityKeyParameterName) { object obj = permissionObject; var cat = PermissionCoordinator.GetPermissionCategory((P)obj); return(GetPermissionCategoryKey(cat)); }
public bool?HasPermission(P permissionObject, long requestedPermissions /*NOTE:this parameter can be cumulative*/, PermissionLimiterBase permissionLimiter, K?categoryKey = null) { if (!HttpContext.Current.User.Identity.IsAuthenticated) { return(false); } if (categoryKey == null) { categoryKey = GetPermissionCategoryKey(PermissionCoordinator.GetPermissionCategory(permissionObject)); } return(UserPermissionHelper.HasPermission(permissionObject, requestedPermissions, permissionLimiter, categoryKey)); }
/// <summary> /// از ارسال اجازه های ترکیبی به این پارامتر خودداری شود /// </summary> /// <typeparam name="T"></typeparam> /// <param name="permissions"></param> /// <returns></returns> public bool HasFullPermissionOf <T>(T permissions, K?categoryKey = null) where T : struct { if (!HttpContext.Current.User.Identity.IsAuthenticated) { return(false); } if (categoryKey == null) { categoryKey = GetPermissionCategoryKey(PermissionCoordinator.GetPermissionCategory(PermissionCoordinator.GetRelatedPermissionItem(typeof(T)))); } return(UserPermissionHelper.HasFullPermissionOf <T>(permissions, categoryKey)); }
/// <summary> /// مقدار بازگشتی نال به معنی این است که بر روی همه موجودیت ها اجازه دارد. این موضوع تنها برای مدیر ارشد معنا دارد /// برای سایرین لیست خالی یا لیست با مقدار بازگردانده می شود /// </summary> /// <typeparam name="T"></typeparam> /// <param name="permissions"></param> /// <returns></returns> public List <K?> GetAllowedObjects <T>(T permissions) where T : struct { if (IsEnterpriseAdmin != null && IsEnterpriseAdmin()) { return(null); } var entityItem = PermissionCoordinator.GetRelatedPermissionItem(typeof(T)); var acls = UserAcl(); var cat = PermissionCoordinator.GetPermissionCategory(entityItem); var lst = new List <K?>(); foreach (var aclItem in acls) { if (aclItem.Key.Category.Equals(cat)) { if (HasPermissionInAcl(entityItem, Convert.ToInt64(permissions), null, aclItem.Value) == true) { lst.Add(aclItem.Key.CategoryKey); } } } return(lst); }