Skip to content

Commit 0813434

Browse files
committed
VCST-1392: App with Permission Not Displayed in App List After Sign-In (#2808)
fix: App with Permission Not Displayed in App List After Sign-In.
1 parent 84c3b01 commit 0813434

File tree

1 file changed

+31
-60
lines changed

1 file changed

+31
-60
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,47 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Authorization;
64
using Microsoft.AspNetCore.Mvc;
75
using VirtoCommerce.Platform.Core.Modularity;
8-
using VirtoCommerce.Platform.Security.Authorization;
96
using VirtoCommerce.Platform.Web.Model.Modularity;
107

118

12-
namespace VirtoCommerce.Platform.Web.Controllers.Api
13-
{
14-
[Route("api/platform/apps")]
15-
public class AppsController : Controller
16-
{
17-
private readonly ILocalModuleCatalog _localModuleCatalog;
18-
private readonly IAuthorizationService _authorizationService;
19-
20-
public AppsController(ILocalModuleCatalog localModuleCatalog, IAuthorizationService authorizationService)
21-
{
22-
_localModuleCatalog = localModuleCatalog ?? throw new ArgumentNullException(nameof(localModuleCatalog));
23-
_authorizationService = authorizationService ?? throw new ArgumentNullException(nameof(authorizationService));
24-
}
25-
26-
/// <summary>
27-
/// Gets the list of available apps, filtered by user permissions.
28-
/// </summary>
29-
/// <returns>The list of available apps</returns>
30-
[HttpGet]
31-
public async Task<ActionResult<IEnumerable<AppDescriptor>>> GetApps()
32-
{
33-
34-
var authorizedApps = new List<AppDescriptor>
35-
{
36-
// Add Commerce Manager by Default
37-
new AppDescriptor
38-
{
39-
Id = "platform",
40-
Title = "Commerce Manager",
41-
Description = "Virto Commerce Platform",
42-
RelativeUrl = "/",
43-
IconUrl = "/images/platform_app.svg"
44-
}
45-
};
46-
47-
var applicationList = _localModuleCatalog.Modules.OfType<ManifestModuleInfo>()
48-
.SelectMany(x => x.Apps)
49-
.OrderBy(x => x.Title);
9+
namespace VirtoCommerce.Platform.Web.Controllers.Api;
5010

51-
foreach (var moduleAppInfo in applicationList)
52-
{
53-
if (await AuthorizeAppAsync(moduleAppInfo.Permission))
54-
{
55-
authorizedApps.Add(new AppDescriptor(moduleAppInfo));
56-
}
57-
}
58-
59-
return authorizedApps;
11+
[Route("api/platform/apps")]
12+
public class AppsController : Controller
13+
{
14+
private readonly ILocalModuleCatalog _localModuleCatalog;
6015

61-
}
16+
public AppsController(ILocalModuleCatalog localModuleCatalog)
17+
{
18+
_localModuleCatalog = localModuleCatalog ?? throw new ArgumentNullException(nameof(localModuleCatalog));
19+
}
6220

63-
private async Task<bool> AuthorizeAppAsync(string permission)
64-
{
65-
if (string.IsNullOrEmpty(permission))
21+
/// <summary>
22+
/// Gets the list of available apps, filtered by user permissions.
23+
/// </summary>
24+
/// <returns>The list of available apps</returns>
25+
[HttpGet]
26+
public IEnumerable<AppDescriptor> GetApps()
27+
{
28+
var apps = _localModuleCatalog.Modules.OfType<ManifestModuleInfo>()
29+
.SelectMany(x => x.Apps)
30+
.Select(x => new AppDescriptor(x))
31+
.OrderBy(x => x.Title)
32+
.ToList();
33+
34+
apps.Insert(0, // Add Commerce Manager by Default
35+
new AppDescriptor
6636
{
67-
return true;
68-
}
37+
Id = "platform",
38+
Title = "Commerce Manager",
39+
Description = "Virto Commerce Platform",
40+
RelativeUrl = "/",
41+
IconUrl = "/images/platform_app.svg"
42+
});
6943

70-
var result = await _authorizationService.AuthorizeAsync(User, null,
71-
new PermissionAuthorizationRequirement(permission));
44+
return apps;
7245

73-
return result.Succeeded;
74-
}
7546
}
7647
}

0 commit comments

Comments
 (0)