Skip to content

Commit 67873f9

Browse files
basilkotartem-dudarevMaria-Volkova-Tula
authored
VCST-2990: Add developer tools (#2905)
Co-authored-by: Artem Dudarev <artem@virtoworks.com> Co-authored-by: Maria Volkova <106367190+Maria-Volkova-Tula@users.noreply.github.com>
1 parent 177cc08 commit 67873f9

25 files changed

+321
-6
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace VirtoCommerce.Platform.Core.DeveloperTools;
2+
3+
public class DeveloperToolDescriptor
4+
{
5+
public string Name { get; set; }
6+
public string Url { get; set; }
7+
public bool IsExternal { get; set; }
8+
public int SortOrder { get; set; }
9+
public string Permission { get; set; }
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections.Generic;
2+
using System.Security.Claims;
3+
4+
namespace VirtoCommerce.Platform.Core.DeveloperTools;
5+
6+
public interface IDeveloperToolRegistrar
7+
{
8+
void RegisterDeveloperTool(DeveloperToolDescriptor tool);
9+
IList<DeveloperToolDescriptor> GetRegisteredTools(ClaimsPrincipal claimsPrincipal);
10+
}

src/VirtoCommerce.Platform.Core/PlatformConstants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public static class Permissions
6363
public const string SettingAccess = "platform:setting:access";
6464
public const string SettingUpdate = "platform:setting:update";
6565

66+
public const string DeveloperToolsAccess = "platform:developer-tools:access";
67+
6668
public const string DynamicPropertiesQuery = "platform:dynamic_properties:read";
6769
public const string DynamicPropertiesCreate = "platform:dynamic_properties:create";
6870
public const string DynamicPropertiesAccess = "platform:dynamic_properties:access";
@@ -96,6 +98,7 @@ public static class Permissions
9698
AssetAccess, AssetDelete, AssetUpdate, AssetCreate, AssetRead,
9799
ModuleQuery, ModuleAccess, ModuleManage,
98100
SettingQuery, SettingAccess, SettingUpdate,
101+
DeveloperToolsAccess,
99102
DynamicPropertiesQuery, DynamicPropertiesCreate, DynamicPropertiesAccess, DynamicPropertiesUpdate, DynamicPropertiesDelete,
100103
SecurityQuery, SecurityCreate, SecurityAccess, SecurityUpdate, SecurityDelete,
101104
SecurityLoginOnBehalf, SecurityVerifyEmail, SecurityConfirmEmail, SecurityGenerateToken, SecurityVerifyToken,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Security.Claims;
5+
using VirtoCommerce.Platform.Core;
6+
using VirtoCommerce.Platform.Core.DeveloperTools;
7+
using static VirtoCommerce.Platform.Core.PlatformConstants.Security.Claims;
8+
9+
namespace VirtoCommerce.Platform.Data.DeveloperTools;
10+
11+
public class DeveloperToolRegistrar : IDeveloperToolRegistrar
12+
{
13+
private readonly List<DeveloperToolDescriptor> _tools = [];
14+
15+
public void RegisterDeveloperTool(DeveloperToolDescriptor tool)
16+
{
17+
ArgumentNullException.ThrowIfNull(tool);
18+
_tools.Add(tool);
19+
}
20+
21+
public IList<DeveloperToolDescriptor> GetRegisteredTools(ClaimsPrincipal claimsPrincipal)
22+
{
23+
var isAdmin = claimsPrincipal != null && claimsPrincipal.IsInRole(PlatformConstants.Security.SystemRoles.Administrator);
24+
25+
return _tools
26+
.Where(x =>
27+
isAdmin ||
28+
string.IsNullOrEmpty(x.Permission) ||
29+
claimsPrincipal != null && claimsPrincipal.HasClaim(PermissionClaimType, x.Permission))
30+
.OrderBy(x => x.SortOrder)
31+
.ToList();
32+
}
33+
}

src/VirtoCommerce.Platform.Hangfire/Extensions/ApplicationBuilderExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
using Microsoft.Extensions.Configuration;
99
using Microsoft.Extensions.DependencyInjection;
1010
using Microsoft.Extensions.Options;
11+
using VirtoCommerce.Platform.Core;
12+
using VirtoCommerce.Platform.Core.DeveloperTools;
1113
using VirtoCommerce.Platform.Core.Events;
1214
using VirtoCommerce.Platform.Core.Security;
15+
using VirtoCommerce.Platform.Core.Settings;
1316
using VirtoCommerce.Platform.Core.Settings.Events;
1417
using VirtoCommerce.Platform.Hangfire.Middleware;
1518

@@ -67,6 +70,15 @@ public static IApplicationBuilder UseHangfire(this IApplicationBuilder appBuilde
6770
var userNameResolver = appBuilder.ApplicationServices.CreateScope().ServiceProvider.GetRequiredService<IUserNameResolver>();
6871
GlobalJobFilters.Filters.Add(new HangfireUserContextMiddleware(userNameResolver));
6972

73+
var toolRegistrar = appBuilder.ApplicationServices.GetService<IDeveloperToolRegistrar>();
74+
toolRegistrar.RegisterDeveloperTool(new DeveloperToolDescriptor
75+
{
76+
Name = "Hangfire",
77+
Url = "/hangfire",
78+
SortOrder = 20,
79+
Permission = PlatformConstants.Security.Permissions.BackgroundJobsManage,
80+
});
81+
7082
return appBuilder;
7183
}
7284
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
3+
using VirtoCommerce.Platform.Core.DeveloperTools;
4+
using Permissions = VirtoCommerce.Platform.Core.PlatformConstants.Security.Permissions;
5+
6+
namespace VirtoCommerce.Platform.Web.Controllers.Api;
7+
8+
[Authorize]
9+
[Route("/api/platform/developer-tools")]
10+
public class DeveloperToolsController(IDeveloperToolRegistrar developerToolRegistrar) : Controller
11+
{
12+
[HttpGet]
13+
[Authorize(Permissions.DeveloperToolsAccess)]
14+
public ActionResult<DeveloperToolDescriptor[]> GetDeveloperTools()
15+
{
16+
return Ok(developerToolRegistrar.GetRegisteredTools(User));
17+
}
18+
}

src/VirtoCommerce.Platform.Web/Startup.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
using Serilog;
3737
using VirtoCommerce.Platform.Core;
3838
using VirtoCommerce.Platform.Core.Common;
39+
using VirtoCommerce.Platform.Core.DeveloperTools;
3940
using VirtoCommerce.Platform.Core.DynamicProperties;
4041
using VirtoCommerce.Platform.Core.JsonConverters;
4142
using VirtoCommerce.Platform.Core.Localizations;
@@ -44,6 +45,7 @@
4445
using VirtoCommerce.Platform.Core.Security;
4546
using VirtoCommerce.Platform.Core.Security.ExternalSignIn;
4647
using VirtoCommerce.Platform.Core.Settings;
48+
using VirtoCommerce.Platform.Data.DeveloperTools;
4749
using VirtoCommerce.Platform.Data.Extensions;
4850
using VirtoCommerce.Platform.Data.MySql;
4951
using VirtoCommerce.Platform.Data.MySql.Extensions;
@@ -79,7 +81,6 @@
7981
using JsonSerializer = Newtonsoft.Json.JsonSerializer;
8082
using MsTokens = Microsoft.IdentityModel.Tokens;
8183

82-
8384
namespace VirtoCommerce.Platform.Web
8485
{
8586
public class Startup
@@ -485,6 +486,8 @@ public void ConfigureServices(IServiceCollection services)
485486
//Platform authorization handler for policies based on permissions
486487
services.AddSingleton<IAuthorizationHandler, DefaultPermissionAuthorizationHandler>();
487488

489+
services.AddSingleton<IDeveloperToolRegistrar, DeveloperToolRegistrar>();
490+
488491
services.AddTransient<IExternalSignInService, ExternalSignInService>();
489492
services.AddTransient<IExternalSigninService, ExternalSignInService>();
490493

@@ -699,6 +702,14 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<
699702

700703
app.UseEndpoints(SetupEndpoints);
701704

705+
var toolRegistrar = app.ApplicationServices.GetService<IDeveloperToolRegistrar>();
706+
toolRegistrar.RegisterDeveloperTool(new DeveloperToolDescriptor
707+
{
708+
Name = "Health",
709+
Url = "/health",
710+
SortOrder = 10,
711+
});
712+
702713
// Enable middleware to serve generated Swagger as a JSON endpoint.
703714
app.UseSwagger();
704715

src/VirtoCommerce.Platform.Web/Swagger/SwaggerServiceCollectionExtensions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Swashbuckle.AspNetCore.SwaggerGen;
1515
using Swashbuckle.AspNetCore.SwaggerUI;
1616
using VirtoCommerce.Platform.Core.Common;
17+
using VirtoCommerce.Platform.Core.DeveloperTools;
1718
using VirtoCommerce.Platform.Core.Modularity;
1819
using VirtoCommerce.Platform.Core.Swagger;
1920

@@ -194,6 +195,14 @@ public static void UseSwagger(this IApplicationBuilder applicationBuilder)
194195
c.DocExpansion(DocExpansion.None);
195196
c.DefaultModelsExpandDepth(-1);
196197
});
198+
199+
var toolRegistrar = applicationBuilder.ApplicationServices.GetService<IDeveloperToolRegistrar>();
200+
toolRegistrar.RegisterDeveloperTool(new()
201+
{
202+
Name = "Swagger",
203+
Url = "/docs/index.html",
204+
SortOrder = 30,
205+
});
197206
}
198207

199208

src/VirtoCommerce.Platform.Web/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218
// X-Frame-Options header configuration. Allowed values: Deny - default, SameOrigin, or custom uri.
219219
"FrameOptions": "Deny",
220220
// FrameAncestors configuration in Content-Security-Header header. Allowed values: None - default, Self, or custom uri.
221-
"FrameAncestors": "None"
221+
"FrameAncestors": "Self"
222222
},
223223
"AzureAd": {
224224
"Enabled": false,

src/VirtoCommerce.Platform.Web/wwwroot/Localizations/de.VirtoCommerce.Platform.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
"user-profile": "Benutzerprofil",
1515
"assets": "Ressourcen",
1616
"toggle-favorites": "Umschalt + Leertaste zum Umschalten der Favoriten",
17+
"developer-tools": "Entwicklerwerkzeuge",
1718
"help": "Hilfe"
1819
},
1920
"navigation": {
2021
"back": "Zurück"
2122
},
2223
"blades": {
24+
"developer-tools": {
25+
"title": "Entwicklerwerkzeuge"
26+
},
2327
"system-info": {
2428
"title": "Plattforminformationen",
2529
"labels": {

src/VirtoCommerce.Platform.Web/wwwroot/Localizations/en.VirtoCommerce.Platform.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
"user-profile": "User profile",
1515
"assets": "Assets",
1616
"toggle-favorites": "Shift + Space to toggle favorites",
17+
"developer-tools": "Developer tools",
1718
"help": "Help"
1819
},
1920
"navigation": {
2021
"back": "Back"
2122
},
2223
"blades": {
24+
"developer-tools": {
25+
"title": "Developer tools"
26+
},
2327
"system-info": {
2428
"title": "Platform information",
2529
"labels": {

src/VirtoCommerce.Platform.Web/wwwroot/Localizations/es.VirtoCommerce.Platform.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
"user-profile": "Perfil de usuario",
1515
"assets": "Recursos",
1616
"toggle-favorites": "Shift + Espacio para alternar favoritos",
17+
"developer-tools": "Herramientas para desarrolladores",
1718
"help": "Ayuda"
1819
},
1920
"navigation": {
2021
"back": "Atrás"
2122
},
2223
"blades": {
24+
"developer-tools": {
25+
"title": "Herramientas para desarrolladores"
26+
},
2327
"system-info": {
2428
"title": "Información de la plataforma",
2529
"labels": {

src/VirtoCommerce.Platform.Web/wwwroot/Localizations/fr.VirtoCommerce.Platform.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
"user-profile": "Profil utilisateur",
1515
"assets": "Ressources",
1616
"toggle-favorites": "Maj + Espace pour basculer les favoris",
17+
"developer-tools": "Outils développeur",
1718
"help": "Aide"
1819
},
1920
"navigation": {
2021
"back": "Retour"
2122
},
2223
"blades": {
24+
"developer-tools": {
25+
"title": "Outils développeur"
26+
},
2327
"system-info": {
2428
"title": "Informations sur la plateforme",
2529
"labels": {

src/VirtoCommerce.Platform.Web/wwwroot/Localizations/it.VirtoCommerce.Platform.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
"user-profile": "Profilo utente",
1515
"assets": "Risorse",
1616
"toggle-favorites": "Shift + Spazio per attivare/disattivare i preferiti",
17+
"developer-tools": "Strumenti per sviluppatori",
1718
"help": "Aiuto"
1819
},
1920
"navigation": {
2021
"back": "Indietro"
2122
},
2223
"blades": {
24+
"developer-tools": {
25+
"title": "Strumenti per sviluppatori"
26+
},
2327
"system-info": {
2428
"title": "Informazioni sulla piattaforma",
2529
"labels": {

src/VirtoCommerce.Platform.Web/wwwroot/Localizations/ja.VirtoCommerce.Platform.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
"user-profile": "ユーザープロフィール",
1515
"assets": "リソース",
1616
"toggle-favorites": "Shift + スペースでお気に入りを切り替え",
17+
"developer-tools": "開発者ツール",
1718
"help": "ヘルプ"
1819
},
1920
"navigation": {
2021
"back": "戻る"
2122
},
2223
"blades": {
24+
"developer-tools": {
25+
"title": "開発者ツール"
26+
},
2327
"system-info": {
2428
"title": "プラットフォーム情報",
2529
"labels": {

src/VirtoCommerce.Platform.Web/wwwroot/Localizations/pl.VirtoCommerce.Platform.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
"user-profile": "Profil użytkownika",
1515
"assets": "Zasoby",
1616
"toggle-favorites": "Shift + Spacja, aby przełączyć ulubione",
17+
"developer-tools": "Narzędzia deweloperskie",
1718
"help": "Pomoc"
1819
},
1920
"navigation": {
2021
"back": "Wstecz"
2122
},
2223
"blades": {
24+
"developer-tools": {
25+
"title": "Narzędzia deweloperskie"
26+
},
2327
"system-info": {
2428
"title": "Informacje o platformie",
2529
"labels": {

src/VirtoCommerce.Platform.Web/wwwroot/Localizations/pt.VirtoCommerce.Platform.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
"user-profile": "Perfil do usuário",
1515
"assets": "Recursos",
1616
"toggle-favorites": "Shift + Espaço para alternar favoritos",
17+
"developer-tools": "Ferramentas de desenvolvedor",
1718
"help": "Ajuda"
1819
},
1920
"navigation": {
2021
"back": "Voltar"
2122
},
2223
"blades": {
24+
"developer-tools": {
25+
"title": "Ferramentas de desenvolvedor"
26+
},
2327
"system-info": {
2428
"title": "Informações da plataforma",
2529
"labels": {

src/VirtoCommerce.Platform.Web/wwwroot/Localizations/ru.VirtoCommerce.Platform.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
"user-profile": "Профиль пользователя",
1515
"assets": "Ресурсы",
1616
"toggle-favorites": "Shift + Пробел для переключения избранного",
17+
"developer-tools": "Инструменты разработчика",
1718
"help": "Помощь"
1819
},
1920
"navigation": {
2021
"back": "Назад"
2122
},
2223
"blades": {
24+
"developer-tools": {
25+
"title": "Инструменты разработчика"
26+
},
2327
"system-info": {
2428
"title": "Информация о платформе",
2529
"labels": {

src/VirtoCommerce.Platform.Web/wwwroot/Localizations/zh.VirtoCommerce.Platform.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
"user-profile": "用户资料",
1515
"assets": "资源",
1616
"toggle-favorites": "按 Shift + 空格键切换收藏夹",
17+
"developer-tools": "开发者工具",
1718
"help": "帮助"
1819
},
1920
"navigation": {
2021
"back": "返回"
2122
},
2223
"blades": {
24+
"developer-tools": {
25+
"title": "开发者工具"
26+
},
2327
"system-info": {
2428
"title": "平台信息",
2529
"labels": {

0 commit comments

Comments
 (0)