-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Adding AuthorizePage & AuthorizeFolder without requiring a policy #5942
Conversation
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(path)); | ||
} | ||
|
||
var authorizeFilter = new AuthorizeFilter(string.Empty); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can use this instead
var authorizeFilter = new AuthorizeFilter(new[] { new AuthorizeAttribute() });
but IMHO passing string.Empty
is much simpler in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing this, just call the other overload:
public static RazorPagesOptions AuthorizePage(this RazorPagesOptions options, string path) => AuthorizePage(options, path, policy: string.Empty);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking last time do the exact thing, but I forget it 😄 , I will update it now ..
[Theory] | ||
[InlineData("/Users")] | ||
[InlineData("/Users/")] | ||
public void AuthorizePage_AddsAuthorizeFilterToPagesUnderFolder(string folderName) | ||
public void AuthorizePage_AddsAuthorizeFilterWithPolicyToPagesUnderFolder(string folderName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add optional param for policy
in this way we can merge both tests in one, let me know if I can go with it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the tests are fine the way they are now.
@@ -43,7 +43,7 @@ public static RazorPagesOptions ConfigureFilter(this RazorPagesOptions options, | |||
/// <param name="path">The path of the Razor Page.</param> | |||
/// <param name="policy">The authorization policy.</param> | |||
/// <returns>The <see cref="RazorPagesOptions"/>.</returns> | |||
public static RazorPagesOptions AuthorizePage(this RazorPagesOptions options, string path, string policy) | |||
public static RazorPagesOptions AuthorizePage(this RazorPagesOptions options, string path, string policy = "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I preferred to use optional parameter instead of creating another overload
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use default(string)
too if you don't like the double quotes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generally don't use optional parameters in public APIs. Could you create another overload?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a blog post that explains why it's a tricky to version these: http://haacked.com/archive/2010/08/10/versioning-issues-with-optional-arguments.aspx/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I saw this blog post long time back, ok I will revert the latest change
@@ -43,7 +43,7 @@ public static RazorPagesOptions ConfigureFilter(this RazorPagesOptions options, | |||
/// <param name="path">The path of the Razor Page.</param> | |||
/// <param name="policy">The authorization policy.</param> | |||
/// <returns>The <see cref="RazorPagesOptions"/>.</returns> | |||
public static RazorPagesOptions AuthorizePage(this RazorPagesOptions options, string path, string policy) | |||
public static RazorPagesOptions AuthorizePage(this RazorPagesOptions options, string path, string policy = "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generally don't use optional parameters in public APIs. Could you create another overload?
[Theory] | ||
[InlineData("/Users")] | ||
[InlineData("/Users/")] | ||
public void AuthorizePage_AddsAuthorizeFilterToPagesUnderFolder(string folderName) | ||
public void AuthorizePage_AddsAuthorizeFilterWithPolicyToPagesUnderFolder(string folderName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the tests are fine the way they are now.
It's ok now |
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(path)); | ||
} | ||
|
||
var authorizeFilter = new AuthorizeFilter(string.Empty); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing this, just call the other overload:
public static RazorPagesOptions AuthorizePage(this RazorPagesOptions options, string path) => AuthorizePage(options, path, policy: string.Empty);
/// <param name="options">The <see cref="RazorPagesOptions"/> to configure.</param> | ||
/// <param name="folderPath">The folder path.</param> | ||
/// <returns>The <see cref="RazorPagesOptions"/>.</returns> | ||
public static RazorPagesOptions AuthorizeFolder(this RazorPagesOptions options, string folderPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing as AuthorizePage
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG something goes wrong in my local commits, sorry
It should be ok now |
Thanks for the update. I'll get this merged once Travis \ AppVeyor pass. |
This PR fixes issue #5936
/cc @pranavkm