Skip to content

Commit

Permalink
Update AuthorizeMenuAttribute to return ForbidResult instead of previ…
Browse files Browse the repository at this point in the history
…ous result
  • Loading branch information
support committed Oct 9, 2023
1 parent d670ac4 commit 2c67a96
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public async Task TestAuthorizeMenuAttribute_WithValidSiteMap_AllPermissions()
await filter.OnAuthorizationAsync(_mockFilterContext);

// Assert
Assert.IsInstanceOfType(_mockFilterContext.Result, typeof(RedirectToRouteResult));
Assert.IsInstanceOfType(_mockFilterContext.Result, typeof(ForbidResult));
}

[Test]
Expand Down Expand Up @@ -217,6 +217,6 @@ public async Task TestAuthorizeMenuAttribute_WithoutAllPermissions_NotAuthorized

// Assert
// Permission exists but user is not authorized, so a redirect should occur
Assert.IsInstanceOfType(_mockFilterContext.Result, typeof(RedirectToRouteResult));
Assert.IsInstanceOfType(_mockFilterContext.Result, typeof(ForbidResult));
}
}
4 changes: 2 additions & 2 deletions src/Web/Grand.Web.Common/Filters/AuthorizeMenuAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ private async Task ValidateMenuSiteMapPermissions(AuthorizationFilterContext fil
{
if (!(await menuSiteMap.PermissionNames.AllAsync(async x =>
await _permissionService.Authorize(x, _workContext.CurrentCustomer))))
filterContext.Result = new RedirectToRouteResult("AdminLogin", new RouteValueDictionary());
filterContext.Result = new ForbidResult();
}
else
{
if (!(await menuSiteMap.PermissionNames.AnyAsync(async x =>
await _permissionService.Authorize(x, _workContext.CurrentCustomer))))
filterContext.Result = new RedirectToRouteResult("AdminLogin", new RouteValueDictionary());
filterContext.Result = new ForbidResult();
}
}
}
Expand Down

0 comments on commit 2c67a96

Please sign in to comment.