public bool Authorize(string userName, ExportDataQuery dataQuery) { var result = true; if (!_securityService.UserHasAnyPermission(userName, null, CatalogPredefinedPermissions.Read)) { // Get user 'read' permission scopes var readPermissionScopes = _securityService.GetUserPermissions(userName) .Where(x => x.Id.StartsWith(CatalogPredefinedPermissions.Read)) .SelectMany(x => x.AssignedScopes) .ToList(); if (dataQuery is ProductExportDataQuery productExportDataQuery) { productExportDataQuery.CatalogIds = ApplyScope <CatalogSelectedScope>(productExportDataQuery.CatalogIds, readPermissionScopes); productExportDataQuery.CategoryIds = ApplyScope <CatalogSelectedCategoryScope>(productExportDataQuery.CategoryIds, readPermissionScopes); } else if (dataQuery is CatalogFullExportDataQuery catalogFullExportDataQuery) { catalogFullExportDataQuery.CatalogIds = ApplyScope <CatalogSelectedScope>(catalogFullExportDataQuery.CatalogIds, readPermissionScopes); } } return(result); }
private ExportDataRequest CreatExportDataRequest(ExportDataQuery dataQuery, IExportProviderConfiguration providerConfig = null) { var result = new ExportDataRequest() { ProviderName = nameof(CsvExportProvider), DataQuery = dataQuery, ProviderConfig = providerConfig, }; return(result); }
public virtual IPagedDataSource Create(ExportDataQuery dataQuery) { IPagedDataSource result = null; if (dataQuery is CustomerReviewExportDataQuery customerReviewExportDataQuery) { result = new CustomerReviewExportPagedDataSource(_searchService, _customerReviewService, _itemService, _blobUrlResolver, customerReviewExportDataQuery); } return(result ?? throw new ArgumentException($"Unsupported export query type: {dataQuery.GetType().Name}")); }
public static void FilterProperties(this ExportDataQuery dataQuery, object obj, string baseMemberName = null) { var type = obj.GetType(); var includedProperties = dataQuery.IncludedProperties; if (!includedProperties.IsNullOrEmpty()) { foreach (var property in type.GetProperties().Where(x => x.CanRead && x.CanWrite)) { var propertyName = property.GetDerivedName(baseMemberName); var nestedType = property.PropertyType.GetNestedType(); if (nestedType.IsSubclassOf(typeof(Entity))) { if (!includedProperties.Any(x => x.FullName.StartsWith($"{propertyName}.", StringComparison.InvariantCultureIgnoreCase))) { property.SetValue(obj, null); } else { if (typeof(IEnumerable).IsAssignableFrom(property.PropertyType)) { var objectValues = property.GetValue(obj, null) as IEnumerable; if (objectValues != null) { foreach (var value in objectValues) { FilterProperties(dataQuery, value, propertyName); } } } else { var objectValue = property.GetValue(obj, null); if (objectValue != null) { FilterProperties(dataQuery, objectValue, propertyName); } } } } else if (!includedProperties.Any(x => x.FullName.Equals(propertyName, StringComparison.InvariantCultureIgnoreCase))) { property.SetValue(obj, null); } } } }
public virtual IPagedDataSource Create(ExportDataQuery dataQuery) { IPagedDataSource result = null; if (dataQuery is PriceExportDataQuery priceExportDataQuery) { result = new PriceExportPagedDataSource(_searchService, _pricingService, _itemService, priceExportDataQuery); } else if (dataQuery is PricelistAssignmentExportDataQuery pricelistAssignmentExportDataQuery) { result = new PricelistAssignmentExportPagedDataSource(_searchService, _pricingService, _catalogService, pricelistAssignmentExportDataQuery); } else if (dataQuery is PricelistExportDataQuery pricelistExportDataQuery) { result = new PricelistExportPagedDataSource(_searchService, _pricingService, pricelistExportDataQuery); } return(result ?? throw new ArgumentException($"Unsupported export query type: {dataQuery.GetType().Name}")); }
public virtual IPagedDataSource Create(ExportDataQuery dataQuery) { IPagedDataSource result = null; if (dataQuery is PropertyExportDataQuery propertyExportQuery) { result = new PropertyExportPagedDataSource(_propertyService, propertyExportQuery); } else if (dataQuery is PropertyDictionaryItemExportDataQuery propDictExportQuery) { result = new PropertyDictionaryItemExportPagedDataSource(_propertyDictionaryItemSearchService, propDictExportQuery); } else if (dataQuery is ProductFullExportDataQuery productFullExportQuery) { result = new ProductExportPagedDataSource(_blobStorageProvider, _itemService, _catalogSearchService, _blobUrlResolver, productFullExportQuery.ToProductExportDataQuery()); } else if (dataQuery is CategoryExportDataQuery categoryExportQuery) { result = new CategoryExportPagedDataSource(_catalogSearchService, _categoryService, _blobStorageProvider, categoryExportQuery); } else if (dataQuery is CatalogExportDataQuery catalogExportQuery) { result = new CatalogExportPagedDataSource(_catalogSearchService, catalogExportQuery); } else if (dataQuery is ProductExportDataQuery productExportQuery) { result = new ProductExportPagedDataSource(_blobStorageProvider, _itemService, _catalogSearchService, _blobUrlResolver, productExportQuery); } else if (dataQuery is CatalogFullExportDataQuery catalogFullExportDataQuery) { result = new CatalogFullExportPagedDataSource(this, catalogFullExportDataQuery); } if (result == null) { throw new ArgumentException($"Unsupported export query type: {dataQuery.GetType().Name}"); } return(result); }
public IPagedDataSource Create(ExportDataQuery dataQuery) { var priceExportDataQuery = dataQuery as PriceExportDataQuery ?? throw new InvalidCastException($"Cannot cast dataQuery to type {typeof(PriceExportDataQuery)}"); return(new PriceExportPagedDataSource(_searchService, _pricingService, _itemService, _blobUrlResolver, priceExportDataQuery)); }
public IPagedDataSource Create(ExportDataQuery dataQuery) { var pricelistAssignmentExportDataQuery = dataQuery as PricelistAssignmentExportDataQuery ?? throw new InvalidCastException($"Cannot cast dataQuery to type {typeof(PricelistAssignmentExportDataQuery)}"); return(new PricelistAssignmentExportPagedDataSource(_searchService, _pricingService, _catalogService, pricelistAssignmentExportDataQuery)); }