Hi
I can confirm the problem, we will fix it in the next patch version.
This is a temporary solution:
[Serializable]
[IgnoreMultiTenancy]
public class MyFileDownloadTokenCacheItem
{
public Guid FileDescriptorId { get; set; }
public Guid? TenantId { get; set; }
}
[RequiresFeature(FileManagementFeatures.Enable)]
[Authorize(FileManagementPermissions.FileDescriptor.Default)]
[ExposeServices(typeof(IFileDescriptorAppService))]
public class MyFileDescriptorAppService : FileDescriptorAppService
{
private IDistributedCache<MyFileDownloadTokenCacheItem, string> _tokenCache { get; set; }
public MyFileDescriptorAppService(IFileManager fileManager, IFileDescriptorRepository fileDescriptorRepository,
IBlobContainer<FileManagementContainer> blobContainer,
IDistributedCache<FileDownloadTokenCacheItem, string> downloadTokenCache,
IDistributedCache<MyFileDownloadTokenCacheItem, string> tokenCache) : base(fileManager,
fileDescriptorRepository, blobContainer, downloadTokenCache)
{
_tokenCache = tokenCache;
}
[AllowAnonymous]
public override async Task<IRemoteStreamContent> DownloadAsync(Guid id, string token)
{
var downloadToken = await _tokenCache.GetAsync(token);
if (downloadToken == null || downloadToken.FileDescriptorId != id)
{
throw new AbpAuthorizationException("Invalid download token: " + token);
}
using (CurrentTenant.Change(downloadToken.TenantId))
{
var fileDescriptor = await FileDescriptorRepository.GetAsync(id);
var stream = await BlobContainer.GetAsync(id.ToString());
return new RemoteStreamContent(stream, fileDescriptor?.Name);
}
}
public override async Task<DownloadTokenResultDto> GetDownloadTokenAsync(Guid id)
{
var token = Guid.NewGuid().ToString();
await _tokenCache.SetAsync(
token,
new MyFileDownloadTokenCacheItem()
{
FileDescriptorId = id,
TenantId = CurrentTenant.Id
},
new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(60)
});
return new DownloadTokenResultDto
{
Token = token
};
}
}
Hi,
The CMS kit module does not support such feature yet.
You can custom the module:
ObjectExtensionManager.Instance.Modules()
.ConfigureCmsKit(cmsKit =>
{
cmsKit.ConfigureMenuItem(menu =>
{
menu.AddOrUpdateProperty<string>( //property type: string
"PermissionName", //property name
property =>
{
}
);
});
});
public class MyCmsKitPublicMenuContributor : IMenuContributor
{
public async Task ConfigureMenuAsync(MenuConfigurationContext context)
{
if (context.Menu.Name == CmsKitMenus.Public)
{
await ConfigureMainMenuAsync(context);
}
}
private async Task ConfigureMainMenuAsync(MenuConfigurationContext context)
{
var featureChecker = context.ServiceProvider.GetRequiredService<IFeatureChecker>();
if (GlobalFeatureManager.Instance.IsEnabled<MenuFeature>() && await featureChecker.IsEnabledAsync(CmsKitFeatures.MenuEnable))
{
var menuAppService = context.ServiceProvider.GetRequiredService<IMenuItemPublicAppService>();
var permissionCheck = context.ServiceProvider.GetRequiredService<IPermissionChecker>();
var menuItems = await menuAppService.GetListAsync();
if (!menuItems.IsNullOrEmpty())
{
foreach (var menuItemDto in menuItems.Where(x => x.ParentId == null && x.IsActive))
{
var permissionName = menuItemDto.GetProperty<string>("PermissionName");
if (!permissionName.IsNullOrWhiteSpace() && !await permissionCheck.IsGrantedAsync(permissionName))
{
continue;
}
AddChildItems(menuItemDto, menuItems, context.Menu);
}
}
}
}
private void AddChildItems(MenuItemDto menuItem, List<MenuItemDto> source, IHasMenuItems parent = null)
{
var applicationMenuItem = CreateApplicationMenuItem(menuItem);
foreach (var item in source.Where(x => x.ParentId == menuItem.Id && x.IsActive))
{
AddChildItems(item, source, applicationMenuItem);
}
parent?.Items.Add(applicationMenuItem);
}
private ApplicationMenuItem CreateApplicationMenuItem(MenuItemDto menuItem)
{
return new ApplicationMenuItem(
menuItem.DisplayName,
menuItem.DisplayName,
menuItem.Url,
menuItem.Icon,
menuItem.Order,
menuItem.Target,
menuItem.ElementId,
menuItem.CssClass
);
}
}
Configure<AbpNavigationOptions>(options =>
{
options.MenuContributors.RemoveAll(x => x.GetType() == typeof(CmsKitPublicMenuContributor));
options.MenuContributors.Add(new MyCmsKitPublicMenuContributor());
});
We will fix it in the next patch version: https://github.com/abpframework/abp/issues/17866
Hi,
It looks like a problem. you can try:
public class MyCmsKitPublicMenuContributor : IMenuContributor
{
public async Task ConfigureMenuAsync(MenuConfigurationContext context)
{
if (context.Menu.Name == CmsKitMenus.Public)
{
await ConfigureMainMenuAsync(context);
}
}
private async Task ConfigureMainMenuAsync(MenuConfigurationContext context)
{
var featureCheck = context.ServiceProvider.GetRequiredService<IFeatureChecker>();
if (GlobalFeatureManager.Instance.IsEnabled<MenuFeature>() && await featureCheck.IsEnabledAsync(CmsKitFeatures.MenuEnable))
{
var menuAppService = context.ServiceProvider.GetRequiredService<IMenuItemPublicAppService>();
var menuItems = await menuAppService.GetListAsync();
if (!menuItems.IsNullOrEmpty())
{
foreach (var menuItemDto in menuItems.Where(x => x.ParentId == null && x.IsActive))
{
AddChildItems(menuItemDto, menuItems, context.Menu);
}
}
}
}
private void AddChildItems(MenuItemDto menuItem, List<MenuItemDto> source, IHasMenuItems parent = null)
{
var applicationMenuItem = CreateApplicationMenuItem(menuItem);
foreach (var item in source.Where(x => x.ParentId == menuItem.Id && x.IsActive))
{
AddChildItems(item, source, applicationMenuItem);
}
parent?.Items.Add(applicationMenuItem);
}
private ApplicationMenuItem CreateApplicationMenuItem(MenuItemDto menuItem)
{
return new ApplicationMenuItem(
menuItem.DisplayName,
menuItem.DisplayName,
menuItem.Url,
menuItem.Icon,
menuItem.Order,
menuItem.Target,
menuItem.ElementId,
menuItem.CssClass
);
}
}
Configure<AbpNavigationOptions>(options =>
{
options.MenuContributors.RemoveAll(x => x.GetType() == typeof(CmsKitPublicMenuContributor));
options.MenuContributors.Add(new MyCmsKitPublicMenuContributor());;
});
Hi,
Please make sure all ABP packages are 7.4.0 version.
And try abp clean & dotnet build again.
I didn't use this package in my application
This is the basic package of abp and is included in the template.
please close this. thanks
Hello, If you want, I can send you a sample app if you give me an email address ok here are the steps.
Yes, please. my emali is shiwei.liang@volosoft.com
Hi,
Could you use suite to create a new project to reproduce this problem and share it with me? shiwei.liang@volosoft.com I will check it.