user and role management improvements
This commit is contained in:
parent
5a519510a9
commit
d42c7a5ea5
@ -58,12 +58,16 @@ else
|
||||
<Pager Items="@userroles">
|
||||
<Header>
|
||||
<th>@Localizer["Users"]</th>
|
||||
<th>@Localizer["Effective"]</th>
|
||||
<th>@Localizer["Expiry"]</th>
|
||||
<th> </th>
|
||||
</Header>
|
||||
<Row>
|
||||
<td>@context.User.DisplayName</td>
|
||||
<td>@context.EffectiveDate</td>
|
||||
<td>@context.ExpiryDate</td>
|
||||
<td>
|
||||
<ActionDialog Header="Remove User" Message="@Localizer["Are You Sure You Wish To Remove {0} From This Role?", context.User.DisplayName]" Action="Delete" Security="SecurityAccessLevel.Admin" Class="btn btn-danger" OnClick="@(async () => await DeleteUserRole(context.UserRoleId))" ResourceKey="DeleteUserRole" />
|
||||
<ActionDialog Header="Remove User" Message="@Localizer["Are You Sure You Wish To Remove {0} From This Role?", context.User.DisplayName]" Action="Delete" Security="SecurityAccessLevel.Admin" Class="btn btn-danger" OnClick="@(async () => await DeleteUserRole(context.UserRoleId))" Disabled="@(context.Role.IsAutoAssigned)" ResourceKey="DeleteUserRole" />
|
||||
</td>
|
||||
</Row>
|
||||
</Pager>
|
||||
|
@ -36,10 +36,7 @@ else
|
||||
<ActionLink Action="Edit" Parameters="@($"id=" + context.UserId.ToString())" ResourceKey="EditUser" />
|
||||
</td>
|
||||
<td>
|
||||
@if (context.Role.Name != RoleNames.Host)
|
||||
{
|
||||
<ActionDialog Header="Delete User" Message="@Localizer["Are You Sure You Wish To Delete {0}?", context.User.DisplayName]" Action="Delete" Security="SecurityAccessLevel.Admin" Class="btn btn-danger" OnClick="@(async () => await DeleteUser(context))" ResourceKey="DeleteUser" />
|
||||
}
|
||||
<ActionDialog Header="Delete User" Message="@Localizer["Are You Sure You Wish To Delete {0}?", context.User.DisplayName]" Action="Delete" Security="SecurityAccessLevel.Admin" Class="btn btn-danger" OnClick="@(async () => await DeleteUser(context))" Disabled="@(context.Role.Name == RoleNames.Host)" ResourceKey="DeleteUser" />
|
||||
</td>
|
||||
<td>
|
||||
<ActionLink Action="Roles" Parameters="@($"id=" + context.UserId.ToString())" ResourceKey="Roles" />
|
||||
|
@ -59,15 +59,16 @@ else
|
||||
<Pager Items="@userroles">
|
||||
<Header>
|
||||
<th>@Localizer["Roles"]</th>
|
||||
<th>@Localizer["Effective"]</th>
|
||||
<th>@Localizer["Expiry"]</th>
|
||||
<th> </th>
|
||||
</Header>
|
||||
<Row>
|
||||
<td>@context.Role.Name</td>
|
||||
<td>@context.EffectiveDate</td>
|
||||
<td>@context.ExpiryDate</td>
|
||||
<td>
|
||||
@if (context.Role.Name != RoleNames.Registered && (context.Role.Name != RoleNames.Host || userid != PageState.User.UserId))
|
||||
{
|
||||
<ActionDialog Header="Remove Role" Message="@Localizer["Are You Sure You Wish To Remove This User From The {0} Role?", context.Role.Name]" Action="Delete" Security="SecurityAccessLevel.Admin" Class="btn btn-danger" OnClick="@(async () => await DeleteUserRole(context.UserRoleId))" ResourceKey="DeleteUserRole" />
|
||||
}
|
||||
<ActionDialog Header="Remove Role" Message="@Localizer["Are You Sure You Wish To Remove This User From The {0} Role?", context.Role.Name]" Action="Delete" Security="SecurityAccessLevel.Admin" Class="btn btn-danger" OnClick="@(async () => await DeleteUserRole(context.UserRoleId))" Disabled="@(context.Role.IsAutoAssigned || (context.Role.Name == RoleNames.Host && userid == PageState.User.UserId))" ResourceKey="DeleteUserRole" />
|
||||
</td>
|
||||
</Row>
|
||||
</Pager>
|
||||
@ -95,6 +96,7 @@ else
|
||||
if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host))
|
||||
{
|
||||
roles = await RoleService.GetRolesAsync(PageState.Site.SiteId, true);
|
||||
roles = roles.Where(item => item.Name != RoleNames.Everyone).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ namespace Oqtane.Controllers
|
||||
{
|
||||
if (string.IsNullOrEmpty(global))
|
||||
{
|
||||
global = "false";
|
||||
global = "False";
|
||||
}
|
||||
return _roles.GetRoles(int.Parse(siteid), bool.Parse(global));
|
||||
}
|
||||
@ -71,9 +71,13 @@ namespace Oqtane.Controllers
|
||||
[HttpDelete("{id}")]
|
||||
[Authorize(Roles = RoleNames.Admin)]
|
||||
public void Delete(int id)
|
||||
{
|
||||
var role = _roles.GetRole(id);
|
||||
if (!role.IsSystem)
|
||||
{
|
||||
_roles.DeleteRole(id);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Role Deleted {RoleId}", id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,16 +52,16 @@ namespace Oqtane.Controllers
|
||||
var role = _roles.GetRole(userRole.RoleId);
|
||||
if (ModelState.IsValid && (User.IsInRole(RoleNames.Host) || role.Name != RoleNames.Host))
|
||||
{
|
||||
userRole = _userRoles.AddUserRole(userRole);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "User Role Added {UserRole}", userRole);
|
||||
|
||||
if (role.Name == RoleNames.Host)
|
||||
{
|
||||
// host roles can only exist at global level - remove all site specific user roles
|
||||
_userRoles.DeleteUserRoles(userRole.UserId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "User Roles Deleted For UserId {UserId}", userRole.UserId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "User Roles Deleted For UserId {UserId}", userRole.UserId);
|
||||
}
|
||||
|
||||
userRole = _userRoles.AddUserRole(userRole);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "User Role Added {UserRole}", userRole);
|
||||
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.User, userRole.UserId);
|
||||
}
|
||||
return userRole;
|
||||
@ -98,10 +98,10 @@ namespace Oqtane.Controllers
|
||||
// add site specific user roles to preserve user access
|
||||
var role = _roles.GetRoles(_tenants.GetAlias().SiteId).FirstOrDefault(item => item.Name == RoleNames.Registered);
|
||||
userRole = _userRoles.AddUserRole(new UserRole { UserId = userRole.UserId, RoleId = role.RoleId, EffectiveDate = null, ExpiryDate = null });
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "User Role Added {UserRole}", userRole);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "User Role Added {UserRole}", userRole);
|
||||
role = _roles.GetRoles(_tenants.GetAlias().SiteId).FirstOrDefault(item => item.Name == RoleNames.Admin);
|
||||
userRole = _userRoles.AddUserRole(new UserRole { UserId = userRole.UserId, RoleId = role.RoleId, EffectiveDate = null, ExpiryDate = null });
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "User Role Added {UserRole}", userRole);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "User Role Added {UserRole}", userRole);
|
||||
}
|
||||
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.User, userRole.UserId);
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Oqtane.Models;
|
||||
@ -16,13 +16,20 @@ namespace Oqtane.Repository
|
||||
|
||||
public IEnumerable<Role> GetRoles(int siteId)
|
||||
{
|
||||
return _db.Role.Where(item => item.SiteId == siteId);
|
||||
return GetRoles(siteId, false);
|
||||
}
|
||||
|
||||
public IEnumerable<Role> GetRoles(int siteId, bool includeGlobalRoles)
|
||||
{
|
||||
if (includeGlobalRoles)
|
||||
{
|
||||
return _db.Role.Where(item => item.SiteId == siteId || item.SiteId == null);
|
||||
}
|
||||
else
|
||||
{
|
||||
return _db.Role.Where(item => item.SiteId == siteId);
|
||||
}
|
||||
}
|
||||
|
||||
public Role AddRole(Role role)
|
||||
{
|
||||
|
Reference in New Issue
Block a user