public void InitializeDeleteRestrictionsTypeWithRecordSuccess()
        {
            // Assert
            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("Deletable", new EdmBooleanConstant(false)),
                new EdmPropertyConstructor("NonDeletableNavigationProperties",
                                           new EdmCollectionExpression(new EdmNavigationPropertyPathExpression("abc"), new EdmNavigationPropertyPathExpression("RelatedEvents"))),
                new EdmPropertyConstructor("MaxLevels", new EdmIntegerConstant(42)),
                new EdmPropertyConstructor("Permissions", new EdmCollectionExpression(
                                               new EdmRecordExpression(
                                                   new EdmPropertyConstructor("SchemeName", new EdmStringConstant("schemeName"))))),
                new EdmPropertyConstructor("CustomQueryOptions", new EdmCollectionExpression(
                                               new EdmRecordExpression(
                                                   new EdmPropertyConstructor("Name", new EdmStringConstant("odata-debug")),
                                                   new EdmPropertyConstructor("DocumentationURL", new EdmStringConstant("https://debug.html")))))
                // CustomHeaders
                );

            // Act
            DeleteRestrictionsType delete = new DeleteRestrictionsType();

            delete.Initialize(record);

            // Assert
            VerifyDeleteRestrictionsType(delete);
        }
Beispiel #2
0
        /// <inheritdoc/>
        protected override void SetOperations(OpenApiPathItem item)
        {
            ReadRestrictionsType read = Context.Model.GetRecord <ReadRestrictionsType>(EntitySet);

            if (read == null ||
                (read.ReadByKeyRestrictions == null && read.IsReadable) ||
                (read.ReadByKeyRestrictions != null && read.ReadByKeyRestrictions.IsReadable))
            {
                // If we don't have Read by key read restriction, we should check the set read restrction.
                AddOperation(item, OperationType.Get);
            }

            UpdateRestrictionsType update = Context.Model.GetRecord <UpdateRestrictionsType>(EntitySet);

            if (update == null || update.IsUpdatable)
            {
                AddOperation(item, OperationType.Patch);
            }

            DeleteRestrictionsType delete = Context.Model.GetRecord <DeleteRestrictionsType>(EntitySet);

            if (delete == null || delete.IsDeletable)
            {
                AddOperation(item, OperationType.Delete);
            }
        }
Beispiel #3
0
        private void AddDeleteOperation(OpenApiPathItem item, NavigationPropertyRestriction restriction)
        {
            DeleteRestrictionsType delete = restriction?.DeleteRestrictions;

            if (delete == null || delete.IsDeletable)
            {
                AddOperation(item, OperationType.Delete);
            }
        }
Beispiel #4
0
        protected override void SetSecurity(OpenApiOperation operation)
        {
            DeleteRestrictionsType delete = Context.Model.GetRecord <DeleteRestrictionsType>(EntitySet, CapabilitiesConstants.DeleteRestrictions);

            if (delete == null || delete.Permissions == null)
            {
                return;
            }

            operation.Security = Context.CreateSecurityRequirements(delete.Permissions).ToList();
        }
Beispiel #5
0
        protected override void AppendCustomParameters(OpenApiOperation operation)
        {
            DeleteRestrictionsType delete = Context.Model.GetRecord <DeleteRestrictionsType>(EntitySet, CapabilitiesConstants.DeleteRestrictions);

            if (delete == null)
            {
                return;
            }

            if (delete.CustomHeaders != null)
            {
                AppendCustomParameters(operation, delete.CustomHeaders, ParameterLocation.Header);
            }

            if (delete.CustomQueryOptions != null)
            {
                AppendCustomParameters(operation, delete.CustomQueryOptions, ParameterLocation.Query);
            }
        }
        private void AddDeleteOperation(OpenApiPathItem item, NavigationPropertyRestriction restriction)
        {
            Debug.Assert(!LastSegmentIsRefSegment);

            if (!NavigationProperty.ContainsTarget)
            {
                return;
            }

            DeleteRestrictionsType delete = restriction?.DeleteRestrictions;

            if (delete == null || delete.IsDeletable)
            {
                if (NavigationProperty.TargetMultiplicity() != EdmMultiplicity.Many || LastSegmentIsKeySegment)
                {
                    AddOperation(item, OperationType.Delete);
                }

                return;
            }
        }
        public void TargetOnEntitySetReturnsCorrectDeleteRestrictionsValue(EdmVocabularyAnnotationSerializationLocation location)
        {
            // Arrange
            const string template = @"
                <Annotations Target=""NS.Default/Calendars"">
                  {0}
                </Annotations>";

            IEdmModel model = GetEdmModel(template, location);

            Assert.NotNull(model); // guard

            IEdmEntitySet calendars = model.EntityContainer.FindEntitySet("Calendars");

            Assert.NotNull(calendars); // guard

            // Act
            DeleteRestrictionsType delete = model.GetRecord <DeleteRestrictionsType>(calendars);

            // Assert
            VerifyDeleteRestrictionsType(delete);
        }
        private static void VerifyDeleteRestrictionsType(DeleteRestrictionsType delete)
        {
            Assert.NotNull(delete);

            Assert.NotNull(delete.Deletable);
            Assert.False(delete.Deletable.Value);

            Assert.NotNull(delete.NonDeletableNavigationProperties);
            Assert.Equal(2, delete.NonDeletableNavigationProperties.Count);
            Assert.Equal("abc|RelatedEvents", String.Join("|", delete.NonDeletableNavigationProperties));

            Assert.True(delete.IsNonDeletableNavigationProperty("RelatedEvents"));

            Assert.NotNull(delete.Permissions);
            //Assert.Equal("schemeName", delete.Permissions);

            Assert.Null(delete.CustomHeaders);

            Assert.NotNull(delete.CustomQueryOptions);
            CustomParameter parameter = Assert.Single(delete.CustomQueryOptions);

            Assert.Equal("odata-debug", parameter.Name);
            Assert.Equal("https://debug.html", parameter.DocumentationURL);
        }
        private void AddDeleteOperation(OpenApiPathItem item, NavigationPropertyRestriction restriction)
        {
            Debug.Assert(!LastSegmentIsRefSegment);

            if (!NavigationProperty.ContainsTarget)
            {
                return;
            }

            DeleteRestrictionsType delete       = restriction?.DeleteRestrictions;
            DeleteRestrictionsType deleteEntity = Context.Model.GetRecord <DeleteRestrictionsType>(_entityType);
            bool isDeletableDefault             = delete == null && deleteEntity == null;

            if (isDeletableDefault ||
                (delete?.IsDeletable ?? false) ||
                (deleteEntity?.IsDeletable ?? false))
            {
                if (NavigationProperty.TargetMultiplicity() != EdmMultiplicity.Many || LastSegmentIsKeySegment)
                {
                    AddOperation(item, OperationType.Delete);
                }
                return;
            }
        }
Beispiel #10
0
        /// <inheritdoc/>
        protected override void SetOperations(OpenApiPathItem item)
        {
            IEdmEntitySet             entitySet = NavigationSource as IEdmEntitySet;
            IEdmVocabularyAnnotatable target    = entitySet;

            if (target == null)
            {
                target = NavigationSource as IEdmSingleton;
            }

            string navigationPropertyPath = String.Join("/",
                                                        Path.Segments.Where(s => !(s is ODataKeySegment || s is ODataNavigationSourceSegment)).Select(e => e.Identifier));

            NavigationRestrictionsType    navigation  = Context.Model.GetRecord <NavigationRestrictionsType>(target, CapabilitiesConstants.NavigationRestrictions);
            NavigationPropertyRestriction restriction = navigation?.RestrictedProperties?.FirstOrDefault(r => r.NavigationProperty == navigationPropertyPath);

            // verify using individual first
            if (restriction != null && restriction.Navigability != null && restriction.Navigability.Value == NavigationType.None)
            {
                return;
            }

            if (restriction == null || restriction.Navigability == null)
            {
                // if the individual has not navigability setting, use the global navigability setting
                if (navigation != null && navigation.Navigability != null && navigation.Navigability.Value == NavigationType.None)
                {
                    // Default navigability for all navigation properties of the annotation target.
                    // Individual navigation properties can override this value via `RestrictedProperties/Navigability`.
                    return;
                }
            }

            // So far, we only consider the non-containment
            Debug.Assert(!NavigationProperty.ContainsTarget);

            // It seems OData supports to "GetRef, DeleteRef",
            // Here at this time,let's only consider the "delete"
            ReadRestrictionsType read = restriction?.ReadRestrictions;

            if (read == null || read.IsReadable)
            {
                AddOperation(item, OperationType.Get);
            }

            // Create the ref
            if (NavigationProperty.TargetMultiplicity() == EdmMultiplicity.Many)
            {
                InsertRestrictionsType insert = restriction?.InsertRestrictions;
                if (insert == null || insert.IsInsertable)
                {
                    AddOperation(item, OperationType.Post);
                }
            }
            else
            {
                UpdateRestrictionsType update = restriction?.UpdateRestrictions;
                if (update == null || update.IsUpdatable)
                {
                    AddOperation(item, OperationType.Put);
                }

                // delete the link
                DeleteRestrictionsType delete = restriction?.DeleteRestrictions;
                if (delete == null || delete.IsDeletable)
                {
                    AddOperation(item, OperationType.Delete);
                }
            }
        }
        protected override void Initialize(ODataContext context, ODataPath path)
        {
            base.Initialize(context, path);

            _deleteRestrictions = Context.Model.GetRecord <DeleteRestrictionsType>(EntitySet, CapabilitiesConstants.DeleteRestrictions);
        }