Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Capabilities Vocabulary Configuration #9

Merged
merged 29 commits into from
Aug 30, 2020

Conversation

g2mula
Copy link
Member

@g2mula g2mula commented Jun 18, 2020

Issues

Adds support for configuring capabilities vocabulary terms target navigation sources and operations

Description

Configurations are auto generated from the referenced vocabulary model in a default EdmModel.
Extension methods have been added to attach configurations to a navigation source or operation.
A fluent api design has been used for setting configuration properties.

Usage

var modelBuilder = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet();
var entitySetConfiguration = modelBuilder.EntitySet<Customer>("Customers");

var deleteRestrictionsBuilder = entitySetConfiguration
    .HasDeleteRestrictions()
    .IsDeletable(false)
    .HasDescription(Description);

Nested configurations can also be easily added via chaining eg

var operationRestrictionsBuilder = actionConfiguration
    .HasOperationRestrictions()
    .IsFilterSegmentSupported(true)
    .HasPermissions(
        new PermissionTypeConfiguration()
            .HasSchemeName(SchemeName)
            .HasScopes(
                new ScopeTypeConfiguration()
                    .HasScope(CustomerReadWriteAllScope)
                    .HasRestrictedProperties("*")));

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

Additional work

Opened new Task #10 Supporting attributes that can be automatically read by the ConventionModelBuilder.
Opened Docs PR at MicrosoftDocs/OData-docs#141

@g2mula
Copy link
Member Author

g2mula commented Jul 8, 2020

The solution looks good to me. @mikepizzo can you leave your comments?
Besides, Do we support "attribute" model builder.

For example, consider:

[DeleteRestriction("Customers", true, .....]
public class Customer
{
....
}

So, developer can use ODataConventionModelBuilder to builder the model with restricitons.

The attrubute modelbuilder is something we can look at in another task, we need to consider the complex nature of some of the options we could want to be able to configure directly in the attribute... If we can come up with clear rules on these, then auto generation of this should also be possible

@xuzhg
Copy link
Member

xuzhg commented Jul 22, 2020

Please file an issue and copy/paste the link into this PR.
Besides, i noticed there are only two test case classes, would you please add more?
In summary, it looks good to me. So i approve it with little comments.


In reply to: 655538126 [](ancestors = 655538126)

Copy link
Member

@xuzhg xuzhg left a comment

Choose a reason for hiding this comment

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

:shipit:

@habbes
Copy link
Contributor

habbes commented Aug 6, 2020

@g2mula could you give an example of how to add navigation restrictions?

The HadNavigationProperty() method requires an IEdmPathExpression parameter. Constructing a new EdmPathExpression instance requires passing the path segments. Here's where I'm not sure what is expected. If, say, I wanted to pass an EntitySetSegment, I would need to specify the IEdmEntitySet. But since the model has not been built yet (because builder.GetEdmModel() has not yet been called)., I don't have access to the eventual entity sets of the model:

customers.HasNavigationRestrictions().HasRestrictedProperties(rp =>
    rp.HasNavigationProperty(new EdmNavigationPropertyPathExpression(new EntitySetSegment(/* what do I pass here? */)))
        .HasReadRestrictions(r =>
            r.HasPermissions(p =>
                p.HasSchemeName("AuthScheme")
                .HasScopes(s => s.HasScope("Customers.ReadByKey").HasRestrictedProperties("*")))));

@g2mula
Copy link
Member Author

g2mula commented Aug 26, 2020

Please file an issue and copy/paste the link into this PR.
Besides, i noticed there are only two test case classes, would you please add more?
In summary, it looks good to me. So i approve it with little comments.

In reply to: 655538126 [](ancestors = 655538126)

Added #10

@g2mula g2mula closed this Aug 26, 2020
@g2mula g2mula reopened this Aug 26, 2020
@g2mula g2mula merged commit 26bea72 into OData:master Aug 30, 2020
@g2mula g2mula self-assigned this Sep 10, 2020
@g2mula g2mula linked an issue Sep 10, 2020 that may be closed by this pull request
@g2mula g2mula deleted the AutoGeneratedVocabulary branch September 10, 2020 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support vocabulary annotation configuration
5 participants