/// <summary> /// Checks collections for sufficient permissions. /// </summary> /// <param name="dataApiClient">DataAPI client</param> /// <param name="requiredCollectionPermissions">Map of required permissions. Data type as key, list of permissions as value.</param> /// <returns> /// Result containing boolean indicating sufficient permissions and, /// if false, the first collection with insufficient permissions, the actual roles and the required roles. /// </returns> public static async Task <DataPermissionCheckerResult> Check( IDataApiClient dataApiClient, Dictionary <string, IList <Role> > requiredCollectionPermissions) { foreach (var kvp in requiredCollectionPermissions) { var collectionName = kvp.Key; var requiredPermissions = kvp.Value; try { var collectionInfomration = await dataApiClient.GetCollectionInformationAsync(collectionName); if (!HashSufficientPermissions(collectionInfomration.UserRoles, requiredPermissions)) { return(DataPermissionCheckerResult.Fail(collectionName, collectionInfomration.UserRoles, requiredPermissions)); } } catch (ApiException apiException) { if (apiException.StatusCode == HttpStatusCode.Unauthorized) { return(DataPermissionCheckerResult.Fail(collectionName, new Role[] {}, requiredPermissions)); } throw; } } return(DataPermissionCheckerResult.Pass()); }