Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Adding AuthorizePage & AuthorizeFolder without requiring a policy #5942

Merged
merged 1 commit into from
Mar 13, 2017

Conversation

hishamco
Copy link
Contributor

This PR fixes issue #5936

/cc @pranavkm

throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(path));
}

var authorizeFilter = new AuthorizeFilter(string.Empty);
Copy link
Contributor Author

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

Copy link
Contributor

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);

Copy link
Contributor Author

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)
Copy link
Contributor Author

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

Copy link
Contributor

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 = "")
Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor

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/

Copy link
Contributor Author

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 = "")
Copy link
Contributor

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)
Copy link
Contributor

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.

@hishamco
Copy link
Contributor Author

It's ok now

throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(path));
}

var authorizeFilter = new AuthorizeFilter(string.Empty);
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing as AuthorizePage?

Copy link
Contributor Author

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

@hishamco
Copy link
Contributor Author

It should be ok now

@pranavkm
Copy link
Contributor

Thanks for the update. I'll get this merged once Travis \ AppVeyor pass.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants