private static IScopesEvaluator GetNavigationPropertyPropertyOperationPermisions(IList <ODataPathSegment> pathSegments, bool isTargetByKey, IEdmModel model, string method)
        {
            if (pathSegments.Count <= 1)
            {
                return(new DefaultScopesEvaluator());
            }

            var expectedPath = GetPathFromSegments(pathSegments);
            IEdmVocabularyAnnotatable root = (pathSegments[0] as EntitySetSegment).EntitySet as IEdmVocabularyAnnotatable ?? (pathSegments[0] as SingletonSegment).Singleton;

            var navRestrictions = root.VocabularyAnnotations(model).Where(a => a.Term.FullName() == ODataCapabilityRestrictionsConstants.NavigationRestrictions);

            foreach (var restriction in navRestrictions)
            {
                if (restriction.Value is IEdmRecordExpression record)
                {
                    var temp = record.FindProperty("RestrictedProperties");
                    if (temp?.Value is IEdmCollectionExpression restrictedProperties)
                    {
                        foreach (var item in restrictedProperties.Elements)
                        {
                            if (item is IEdmRecordExpression restrictedProperty)
                            {
                                var navigationProperty = restrictedProperty.FindProperty("NavigationProperty").Value as IEdmPathExpression;
                                if (navigationProperty?.Path == expectedPath)

                                {
                                    if (method == "GET")
                                    {
                                        var readRestrictions = restrictedProperty.FindProperty("ReadRestrictions")?.Value as IEdmRecordExpression;

                                        var readPermissions = ExtractPermissionsFromRecord(readRestrictions);
                                        var evaluator       = new WithOrScopesCombiner(readPermissions);

                                        if (isTargetByKey)
                                        {
                                            var readByKeyRestrictions = readRestrictions.FindProperty("ReadByKeyRestrictions")?.Value as IEdmRecordExpression;
                                            var readByKeyPermissions  = ExtractPermissionsFromRecord(readByKeyRestrictions);
                                            evaluator.AddRange(readByKeyPermissions);
                                        }

                                        return(evaluator);
                                    }
                                    else if (method == "POST" || method == "PATCH" || method == "PUT" || method == "MERGE" || method == "DELETE")
                                    {
                                        var updateRestrictions = restrictedProperty.FindProperty("UpdateRestrictions")?.Value as IEdmRecordExpression;
                                        var updatePermissions  = ExtractPermissionsFromRecord(updateRestrictions);
                                        return(new WithOrScopesCombiner(updatePermissions));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(new DefaultScopesEvaluator());
        }
        private static IScopesEvaluator GetReadByKeyPermissions(IEnumerable <IEdmVocabularyAnnotation> annotations)
        {
            var evaluator = new WithOrScopesCombiner();

            foreach (var annotation in annotations)
            {
                if (annotation.Term.FullName() == ODataCapabilityRestrictionsConstants.ReadRestrictions && annotation.Value is IEdmRecordExpression record)
                {
                    var readPermissions = ExtractPermissionsFromAnnotation(annotation);
                    evaluator.AddRange(readPermissions);

                    var readByKeyProperty    = record.FindProperty("ReadByKeyRestrictions");
                    var readByKeyValue       = readByKeyProperty?.Value as IEdmRecordExpression;
                    var permissionsProperty  = readByKeyValue?.FindProperty("Permissions");
                    var readByKeyPermissions = ExtractPermissionsFromProperty(permissionsProperty);
                    evaluator.AddRange(readByKeyPermissions);
                }
            }

            return(evaluator);
        }