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

Add support for specifying filters on page models.#6417

Closed
pranavkm wants to merge 2 commits into
devfrom
prkrishn/page-filters
Closed

Add support for specifying filters on page models.#6417
pranavkm wants to merge 2 commits into
devfrom
prkrishn/page-filters

Conversation

@pranavkm

Copy link
Copy Markdown
Contributor

No description provided.

@pranavkm
pranavkm requested a review from rynowak June 20, 2017 21:27
@pranavkm
pranavkm force-pushed the prkrishn/page-filters branch from 80fdecd to 260e60c Compare June 20, 2017 21:28
}

// Filters are only allowed to be declared on an explicitly specified model.
var filters = actionDescriptor.FilterDescriptors;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Layering concerns?

}

[AttributeUsage(AttributeTargets.Class)]
public class HandlerChangingPageFilterAttribute : Attribute, IPageFilter

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Did we intentionally choose not to add a PageFilterAttribute or was that an oversight?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I chose not to add it. We can if you think it's good

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNetCore.Authorization;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will undo

var filters = actionDescriptor.FilterDescriptors;
if (modelType != null && modelType != pageType)
{
var modelAttributes = modelType.GetCustomAttributes(inherit: true);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do we want PageModel to implement IPageFilter, IAsyncPageFilter and discover those too?

@pranavkm
pranavkm force-pushed the prkrishn/page-filters branch from 260e60c to bf63fe5 Compare June 24, 2017 01:16
@pranavkm

Copy link
Copy Markdown
Contributor Author

🆙 📅 Still in design

/// Executed for the second pass of <see cref="ApplicationModel"/> building. See <see cref="Order"/>.
/// </summary>
/// <param name="context">The <see cref="PageApplicationModelProviderContext"/>.</param>
void OnProvidersExecuted(PageApplicationModelProviderContext context);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think the changes here really clear anything up.

/// </summary>
/// <param name="model">The <see cref="PageRouteModel"/>.</param>
void Apply(PageRouteModel model);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't love this name, but I don't have a better one in mind.

public IList<SelectorModel> Selectors { get; }
public IList<PageHandlerModel> Handlers { get; }

public IList<PagePropertyModel> HandlerProperties { get; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Call this bound properties (same as controllers)


public TypeInfo HandlerType { get; }

public IReadOnlyList<object> HandlerAttributes { get; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should probably be HandlerTypeAttributes

/// </summary>
public string PropertyName { get; set; }

public bool SupportsGets { get; set; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

delete

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is part of binding info now 👍

TypeInfo pageType,
TypeInfo modelType,
TypeInfo handlerType,
IReadOnlyList<object> handlerAttributes)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should expose the route information here in a read-only format

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What does that look like - something that looks like AttributeRouteInfo?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah or maybe just the route template as a string. It's mostly for informational purposes.

pageModel.Filters.Add(new PageSaveTempDataPropertyFilterFactory());

// Always require an antiforgery token on post
pageModel.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These should move to their own providers

@rynowak rynowak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks great! Really on the right track here.

@pranavkm
pranavkm force-pushed the prkrishn/page-filters branch from bf63fe5 to edb1250 Compare June 28, 2017 19:49
@pranavkm pranavkm changed the title [Design] Add support for specifying filters on page models. Add support for specifying filters on page models. Jun 28, 2017
@pranavkm
pranavkm force-pushed the prkrishn/page-filters branch from edb1250 to fa18eba Compare June 28, 2017 19:52
@pranavkm

Copy link
Copy Markdown
Contributor Author

🆙 📅

/// Gets the sequence of <see cref="PagePropertyModel"/> instances on <see cref="PageHandlerModel"/>.
/// </summary>
public IList<SelectorModel> Selectors { get; }
public IList<PagePropertyModel> HandlerProperties { get; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be BoundProperties like it is on controller model

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok 👍

/// <summary>
/// Gets the page <see cref="TypeInfo"/>.
/// </summary>
public TypeInfo PageType { get; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need this here? Isn't this redundant with the AD?

The type isn't super useful on it's own because it's always generated, I'd say just the AD should be here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PageActionDescriptor doesn't have a type info (just the paths). We need to pass this to the provider in some format, no?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah ok, I guess we do need it. 👍

IReadOnlyList<object> attributes)
{
MethodInfo = handlerMethod ?? throw new ArgumentNullException(nameof(handlerMethod));
Attributes = attributes ?? throw new ArgumentNullException(nameof(attributes));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

😢

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Don't worry, one of these days all our null checks are going to look like this 😈

if (other == null)
{
throw new ArgumentNullException(nameof(other));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Either you're with us or you're against us.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well, that's the annoying bit - it only works for assignments, not regular null checks. Super inconsistent. Sort of one of the reasons I wasn't a big fan of it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yep. This is the using static of this round of features

public string Name { get; set; }

/// <summary>
/// Gets the seqeunce of <see cref="PageParameterModel"/> instances.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sequence


var authorizeFilter = new AuthorizeFilter(policy);
options.Conventions.Add(new FolderConvention(folderPath, model => model.Filters.Add(authorizeFilter)));
options.ApplicationModelConventions.Add(new FolderApplicationModelConvention(folderPath, model => model.Filters.Add(authorizeFilter)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you log a follow up to deal with the fact that we have a collection of conventions on MvcOptions and RazorPagesOptions. I don't like this but I don't want to block you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Where would you want them to go? (So I know for the work item)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't know the answer yet


var handlerModel = new PageHandlerModel(
method,
method.GetCustomAttributes(inherit: false))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We always do inherit: true for these things

pageApplicationModel.Filters.Add(new PageSaveTempDataPropertyFilterFactory());

// Always require an antiforgery token on post
pageApplicationModel.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be separate providers for each of these

/// <summary>
/// Gets a list of <see cref="IPageRouteModelConvention"/> instances that will be applied to
/// the <see cref="PageModel"/> when discovering Razor Pages.
/// </summary>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think both of these need to go into MvcOptions. Let's log an issue for this

@rynowak rynowak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is beautiful 👍 :shipit: 💯 🍺 🐶 😻

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