private static ApiPermissionType ConvertTo(ApiPermissionTypeInternal permInternal) { ApiPermissionType wrapper = new ApiPermissionType(); wrapper.HttpVerb = permInternal.HttpVerb; // wrapper.DelegatedWork = permInternal.DelegatedWork.Where(d => d.Trim() != "Not supported.").Select(d => new PermissionScopeType { ScopeName = d.Trim() }).ToList(); // wrapper.DelegatedPersonal = permInternal.DelegatedPersonal.Where(d => d.Trim() != "Not supported.").Select(d => new PermissionScopeType { ScopeName = d.Trim() }).ToList(); // wrapper.Application = permInternal.Application.Where(d => d.Trim() != "Not supported.").Select(d => new PermissionScopeType { ScopeName = d.Trim() }).ToList(); return(wrapper); }
private static void MergePermissions(IList <ApiPermissionType> source, IList <ApiPermissionType> newPermissions) { foreach (var permType in newPermissions) { ApiPermissionType sameHttpVerbPermission = source.FirstOrDefault(s => s.HttpVerb == permType.HttpVerb); if (sameHttpVerbPermission != null) { sameHttpVerbPermission.DelegatedWork = sameHttpVerbPermission.DelegatedWork.Union(permType.DelegatedWork).ToList(); sameHttpVerbPermission.DelegatedPersonal = sameHttpVerbPermission.DelegatedPersonal.Union(permType.DelegatedPersonal).ToList(); sameHttpVerbPermission.Application = sameHttpVerbPermission.Application.Union(permType.Application).ToList(); } else { source.Add(permType); } } }
private void AppendTheRestrictedProperty(ApiPermissionType append, ApiPermissionType loopUp, string propertyName) { foreach (var scope in append.DelegatedWork) { if (!loopUp.DelegatedWork.Any(a => a == scope)) { HashSet <string> restricted; if (!append.DelegatedWorkRestrictedProperties.TryGetValue(scope, out restricted)) { restricted = new HashSet <string>(); append.DelegatedWorkRestrictedProperties[scope] = restricted; } restricted.Add(propertyName); } } foreach (var scope in append.DelegatedPersonal) { if (!loopUp.DelegatedPersonal.Any(a => a == scope)) { HashSet <string> restricted; if (!append.DelegatedPersonalRestrictedProperties.TryGetValue(scope, out restricted)) { restricted = new HashSet <string>(); append.DelegatedPersonalRestrictedProperties[scope] = restricted; } restricted.Add(propertyName); } } foreach (var scope in append.Application) { if (!loopUp.Application.Any(a => a == scope)) { HashSet <string> restricted; if (!append.ApplicationRestrictedProperties.TryGetValue(scope, out restricted)) { restricted = new HashSet <string>(); append.ApplicationRestrictedProperties[scope] = restricted; } restricted.Add(propertyName); } } }
private static IDictionary <string, IList <ApiPermissionType> > LoadPermissions(JObject topLevelObject) { IDictionary <string, IList <ApiPermissionType> > returns = new Dictionary <string, IList <ApiPermissionType> >(); foreach (var uriProperty in topLevelObject.Properties()) { JArray uriPermissions = uriProperty.Value as JArray; if (uriPermissions == null) { throw new Exception($"Invalid format, Need a JSON array at '{uriProperty.Name}'."); } IList <ApiPermissionType> permissions = new List <ApiPermissionType>(); foreach (var uriPermission in uriPermissions) { JObject uriPermissionObj = uriPermission as JObject; if (uriPermissionObj == null) { throw new Exception($"Invalid format, Need a JSON object within '{uriProperty.Name}'."); } ApiPermissionType permission = new ApiPermissionType(); // HttpVerb JProperty httpVerbProperty = uriPermissionObj.Property("HttpVerb"); if (httpVerbProperty != null) { permission.HttpVerb = httpVerbProperty.Value.ToString(); } // DelegatedWork JProperty delegatedWorkProperty = uriPermissionObj.Property("DelegatedWork"); if (delegatedWorkProperty != null) { JArray delegatedWork = delegatedWorkProperty.Value as JArray; if (delegatedWork != null) { permission.DelegatedWork = delegatedWork.ToObject <List <string> >(); } } // DelegatedPersonal JProperty delegatedPersonalProperty = uriPermissionObj.Property("DelegatedPersonal"); if (delegatedPersonalProperty != null) { JArray delegatedPersonal = delegatedPersonalProperty.Value as JArray; if (delegatedPersonal != null) { permission.DelegatedPersonal = delegatedPersonal.ToObject <List <string> >(); } } // Application JProperty applicationProperty = uriPermissionObj.Property("Application"); if (applicationProperty != null) { JArray application = applicationProperty.Value as JArray; if (application != null) { permission.Application = application.ToObject <List <string> >(); } } permissions.Add(permission); } returns[uriProperty.Name] = permissions; } return(returns); }