/// <summary> /// The ChangePermissionsion /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="action">The <see cref="PermissionAction"/></param> /// <param name="grants">The <see cref="PermissionSet"/></param> /// <param name="resourceType">The <see cref="PermissionResourceType"/></param> /// <param name="resourceId">The <see cref="string"/></param> /// <param name="childType">The <see cref="PermissionResourceType"/></param> /// <param name="subjectType">The <see cref="PermissionSubjectType"/></param> /// <param name="subjectId">The <see cref="string"/></param> private static void ChangePermission(RestClient client, PermissionAction action, PermissionSet grants, PermissionResourceType resourceType, string resourceId, PermissionResourceType childType, PermissionSubjectType subjectType, string subjectId) { var uri = string.Format("/perms/{0}/{1}/{2}/{3}/{4}/{5}", action.ToString().ToLower(), resourceType.ToString().ToLower(), resourceId, childType == PermissionResourceType.none ? string.Empty : childType.ToString(), subjectType.ToString().ToLower(), subjectId ); var permsManage = PermissionsToList(grants.Manage); //.Where(o=>o == "R" ||o=="U" || o == "D"); var permsAuthorize = PermissionsToList(grants.Authorize); //.Where(o=>o =="R" || o == "U" || o == "D" || o == "A"); var permsCreatedManage = PermissionsToList(grants.CreatedDocument.Manage); //.Where(o => o == "R" || o == "U" || o == "D"); var permsCreatedAuthorize = PermissionsToList(grants.CreatedDocument.Authorize); // .Where(o => o == "R" || o == "U" || o == "D" || o == "A"); object grantBody = new { }; if (!permsCreatedManage.Any() && !permsCreatedAuthorize.Any()) { grantBody = new { manage = permsManage, authorize = permsAuthorize }; } else { var created = new { manage = permsCreatedManage, authorize = permsCreatedAuthorize, }; grantBody = new { manage = permsManage, authorize = permsAuthorize, created_document = created }; } uri = uri.Replace("//", "/"); var request = new RestRequest(uri, Method.POST); #if DEBUG var bodyTxt = JsonConvert.SerializeObject(grantBody); #endif Rest.Execute <BasicResponse>(client, request, grantBody); }
public bool permissionForBlogEditing(PermissionAction action, string id, bool autoThrow = false) { // Can do anything else to yourself if (CurrentUserSettings.userId == id) { return(true); } //Otherwise only these guys have permission to do anything else if (CurrentUserSettings.isAdmin) { return(true); } if (autoThrow) { throw new InvalidOperationException("User " + CurrentUserSettings.userName + " does not have permission to " + action.ToString()); } return(false); }
public string CreateClaimCode(PermissionItem item, PermissionAction action) { return($"{item.ToString()}.{action.ToString()}"); }
public static IList GetPermissionIdentifiersFromFunction(Type classType, PermissionAction action) { string cachedKey = string.Format("LISTIDENTIFIERSFromFunction_{0}_{1}_{2}", classType.Name.ToString(), action.ToString(), MembershipHelper.GetUser().UserId); object result = CacheManager.GetCached(cachedKey); if (result == null) { result = ControllerManager.EntityPermission.ListIdentifiersFromFunction(classType, MembershipHelper.GetUser().UserId, (PermissionAction)action); CacheManager.AddItem(cachedKey, result); } return((IList)result); }
public static IList GetPermissionIdentifiers(Type classType, PermissionAction action) { // Check if there are permissions for this object cached for this user. if (logger.IsDebugEnabled) { logger.DebugFormat("Finding entity permission list: {0} {1}", classType.Name, action); } string cachedKey = string.Format("LISTIDENTIFIERS_{0}_{1}_{2}", classType.Name.ToString(), action.ToString(), MembershipHelper.GetUser().UserId); object result = CacheManager.GetCached(cachedKey); if (result == null) { result = ControllerManager.EntityPermission.ListIdentifiers(classType, MembershipHelper.GetUser().UserId, (PermissionAction)action); CacheManager.AddItem(cachedKey, result); } return((IList)result); }