-
-
Notifications
You must be signed in to change notification settings - Fork 752
Expand file tree
/
Copy pathNavMenu.razor
More file actions
127 lines (120 loc) · 5.58 KB
/
NavMenu.razor
File metadata and controls
127 lines (120 loc) · 5.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
@inject Microsoft.Extensions.Localization.IStringLocalizer<NavMenu> _localizer
@using System.Security.Claims
@using BlazorHero.CleanArchitecture.Shared.Constants.Storage
<UserCard />
<MudNavMenu>
<MudNavLink Href="/" Match="NavLinkMatch.All" Icon="@Icons.Material.Outlined.Home">@_localizer["Home"]</MudNavLink>
@if (_canViewHangfire)
{
<MudNavLink Href="@_jobsLink" Target="_blank" Icon="@Icons.Material.Outlined.Work">
@_localizer["Hangfire"]
</MudNavLink>
}
<MudNavLink Href="https://codewithmukesh.com/blog/blazor-hero-quick-start-guide/" Target="_blank" Icon="@Icons.Material.Outlined.ReadMore">
@_localizer["Quick Start Guide"]
</MudNavLink>
<MudNavLink Href="/swagger/index.html" Target="_blank" Icon="@Icons.Material.Outlined.LiveHelp">
@_localizer["Swagger"]
</MudNavLink>
<MudListSubheader Class="mt-2 mb-n2">@_localizer["Personal"]</MudListSubheader>
@if (_canViewDashboards)
{
<MudNavLink Href="/dashboard" Icon="@Icons.Material.Outlined.Dashboard">
@_localizer["Dashboard"]
</MudNavLink>
}
<MudNavLink Href="/account" Icon="@Icons.Material.Outlined.SupervisorAccount">
@_localizer["Account"]
</MudNavLink>
@if (_canViewAuditTrails)
{
<MudNavLink Href="/audit-trails" Icon="@Icons.Material.Outlined.Security">
@_localizer["Audit Trails"]
</MudNavLink>
}
@if (_canViewDocuments || _canViewDocumentTypes)
{
<MudListSubheader Class="mt-2 mb-n2">@_localizer["Document Management"]</MudListSubheader>
@if (_canViewDocuments)
{
<MudNavLink Href="/document-store" Icon="@Icons.Material.Outlined.AttachFile">
@_localizer["Document Store"]
</MudNavLink>
}
@if (_canViewDocumentTypes)
{
<MudNavLink Href="/document-types" Icon="@Icons.Material.Outlined.FileCopy">
@_localizer["Document Types"]
</MudNavLink>
}
}
@if (_canViewUsers || _canViewRoles)
{
<MudListSubheader Class="mt-2 mb-n2">@_localizer["Administrator"]</MudListSubheader>
@if (_canViewUsers)
{
<MudNavLink Href="/identity/users" Icon="@Icons.Material.Outlined.Person">
@_localizer["Users"]
</MudNavLink>
}
@if (_canViewRoles)
{
<MudNavLink Href="/identity/roles" Icon="@Icons.Material.Outlined.Person">@_localizer["Roles"]</MudNavLink>
}
}
@if (_canViewChat)
{
<MudListSubheader Class="mt-2 mb-n2">@_localizer["Communication"]</MudListSubheader>
<MudNavLink Href="/chat" Icon="@Icons.Material.Outlined.Chat">
@_localizer["Chat"]
</MudNavLink>
}
@if (_canViewProducts || _canViewBrands)
{
<MudListSubheader Class="mt-2 mb-n2">@_localizer["Catalog Management"]</MudListSubheader>
@if (_canViewProducts)
{
<MudNavLink Href="/catalog/products" Icon="@Icons.Material.Outlined.CallToAction">
@_localizer["Products"]
</MudNavLink>
}
@if (_canViewBrands)
{
<MudNavLink Href="/catalog/brands" Icon="@Icons.Material.Outlined.CallToAction">
@_localizer["Brands"]
</MudNavLink>
}
}
</MudNavMenu>
@code {
private ClaimsPrincipal _authenticationStateProviderUser;
private bool _canViewHangfire;
private bool _canViewDashboards;
private bool _canViewDocuments;
private bool _canViewDocumentTypes;
private bool _canViewAuditTrails;
private bool _canViewRoles;
private bool _canViewUsers;
private bool _canViewChat;
private bool _canViewProducts;
private bool _canViewBrands;
// example of authorization using token from navlink
private string _accessToken;
private string _jobsLink;
protected override async Task OnParametersSetAsync()
{
_authenticationStateProviderUser = await _stateProvider.GetAuthenticationStateProviderUserAsync();
_canViewHangfire = (await _authorizationService.AuthorizeAsync(_authenticationStateProviderUser, Permissions.Hangfire.View)).Succeeded;
_canViewDashboards = (await _authorizationService.AuthorizeAsync(_authenticationStateProviderUser, Permissions.Dashboards.View)).Succeeded;
_canViewDocuments = (await _authorizationService.AuthorizeAsync(_authenticationStateProviderUser, Permissions.Documents.View)).Succeeded;
_canViewDocumentTypes = (await _authorizationService.AuthorizeAsync(_authenticationStateProviderUser, Permissions.DocumentTypes.View)).Succeeded;
_canViewAuditTrails = (await _authorizationService.AuthorizeAsync(_authenticationStateProviderUser, Permissions.AuditTrails.View)).Succeeded;
_canViewRoles = (await _authorizationService.AuthorizeAsync(_authenticationStateProviderUser, Permissions.Roles.View)).Succeeded;
_canViewUsers = (await _authorizationService.AuthorizeAsync(_authenticationStateProviderUser, Permissions.Users.View)).Succeeded;
_canViewChat = (await _authorizationService.AuthorizeAsync(_authenticationStateProviderUser, Permissions.Communication.Chat)).Succeeded;
_canViewProducts = (await _authorizationService.AuthorizeAsync(_authenticationStateProviderUser, Permissions.Products.View)).Succeeded;
_canViewBrands = (await _authorizationService.AuthorizeAsync(_authenticationStateProviderUser, Permissions.Brands.View)).Succeeded;
_accessToken = await _localStorage.GetItemAsync<string>(StorageConstants.Local.AuthToken);
_jobsLink = $"/jobs?token={_accessToken}";
}
}