Skip to content

Commit f3c3ca0

Browse files
seantleonardseverussundarAniruddh25
authored
Introduces a change in the REST POST, PATCH and PUT API response construction - CHERRYPICK (#1824)
merges changes from #1731 as patch to 0.9. includes merge conflict resolution. let tests run before merge. spot checked REST find, put , and some graphql tests and they succeeded. --------- Co-authored-by: Shyam Sundar J <[email protected]> Co-authored-by: Aniruddh Munde <[email protected]>
1 parent b8c0c84 commit f3c3ca0

File tree

50 files changed

+2991
-1029
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2991
-1029
lines changed

config-generators/mssql-commands.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ update Book --config "dab-config.MsSql.json" --permissions "policy_tester_08:cre
9696
update Book --config "dab-config.MsSql.json" --permissions "policy_tester_08:update" --fields.include "*" --policy-database "@item.id eq 9"
9797
update Book --config "dab-config.MsSql.json" --permissions "policy_tester_08:delete" --fields.include "*" --policy-database "@item.id eq 9"
9898
update Book --config "dab-config.MsSql.json" --permissions "policy_tester_08:read" --fields.include "*"
99+
update Book --config "dab-config.MsSql.json" --permissions "test_role_with_noread:create,update,delete"
100+
update Book --config "dab-config.MsSql.json" --permissions "test_role_with_excluded_fields:create,update,delete"
101+
update Book --config "dab-config.MsSql.json" --permissions "test_role_with_excluded_fields:read" --fields.exclude "publisher_id"
102+
update Book --config "dab-config.MsSql.json" --permissions "test_role_with_policy_excluded_fields:create,update,delete"
103+
update Book --config "dab-config.MsSql.json" --permissions "test_role_with_policy_excluded_fields:read" --fields.exclude "publisher_id" --policy-database "@item.title ne 'Test'"
99104
update Review --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete"
100105
update Review --config "dab-config.MsSql.json" --relationship books --target.entity Book --cardinality one
101106
update BookWebsitePlacement --config "dab-config.MsSql.json" --permissions "authenticated:create,update" --rest true --graphql true
@@ -172,6 +177,12 @@ update Stock --config "dab-config.MsSql.json" --permissions "TestNestedFilterFie
172177
update Stock --config "dab-config.MsSql.json" --permissions "TestNestedFilterFieldIsNull_EntityReadForbidden:read"
173178
update Stock --config "dab-config.MsSql.json" --permissions "database_policy_tester:update" --policy-database "@item.pieceid ne 1"
174179
update Stock --config "dab-config.MsSql.json" --permissions "database_policy_tester:create" --policy-database "@item.pieceid ne 6 and @item.piecesAvailable gt 0"
180+
update Stock --config "dab-config.MsSql.json" --permissions "database_policy_tester:read"
181+
update Stock --config "dab-config.MsSql.json" --permissions "test_role_with_noread:create,update,delete"
182+
update Stock --config "dab-config.MsSql.json" --permissions "test_role_with_excluded_fields:create,update,delete"
183+
update Stock --config "dab-config.MsSql.json" --permissions "test_role_with_excluded_fields:read" --fields.exclude "categoryName"
184+
update Stock --config "dab-config.MsSql.json" --permissions "test_role_with_policy_excluded_fields:create,update,delete"
185+
update Stock --config "dab-config.MsSql.json" --permissions "test_role_with_policy_excluded_fields:read" --fields.exclude "categoryName" --policy-database "@item.piecesAvailable ne 0"
175186
update series --config "dab-config.MsSql.json" --permissions "TestNestedFilterManyOne_ColumnForbidden:read" --fields.exclude "name"
176187
update series --config "dab-config.MsSql.json" --permissions "TestNestedFilterManyOne_EntityReadForbidden:create,update,delete"
177188
update series --config "dab-config.MsSql.json" --permissions "TestNestedFilterOneMany_ColumnForbidden:read"

config-generators/mysql-commands.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ update Publisher --config "dab-config.MySql.json" --permissions "database_policy
4949
update Publisher --config "dab-config.MySql.json" --permissions "database_policy_tester:create"
5050
update Publisher --config "dab-config.MySql.json" --permissions "database_policy_tester:update" --policy-database "@item.id ne 1234"
5151
update Stock --config "dab-config.MySql.json" --permissions "authenticated:create,read,update,delete" --rest commodities --graphql true --relationship stocks_price --target.entity stocks_price --cardinality one
52+
update Stock --config "dab-config.MySql.json" --permissions "test_role_with_noread:create,update,delete"
53+
update Stock --config "dab-config.MySql.json" --permissions "test_role_with_excluded_fields:create,update,delete"
54+
update Stock --config "dab-config.MySql.json" --permissions "test_role_with_excluded_fields:read" --fields.exclude "categoryName"
55+
update Stock --config "dab-config.MySql.json" --permissions "test_role_with_policy_excluded_fields:create,update,delete"
56+
update Stock --config "dab-config.MySql.json" --permissions "test_role_with_policy_excluded_fields:read" --fields.exclude "categoryName" --policy-database "@item.piecesAvailable ne 0"
5257
update Book --config "dab-config.MySql.json" --permissions "authenticated:create,read,update,delete"
5358
update Book --config "dab-config.MySql.json" --relationship publishers --target.entity Publisher --cardinality one
5459
update Book --config "dab-config.MySql.json" --relationship websiteplacement --target.entity BookWebsitePlacement --cardinality one
@@ -81,6 +86,11 @@ update Book --config "dab-config.MySql.json" --permissions "policy_tester_08:cre
8186
update Book --config "dab-config.MySql.json" --permissions "policy_tester_08:update" --fields.include "*" --policy-database "@item.id eq 9"
8287
update Book --config "dab-config.MySql.json" --permissions "policy_tester_08:delete" --fields.include "*" --policy-database "@item.id eq 9"
8388
update Book --config "dab-config.MySql.json" --permissions "policy_tester_08:read" --fields.include "*"
89+
update Book --config "dab-config.MySql.json" --permissions "test_role_with_noread:create,update,delete"
90+
update Book --config "dab-config.MySql.json" --permissions "test_role_with_excluded_fields:create,update,delete"
91+
update Book --config "dab-config.MySql.json" --permissions "test_role_with_excluded_fields:read" --fields.exclude "publisher_id"
92+
update Book --config "dab-config.MySql.json" --permissions "test_role_with_policy_excluded_fields:create,update,delete"
93+
update Book --config "dab-config.MySql.json" --permissions "test_role_with_policy_excluded_fields:read" --fields.exclude "publisher_id" --policy-database "@item.title ne 'Test'"
8494
update Review --config "dab-config.MySql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql review:reviews
8595
update Review --config "dab-config.MySql.json" --relationship books --target.entity Book --cardinality one
8696
update Empty --config "dab-config.MySql.json" --permissions "anonymous:read"

config-generators/postgresql-commands.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@ update Publisher --config "dab-config.PostgreSql.json" --permissions "database_p
5151
update Publisher --config "dab-config.PostgreSql.json" --permissions "database_policy_tester:create"
5252
update Publisher --config "dab-config.PostgreSql.json" --permissions "database_policy_tester:update" --policy-database "@item.id ne 1234"
5353
update Stock --config "dab-config.PostgreSql.json" --permissions "authenticated:create,read,update,delete" --rest commodities --graphql true --relationship stocks_price --target.entity stocks_price --cardinality one
54-
update Stock --config "dab-config.PostgreSql.json" --permissions "database_policy_tester:create"
54+
update Stock --config "dab-config.PostgreSql.json" --permissions "database_policy_tester:create,read"
5555
update Stock --config "dab-config.PostgreSql.json" --permissions "database_policy_tester:update" --policy-database "@item.pieceid ne 1"
56+
update Stock --config "dab-config.PostgreSql.json" --permissions "test_role_with_noread:create,update,delete"
57+
update Stock --config "dab-config.PostgreSql.json" --permissions "test_role_with_excluded_fields:create,update,delete"
58+
update Stock --config "dab-config.PostgreSql.json" --permissions "test_role_with_excluded_fields:read" --fields.exclude "categoryName"
59+
update Stock --config "dab-config.PostgreSql.json" --permissions "test_role_with_policy_excluded_fields:create,update,delete"
60+
update Stock --config "dab-config.PostgreSql.json" --permissions "test_role_with_policy_excluded_fields:read" --fields.exclude "categoryName" --policy-database "@item.piecesAvailable ne 0"
5661
update Book --config "dab-config.PostgreSql.json" --permissions "authenticated:create,read,update,delete"
5762
update Book --config "dab-config.PostgreSql.json" --relationship publishers --target.entity Publisher --cardinality one
5863
update Book --config "dab-config.PostgreSql.json" --relationship websiteplacement --target.entity BookWebsitePlacement --cardinality one
@@ -85,6 +90,11 @@ update Book --config "dab-config.PostgreSql.json" --permissions "policy_tester_0
8590
update Book --config "dab-config.PostgreSql.json" --permissions "policy_tester_08:update" --fields.include "*" --policy-database "@item.id eq 9"
8691
update Book --config "dab-config.PostgreSql.json" --permissions "policy_tester_08:delete" --fields.include "*" --policy-database "@item.id eq 9"
8792
update Book --config "dab-config.PostgreSql.json" --permissions "policy_tester_08:read" --fields.include "*"
93+
update Book --config "dab-config.PostgreSql.json" --permissions "test_role_with_noread:create,update,delete"
94+
update Book --config "dab-config.PostgreSql.json" --permissions "test_role_with_excluded_fields:create,update,delete"
95+
update Book --config "dab-config.PostgreSql.json" --permissions "test_role_with_excluded_fields:read" --fields.exclude "publisher_id"
96+
update Book --config "dab-config.PostgreSql.json" --permissions "test_role_with_policy_excluded_fields:create,update,delete"
97+
update Book --config "dab-config.PostgreSql.json" --permissions "test_role_with_policy_excluded_fields:read" --fields.exclude "publisher_id" --policy-database "@item.title ne 'Test'"
8898
update Review --config "dab-config.PostgreSql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql review:reviews
8999
update Review --config "dab-config.PostgreSql.json" --relationship books --target.entity Book --cardinality one
90100
update Empty --config "dab-config.PostgreSql.json" --permissions "anonymous:read"

src/Auth/IAuthorizationResolver.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ public interface IAuthorizationResolver
5656
/// <returns></returns>
5757
public IEnumerable<string> GetAllowedExposedColumns(string entityName, string roleName, EntityActionOperation operation);
5858

59+
/// <summary>
60+
/// Helper function to fetch the database policy associated with the current request based on the entity under
61+
/// action, the role defined in the the request and the operation to be executed.
62+
/// When no database policy is found, no database query predicates need to be added.
63+
/// 1) _entityPermissionMap[entityName] finds the entityMetaData for the current entityName
64+
/// 2) entityMetaData.RoleToOperationMap[roleName] finds the roleMetaData for the current roleName
65+
/// 3) roleMetaData.OperationToColumnMap[operation] finds the operationMetadata for the current operation
66+
/// 4) operationMetaData.databasePolicy finds the required database policy
67+
/// </summary>
68+
/// <param name="entityName">Entity from request.</param>
69+
/// <param name="roleName">Role defined in client role header.</param>
70+
/// <param name="operation">Operation type: create, read, update, delete.</param>
71+
/// <returns>Policy string if a policy exists in config.</returns>
72+
public string GetDBPolicyForRequest(string entityName, string roleName, EntityActionOperation operation);
73+
5974
/// <summary>
6075
/// Retrieves the policy of an operation within an entity's role entry
6176
/// within the permissions section of the runtime config, and tries to process

src/Config/DataApiBuilderException.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ public enum SubStatusCodes
102102
/// DataSource not found for multiple db scenario.
103103
/// </summary>
104104
DataSourceNotFound,
105+
/// <summary>
106+
/// Item identified by the PK is not found in the database.
107+
/// </summary>
108+
ItemNotFound,
109+
/// <summary>
110+
/// Invalid PK field(s) specified in the request.
111+
/// </summary>
112+
InvalidIdentifierField
105113
}
106114

107115
public HttpStatusCode StatusCode { get; }

src/Core/Authorization/AuthorizationResolver.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,8 @@ public string ProcessDBPolicy(string entityName, string roleName, EntityActionOp
190190
return GetPolicyWithClaimValues(dBpolicyWithClaimTypes, GetAllUserClaims(httpContext));
191191
}
192192

193-
/// <summary>
194-
/// Helper function to fetch the database policy associated with the current request based on the entity under
195-
/// action, the role defined in the the request and the operation to be executed.
196-
/// When no database policy is found, no database query predicates need to be added.
197-
/// 1) _entityPermissionMap[entityName] finds the entityMetaData for the current entityName
198-
/// 2) entityMetaData.RoleToOperationMap[roleName] finds the roleMetaData for the current roleName
199-
/// 3) roleMetaData.OperationToColumnMap[operation] finds the operationMetadata for the current operation
200-
/// 4) operationMetaData.databasePolicy finds the required database policy
201-
/// </summary>
202-
/// <param name="entityName">Entity from request.</param>
203-
/// <param name="roleName">Role defined in client role header.</param>
204-
/// <param name="operation">Operation type: create, read, update, delete.</param>
205-
/// <returns>Policy string if a policy exists in config.</returns>
206-
private string GetDBPolicyForRequest(string entityName, string roleName, EntityActionOperation operation)
193+
/// <inheritdoc />
194+
public string GetDBPolicyForRequest(string entityName, string roleName, EntityActionOperation operation)
207195
{
208196
if (!EntityPermissionsMap[entityName].RoleToOperationMap.TryGetValue(roleName, out RoleMetadata? roleMetadata))
209197
{

src/Core/Resolvers/CosmosQueryEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public async Task<Tuple<IEnumerable<JsonDocument>, IMetadata>> ExecuteListAsync(
184184
}
185185

186186
/// <inheritdoc />
187-
public Task<IActionResult> ExecuteAsync(FindRequestContext context, string dataSourceName = "")
187+
public Task<JsonDocument> ExecuteAsync(FindRequestContext context, string dataSourceName = "")
188188
{
189189
throw new NotImplementedException();
190190
}

src/Core/Resolvers/IQueryEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public interface IQueryEngine
3434
/// <summary>
3535
/// Given the RestRequestContext, obtains the query text and executes it against the backend.
3636
/// </summary>
37-
public Task<IActionResult> ExecuteAsync(FindRequestContext context, string dataSourceName = "");
37+
public Task<JsonDocument?> ExecuteAsync(FindRequestContext context, string dataSourceName = "");
3838

3939
/// <summary>
4040
/// Given the StoredProcedureRequestContext, obtains the query text and executes it against the backend.

src/Core/Resolvers/MsSqlQueryExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public override async Task<DbResultSet> GetMultipleResultSetsIfAnyAsync(
270270
message: $"Cannot perform INSERT and could not find {entityName} " +
271271
$"with primary key {prettyPrintPk} to perform UPDATE on.",
272272
statusCode: HttpStatusCode.NotFound,
273-
subStatusCode: DataApiBuilderException.SubStatusCodes.EntityNotFound);
273+
subStatusCode: DataApiBuilderException.SubStatusCodes.ItemNotFound);
274274
}
275275

276276
throw new DataApiBuilderException(

src/Core/Resolvers/QueryExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ DbResultSet dbResultSet
363363
message: $"Cannot perform INSERT and could not find {entityName} " +
364364
$"with primary key {prettyPrintPk} to perform UPDATE on.",
365365
statusCode: HttpStatusCode.NotFound,
366-
subStatusCode: DataApiBuilderException.SubStatusCodes.EntityNotFound);
366+
subStatusCode: DataApiBuilderException.SubStatusCodes.ItemNotFound);
367367
}
368368
}
369369

0 commit comments

Comments
 (0)