|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Linq;
|
4 |
| -using System.Threading.Tasks; |
5 |
| -using Microsoft.AspNetCore.Authorization; |
6 | 4 | using Microsoft.AspNetCore.Mvc;
|
7 | 5 | using VirtoCommerce.Platform.Core.Modularity;
|
8 |
| -using VirtoCommerce.Platform.Security.Authorization; |
9 | 6 | using VirtoCommerce.Platform.Web.Model.Modularity;
|
10 | 7 |
|
11 | 8 |
|
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; |
50 | 10 |
|
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; |
60 | 15 |
|
61 |
| - } |
| 16 | + public AppsController(ILocalModuleCatalog localModuleCatalog) |
| 17 | + { |
| 18 | + _localModuleCatalog = localModuleCatalog ?? throw new ArgumentNullException(nameof(localModuleCatalog)); |
| 19 | + } |
62 | 20 |
|
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 |
66 | 36 | {
|
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 | + }); |
69 | 43 |
|
70 |
| - var result = await _authorizationService.AuthorizeAsync(User, null, |
71 |
| - new PermissionAuthorizationRequirement(permission)); |
| 44 | + return apps; |
72 | 45 |
|
73 |
| - return result.Succeeded; |
74 |
| - } |
75 | 46 | }
|
76 | 47 | }
|
0 commit comments