Skip to content

Commit

Permalink
VCST-1392: App with Permission Not Displayed in App List After Sign-In (
Browse files Browse the repository at this point in the history
#2808)

fix: App with Permission Not Displayed in App List After Sign-In.
  • Loading branch information
OlegoO committed Jun 13, 2024
1 parent 373fdf9 commit 598d47b
Showing 1 changed file with 31 additions and 60 deletions.
91 changes: 31 additions & 60 deletions src/VirtoCommerce.Platform.Web/Controllers/Api/AppsController.cs
Original file line number Diff line number Diff line change
@@ -1,76 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using VirtoCommerce.Platform.Core.Modularity;
using VirtoCommerce.Platform.Security.Authorization;
using VirtoCommerce.Platform.Web.Model.Modularity;


namespace VirtoCommerce.Platform.Web.Controllers.Api
{
[Route("api/platform/apps")]
public class AppsController : Controller
{
private readonly ILocalModuleCatalog _localModuleCatalog;
private readonly IAuthorizationService _authorizationService;

public AppsController(ILocalModuleCatalog localModuleCatalog, IAuthorizationService authorizationService)
{
_localModuleCatalog = localModuleCatalog ?? throw new ArgumentNullException(nameof(localModuleCatalog));
_authorizationService = authorizationService ?? throw new ArgumentNullException(nameof(authorizationService));
}

/// <summary>
/// Gets the list of available apps, filtered by user permissions.
/// </summary>
/// <returns>The list of available apps</returns>
[HttpGet]
public async Task<ActionResult<IEnumerable<AppDescriptor>>> GetApps()
{

var authorizedApps = new List<AppDescriptor>
{
// Add Commerce Manager by Default
new AppDescriptor
{
Id = "platform",
Title = "Commerce Manager",
Description = "Virto Commerce Platform",
RelativeUrl = "/",
IconUrl = "/images/platform_app.svg"
}
};

var applicationList = _localModuleCatalog.Modules.OfType<ManifestModuleInfo>()
.SelectMany(x => x.Apps)
.OrderBy(x => x.Title);
namespace VirtoCommerce.Platform.Web.Controllers.Api;

foreach (var moduleAppInfo in applicationList)
{
if (await AuthorizeAppAsync(moduleAppInfo.Permission))
{
authorizedApps.Add(new AppDescriptor(moduleAppInfo));
}
}

return authorizedApps;
[Route("api/platform/apps")]
public class AppsController : Controller
{
private readonly ILocalModuleCatalog _localModuleCatalog;

}
public AppsController(ILocalModuleCatalog localModuleCatalog)
{
_localModuleCatalog = localModuleCatalog ?? throw new ArgumentNullException(nameof(localModuleCatalog));
}

private async Task<bool> AuthorizeAppAsync(string permission)
{
if (string.IsNullOrEmpty(permission))
/// <summary>
/// Gets the list of available apps, filtered by user permissions.
/// </summary>
/// <returns>The list of available apps</returns>
[HttpGet]
public IEnumerable<AppDescriptor> GetApps()
{
var apps = _localModuleCatalog.Modules.OfType<ManifestModuleInfo>()
.SelectMany(x => x.Apps)
.Select(x => new AppDescriptor(x))
.OrderBy(x => x.Title)
.ToList();

apps.Insert(0, // Add Commerce Manager by Default
new AppDescriptor
{
return true;
}
Id = "platform",
Title = "Commerce Manager",
Description = "Virto Commerce Platform",
RelativeUrl = "/",
IconUrl = "/images/platform_app.svg"
});

var result = await _authorizationService.AuthorizeAsync(User, null,
new PermissionAuthorizationRequirement(permission));
return apps;

return result.Succeeded;
}
}
}

0 comments on commit 598d47b

Please sign in to comment.