Skip to content

Commit ef24197

Browse files
author
Leonid
committed
Menu items fixes
1 parent d15900d commit ef24197

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

eFormAPI/eFormAPI.Web/Abstractions/IUserService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public interface IUserService
88
int UserId { get; }
99
string Role { get; }
1010
bool IsInRole(string role);
11+
bool IsAdmin();
1112
Task<EformUser> GetByIdAsync(int id);
1213
Task<EformUser> GetByUsernameAsync(string username);
1314
Task<EformUser> GetCurrentUserAsync();

eFormAPI/eFormAPI.Web/Infrastructure/Database/Seed/SeedItems/MenuItemSeed.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using eFormAPI.Web.Infrastructure.Database.Entities;
22
using Microsoft.EntityFrameworkCore;
3-
//using eFormAPI.Web.Infrastructure.Enums;
43

54
namespace eFormAPI.Web.Infrastructure.Database.Seed.SeedItems
65
{

eFormAPI/eFormAPI.Web/Services/MenuService.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,12 @@ private List<MenuItem> FilterMenuForUser(IEnumerable<MenuItem> items, ICollectio
212212
{
213213
newList.Add(menuItem);
214214
}
215-
215+
break;
216+
case "Plugins Settings":
217+
if (_userService.IsAdmin())
218+
{
219+
newList.Add(menuItem);
220+
}
216221
break;
217222
case "Security":
218223
break;

eFormAPI/eFormAPI.Web/Services/UserService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public int UserId
4848

4949
public bool IsInRole(string role) => _httpAccessor.HttpContext.User.IsInRole(role);
5050

51+
public bool IsAdmin()
52+
{
53+
return IsInRole(EformRole.Admin);
54+
}
55+
5156
public async Task<EformUser> GetCurrentUserAsync()
5257
{
5358
return await _dbContext.Users.FirstOrDefaultAsync(x => x.Id == UserId);

0 commit comments

Comments
 (0)