fix #4946 - allow administrators to access user roles via API
This commit is contained in:
parent
f2cb34cc35
commit
1a925221b7
@ -42,7 +42,7 @@ namespace Oqtane.Controllers
|
|||||||
int UserId = -1;
|
int UserId = -1;
|
||||||
if (int.TryParse(siteid, out SiteId) && SiteId == _alias.SiteId && (userid != null && int.TryParse(userid, out UserId) || rolename != null))
|
if (int.TryParse(siteid, out SiteId) && SiteId == _alias.SiteId && (userid != null && int.TryParse(userid, out UserId) || rolename != null))
|
||||||
{
|
{
|
||||||
if (IsAuthorized(UserId, rolename))
|
if (IsAuthorized(UserId, rolename, SiteId))
|
||||||
{
|
{
|
||||||
var userroles = _userRoles.GetUserRoles(SiteId).ToList();
|
var userroles = _userRoles.GetUserRoles(SiteId).ToList();
|
||||||
if (UserId != -1)
|
if (UserId != -1)
|
||||||
@ -82,7 +82,7 @@ namespace Oqtane.Controllers
|
|||||||
public UserRole Get(int id)
|
public UserRole Get(int id)
|
||||||
{
|
{
|
||||||
var userrole = _userRoles.GetUserRole(id);
|
var userrole = _userRoles.GetUserRole(id);
|
||||||
if (userrole != null && SiteValid(userrole.Role.SiteId) && IsAuthorized(userrole.UserId, userrole.Role.Name))
|
if (userrole != null && SiteValid(userrole.Role.SiteId) && IsAuthorized(userrole.UserId, userrole.Role.Name, userrole.Role.SiteId ?? -1))
|
||||||
{
|
{
|
||||||
return Filter(userrole, _userPermissions.GetUser().UserId);
|
return Filter(userrole, _userPermissions.GetUser().UserId);
|
||||||
}
|
}
|
||||||
@ -101,17 +101,21 @@ namespace Oqtane.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsAuthorized(int userId, string roleName)
|
private bool IsAuthorized(int userId, string roleName, int siteId)
|
||||||
{
|
{
|
||||||
bool authorized = true;
|
bool authorized = true;
|
||||||
if (userId != -1)
|
if (userId != -1)
|
||||||
{
|
{
|
||||||
authorized = _userPermissions.GetUser(User).UserId == userId;
|
authorized = (_userPermissions.GetUser(User).UserId == userId);
|
||||||
}
|
}
|
||||||
if (authorized && !string.IsNullOrEmpty(roleName))
|
if (authorized && !string.IsNullOrEmpty(roleName))
|
||||||
{
|
{
|
||||||
authorized = User.IsInRole(roleName);
|
authorized = User.IsInRole(roleName);
|
||||||
}
|
}
|
||||||
|
if (!authorized)
|
||||||
|
{
|
||||||
|
authorized = _userPermissions.IsAuthorized(User, siteId, EntityNames.UserRole, -1, PermissionNames.Write, RoleNames.Admin);
|
||||||
|
}
|
||||||
return authorized;
|
return authorized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user