Skip to content

Commit 1956c34

Browse files
committed
Added ConfigureAwait(false) to permission storages
1 parent 7454aa6 commit 1956c34

9 files changed

+121
-43
lines changed

src/DragonFly.AspNetCore/Permissions/DragonFlyApiPermissionExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ public static async Task<Result> AuthorizeAsync(this IDragonFlyApi api, ClaimsPr
1717
{
1818
IAuthorizationService authorizationService = api.ServiceProvider.GetRequiredService<IAuthorizationService>();
1919

20-
return await authorizationService.AuthorizeAsync(principal, permission);
20+
return await authorizationService.AuthorizeAsync(principal, permission).ConfigureAwait(false);
2121
}
2222
}

src/DragonFly.AspNetCore/Permissions/Storages/AssetFolderPermissionStorage.cs

+15-5
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,36 @@ public AssetFolderPermissionStorage(IAssetFolderStorage storage, IDragonFlyApi a
3434

3535
public async Task<Result> CreateAsync(AssetFolder folder)
3636
{
37-
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetFolderPermissions.CreateAssetFolder).ThenAsync(x => Storage.CreateAsync(folder));
37+
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetFolderPermissions.CreateAssetFolder)
38+
.ThenAsync(x => Storage.CreateAsync(folder))
39+
.ConfigureAwait(false);
3840
}
3941

4042
public async Task<Result> DeleteAsync(AssetFolder folder)
4143
{
42-
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetFolderPermissions.DeleteAssetFolder).ThenAsync(x => Storage.DeleteAsync(folder));
44+
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetFolderPermissions.DeleteAssetFolder)
45+
.ThenAsync(x => Storage.DeleteAsync(folder))
46+
.ConfigureAwait(false);
4347
}
4448

4549
public async Task<Result<AssetFolder?>> GetAssetFolderAsync(Guid id)
4650
{
47-
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetFolderPermissions.ReadAssetFolder).ThenAsync(x => Storage.GetAssetFolderAsync(id));
51+
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetFolderPermissions.ReadAssetFolder)
52+
.ThenAsync(x => Storage.GetAssetFolderAsync(id))
53+
.ConfigureAwait(false);
4854
}
4955

5056
public async Task<Result<QueryResult<AssetFolder>>> QueryAsync(AssetFolderQuery query)
5157
{
52-
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetFolderPermissions.QueryAssetFolder).ThenAsync(x => Storage.QueryAsync(query));
58+
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetFolderPermissions.QueryAssetFolder)
59+
.ThenAsync(x => Storage.QueryAsync(query))
60+
.ConfigureAwait(false);
5361
}
5462

5563
public async Task<Result> UpdateAsync(AssetFolder folder)
5664
{
57-
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetFolderPermissions.UpdateAssetFolder).ThenAsync(x => Storage.UpdateAsync(folder));
65+
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetFolderPermissions.UpdateAssetFolder)
66+
.ThenAsync(x => Storage.UpdateAsync(folder))
67+
.ConfigureAwait(false);
5868
}
5969
}

src/DragonFly.AspNetCore/Permissions/Storages/AssetPermissionStorage.cs

+30-10
Original file line numberDiff line numberDiff line change
@@ -33,51 +33,71 @@ public AssetPermissionStorage(IAssetStorage storage, IDragonFlyApi api, IPrincip
3333

3434
public async Task<Result> ApplyMetadataAsync(Asset asset)
3535
{
36-
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.UpdateAsset).ThenAsync(x => Storage.ApplyMetadataAsync(asset));
36+
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.UpdateAsset)
37+
.ThenAsync(x => Storage.ApplyMetadataAsync(asset))
38+
.ConfigureAwait(false);
3739
}
3840

3941
public async Task<Result<BackgroundTaskInfo>> ApplyMetadataAsync(AssetQuery query)
4042
{
41-
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.UpdateAsset).ThenAsync(x => Storage.ApplyMetadataAsync(query));
43+
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.UpdateAsset)
44+
.ThenAsync(x => Storage.ApplyMetadataAsync(query))
45+
.ConfigureAwait(false);
4246
}
4347

4448
public async Task<Result> CreateAsync(Asset asset)
4549
{
46-
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.CreateAsset).ThenAsync(x => Storage.CreateAsync(asset));
50+
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.CreateAsset)
51+
.ThenAsync(x => Storage.CreateAsync(asset))
52+
.ConfigureAwait(false);
4753
}
4854

4955
public async Task<Result> DeleteAsync(Asset asset)
5056
{
51-
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.DeleteAsset).ThenAsync(x => Storage.DeleteAsync(asset));
57+
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.DeleteAsset)
58+
.ThenAsync(x => Storage.DeleteAsync(asset))
59+
.ConfigureAwait(false);
5260
}
5361

5462
public async Task<Result<Asset?>> GetAssetAsync(Guid id)
5563
{
56-
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.ReadAsset).ThenAsync(x => Storage.GetAssetAsync(id));
64+
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.ReadAsset)
65+
.ThenAsync(x => Storage.GetAssetAsync(id))
66+
.ConfigureAwait(false);
5767
}
5868

5969
public async Task<Result<Stream>> OpenStreamAsync(Guid assetId)
6070
{
61-
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.DownloadAsset).ThenAsync(x => Storage.OpenStreamAsync(assetId));
71+
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.DownloadAsset)
72+
.ThenAsync(x => Storage.OpenStreamAsync(assetId))
73+
.ConfigureAwait(false);
6274
}
6375

6476
public async Task<Result> PublishAsync(Asset asset)
6577
{
66-
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.PublishAsset).ThenAsync(x => Storage.PublishAsync(asset));
78+
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.PublishAsset)
79+
.ThenAsync(x => Storage.PublishAsync(asset))
80+
.ConfigureAwait(false);
6781
}
6882

6983
public async Task<Result<QueryResult<Asset>>> QueryAsync(AssetQuery query)
7084
{
71-
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.QueryAsset).ThenAsync(x => Storage.QueryAsync(query));
85+
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.QueryAsset)
86+
.ThenAsync(x => Storage.QueryAsync(query))
87+
.ConfigureAwait(false);
7288
}
7389

7490
public async Task<Result> UpdateAsync(Asset asset)
7591
{
76-
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.UpdateAsset).ThenAsync(x => Storage.UpdateAsync(asset));
92+
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.UpdateAsset)
93+
.ThenAsync(x => Storage.UpdateAsync(asset))
94+
.ConfigureAwait(false);
7795
}
7896

7997
public async Task<Result> UploadAsync(Guid assetId, string mimetype, Stream stream)
8098
{
81-
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.UploadAsset).ThenAsync(x => Storage.UploadAsync(assetId, mimetype, stream));
99+
return await Api.AuthorizeAsync(PrincipalContext.Current, AssetPermissions.UploadAsset)
100+
.ThenAsync(x => Storage.UploadAsync(assetId, mimetype, stream))
101+
.ConfigureAwait(false);
82102
}
83103
}

src/DragonFly.AspNetCore/Permissions/Storages/BackgroundTaskPermissionStorage.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,23 @@ public BackgroundTaskPermissionStorage(IBackgroundTaskManager storage, IDragonFl
3333

3434
public async Task<Result> CancelAsync(int id)
3535
{
36-
return await Api.AuthorizeAsync(PrincipalContext.Current, BackgroundTaskPermissions.CancelBackgroundTask).ThenAsync(x => Storage.CancelAsync(id));
36+
return await Api.AuthorizeAsync(PrincipalContext.Current, BackgroundTaskPermissions.CancelBackgroundTask)
37+
.ThenAsync(x => Storage.CancelAsync(id))
38+
.ConfigureAwait(false);
3739
}
3840

3941
public async Task<Result<BackgroundTaskInfo[]>> GetTasksAsync()
4042
{
41-
return await Api.AuthorizeAsync(PrincipalContext.Current, BackgroundTaskPermissions.QueryBackgroundTask).ThenAsync(x => Storage.GetTasksAsync());
43+
return await Api.AuthorizeAsync(PrincipalContext.Current, BackgroundTaskPermissions.QueryBackgroundTask)
44+
.ThenAsync(x => Storage.GetTasksAsync())
45+
.ConfigureAwait(false);
4246
}
4347

4448
public async Task<Result<IBackgroundTaskNotificationProvider>> StartNotificationProviderAsync()
4549
{
46-
return await Api.AuthorizeAsync(PrincipalContext.Current, BackgroundTaskPermissions.QueryBackgroundTask).ThenAsync(x => Storage.StartNotificationProviderAsync());
50+
return await Api.AuthorizeAsync(PrincipalContext.Current, BackgroundTaskPermissions.QueryBackgroundTask)
51+
.ThenAsync(x => Storage.StartNotificationProviderAsync())
52+
.ConfigureAwait(false);
4753
}
4854

4955
public BackgroundTask Start(string name, Func<BackgroundTaskContext, Task> action)

src/DragonFly.AspNetCore/Permissions/Storages/ContentPermissionStorage.cs

+28-10
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,23 @@ public ContentPermissionStorage(IContentStorage storage, IDragonFlyApi api, IPri
3434

3535
public async Task<Result> CreateAsync(ContentItem content)
3636
{
37-
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(content.Schema.Name, ContentAction.Create)).ThenAsync(x => Storage.CreateAsync(content));
37+
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(content.Schema.Name, ContentAction.Create))
38+
.ThenAsync(x => Storage.CreateAsync(content))
39+
.ConfigureAwait(false);
3840
}
3941

4042
public async Task<Result<bool>> DeleteAsync(string schema, Guid id)
4143
{
42-
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(schema, ContentAction.Delete)).ThenAsync(x => Storage.DeleteAsync(schema, id));
44+
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(schema, ContentAction.Delete))
45+
.ThenAsync(x => Storage.DeleteAsync(schema, id))
46+
.ConfigureAwait(false);
4347
}
4448

4549
public async Task<Result<ContentItem?>> GetContentAsync(string schema, Guid id)
4650
{
47-
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(schema, ContentAction.Read)).ThenAsync(x => Storage.GetContentAsync(schema, id));
51+
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(schema, ContentAction.Read))
52+
.ThenAsync(x => Storage.GetContentAsync(schema, id))
53+
.ConfigureAwait(false);
4854
}
4955

5056
public async Task<Result<ContentReferenceIndex>> GetReferencedByAsync(string schema, Guid id)
@@ -56,36 +62,48 @@ public async Task<Result<ContentReferenceIndex>> GetReferencedByAsync(string sch
5662

5763
public async Task<Result<bool>> PublishAsync(string schema, Guid id)
5864
{
59-
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(schema, ContentAction.Publish)).ThenAsync(x => Storage.PublishAsync(schema, id));
65+
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(schema, ContentAction.Publish))
66+
.ThenAsync(x => Storage.PublishAsync(schema, id))
67+
.ConfigureAwait(false);
6068
}
6169

6270
public async Task<Result<BackgroundTaskInfo>> PublishQueryAsync(ContentQuery query)
6371
{
64-
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(query.Schema, ContentAction.Publish)).ThenAsync(x => Storage.PublishQueryAsync(query));
72+
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(query.Schema, ContentAction.Publish))
73+
.ThenAsync(x => Storage.PublishQueryAsync(query))
74+
.ConfigureAwait(false);
6575
}
6676

6777
public async Task<Result<QueryResult<ContentItem>>> QueryAsync(ContentQuery query)
6878
{
69-
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(query.Schema, ContentAction.Query)).ThenAsync(x => Storage.QueryAsync(query));
79+
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(query.Schema, ContentAction.Query))
80+
.ThenAsync(x => Storage.QueryAsync(query))
81+
.ConfigureAwait(false);
7082
}
7183

7284
public async Task<Result<bool>> UnpublishAsync(string schema, Guid id)
7385
{
74-
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(schema, ContentAction.Unpublish)).ThenAsync(x => Storage.UnpublishAsync(schema, id));
86+
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(schema, ContentAction.Unpublish))
87+
.ThenAsync(x => Storage.UnpublishAsync(schema, id))
88+
.ConfigureAwait(false);
7589
}
7690

7791
public async Task<Result<BackgroundTaskInfo>> UnpublishQueryAsync(ContentQuery query)
7892
{
79-
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(query.Schema, ContentAction.Unpublish)).ThenAsync(x => Storage.UnpublishQueryAsync(query));
93+
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(query.Schema, ContentAction.Unpublish))
94+
.ThenAsync(x => Storage.UnpublishQueryAsync(query))
95+
.ConfigureAwait(false);
8096
}
8197

8298
public async Task<Result> UpdateAsync(ContentItem content)
8399
{
84-
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(content.Schema.Name, ContentAction.Update)).ThenAsync(x => Storage.UpdateAsync(content));
100+
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(content.Schema.Name, ContentAction.Update))
101+
.ThenAsync(x => Storage.UpdateAsync(content))
102+
.ConfigureAwait(false);
85103
}
86104

87105
public async Task<Result> RebuildDatabaseAsync()
88106
{
89-
return await Storage.RebuildDatabaseAsync();
107+
return await Storage.RebuildDatabaseAsync().ConfigureAwait(false);
90108
}
91109
}

src/DragonFly.AspNetCore/Permissions/Storages/ContentVersionPermissionStorage.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ public ContentVersionPermissionStorage(IContentVersionStorage storage, IDragonFl
3535
public async Task<Result<ContentItem?>> GetContentByVersionAsync(string schema, Guid id)
3636
{
3737
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(schema, ContentAction.Read))
38-
.ThenAsync(x => Storage.GetContentByVersionAsync(schema, id));
38+
.ThenAsync(x => Storage.GetContentByVersionAsync(schema, id))
39+
.ConfigureAwait(false);
3940
}
4041

4142
public async Task<Result<QueryResult<ContentVersionEntry>>> GetContentVersionsAsync(string schema, Guid id)
4243
{
4344
return await Api.AuthorizeAsync(PrincipalContext.Current, ContentPermissions.Create(schema, ContentAction.Read))
44-
.ThenAsync(x => Storage.GetContentVersionsAsync(schema, id));
45+
.ThenAsync(x => Storage.GetContentVersionsAsync(schema, id))
46+
.ConfigureAwait(false);
4547
}
4648
}

src/DragonFly.AspNetCore/Permissions/Storages/SchemaPermissionStorage.cs

+18-6
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,43 @@ public SchemaPermissionStorage(ISchemaStorage storage, IDragonFlyApi api, IPrinc
3434

3535
public async Task<Result> CreateAsync(ContentSchema schema)
3636
{
37-
return await Api.AuthorizeAsync(PrincipalContext.Current, SchemaPermissions.CreateSchema).ThenAsync(x => Storage.CreateAsync(schema));
37+
return await Api.AuthorizeAsync(PrincipalContext.Current, SchemaPermissions.CreateSchema)
38+
.ThenAsync(x => Storage.CreateAsync(schema))
39+
.ConfigureAwait(false);
3840
}
3941

4042
public async Task<Result> DeleteAsync(ContentSchema schema)
4143
{
42-
return await Api.AuthorizeAsync(PrincipalContext.Current, SchemaPermissions.DeleteSchema).ThenAsync(x => Storage.DeleteAsync(schema));
44+
return await Api.AuthorizeAsync(PrincipalContext.Current, SchemaPermissions.DeleteSchema)
45+
.ThenAsync(x => Storage.DeleteAsync(schema))
46+
.ConfigureAwait(false);
4347
}
4448

4549
public async Task<Result<ContentSchema?>> GetSchemaAsync(Guid id)
4650
{
47-
return await Api.AuthorizeAsync(PrincipalContext.Current, SchemaPermissions.ReadSchema).ThenAsync(x => Storage.GetSchemaAsync(id));
51+
return await Api.AuthorizeAsync(PrincipalContext.Current, SchemaPermissions.ReadSchema)
52+
.ThenAsync(x => Storage.GetSchemaAsync(id))
53+
.ConfigureAwait(false);
4854
}
4955

5056
public async Task<Result<ContentSchema?>> GetSchemaAsync(string name)
5157
{
52-
return await Api.AuthorizeAsync(PrincipalContext.Current, SchemaPermissions.ReadSchema).ThenAsync(x => Storage.GetSchemaAsync(name));
58+
return await Api.AuthorizeAsync(PrincipalContext.Current, SchemaPermissions.ReadSchema)
59+
.ThenAsync(x => Storage.GetSchemaAsync(name))
60+
.ConfigureAwait(false);
5361
}
5462

5563
public async Task<Result<QueryResult<ContentSchema>>> QuerySchemasAsync()
5664
{
57-
return await Api.AuthorizeAsync(PrincipalContext.Current, SchemaPermissions.QuerySchema).ThenAsync(x => Storage.QuerySchemasAsync());
65+
return await Api.AuthorizeAsync(PrincipalContext.Current, SchemaPermissions.QuerySchema)
66+
.ThenAsync(x => Storage.QuerySchemasAsync())
67+
.ConfigureAwait(false);
5868
}
5969

6070
public async Task<Result> UpdateAsync(ContentSchema schema)
6171
{
62-
return await Api.AuthorizeAsync(PrincipalContext.Current, SchemaPermissions.UpdateSchema).ThenAsync(x => Storage.UpdateAsync(schema));
72+
return await Api.AuthorizeAsync(PrincipalContext.Current, SchemaPermissions.UpdateSchema)
73+
.ThenAsync(x => Storage.UpdateAsync(schema))
74+
.ConfigureAwait(false);
6375
}
6476
}

0 commit comments

Comments
 (0)