Skip to content

Commit

Permalink
Merge pull request #17337 from abpframework/PermissionIntegrationService
Browse files Browse the repository at this point in the history
Add `PermissionIntegrationService` to permission-management module.
  • Loading branch information
hikalkan authored Aug 10, 2023
2 parents 04cb7fe + 24c5827 commit 631013c
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;

namespace Volo.Abp.PermissionManagement.Integration;

[IntegrationService]
public interface IPermissionIntegrationService : IApplicationService
{
Task<ListResultDto<PermissionGrantOutput>> IsGrantedAsync(List<PermissionGrantInput> input);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace Volo.Abp.PermissionManagement.Integration;

public class PermissionGrantInput
{
public Guid UserId { get; set; }

public string[] PermissionNames { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;

namespace Volo.Abp.PermissionManagement.Integration;

public class PermissionGrantOutput
{
public Guid UserId { get; set; }

public Dictionary<string, bool> Permissions { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Authorization.Permissions;

namespace Volo.Abp.PermissionManagement.Integration;

[IntegrationService]
public class PermissionIntegrationService : ApplicationService, IPermissionIntegrationService
{
protected IPermissionManager PermissionManager { get; }

public PermissionIntegrationService(IPermissionManager permissionManager)
{
PermissionManager = permissionManager;
}

public virtual async Task<ListResultDto<PermissionGrantOutput>> IsGrantedAsync(List<PermissionGrantInput> input)
{
var result = new List<PermissionGrantOutput>();
foreach (var item in input)
{
result.Add(new PermissionGrantOutput
{
UserId = item.UserId,
Permissions = (await PermissionManager.GetAsync(item.PermissionNames, UserPermissionValueProvider.ProviderName, item.UserId.ToString())).Result
.ToDictionary(x => x.Name, x => x.IsGranted)
});
}

return new ListResultDto<PermissionGrantOutput>(result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This file is automatically generated by ABP framework to use MVC Controllers from CSharp
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Http.Client;
using Volo.Abp.Http.Client.ClientProxying;
using Volo.Abp.Http.Modeling;
using Volo.Abp.PermissionManagement.Integration;

// ReSharper disable once CheckNamespace
namespace Volo.Abp.PermissionManagement.Integration;

[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(IPermissionIntegrationService), typeof(PermissionIntegrationClientProxy))]
[IntegrationService]
public partial class PermissionIntegrationClientProxy : ClientProxyBase<IPermissionIntegrationService>, IPermissionIntegrationService
{
public virtual async Task<ListResultDto<PermissionGrantOutput>> IsGrantedAsync(List<PermissionGrantInput> input)
{
return await RequestAsync<ListResultDto<PermissionGrantOutput>>(nameof(IsGrantedAsync), new ClientProxyRequestTypeValue
{
{ typeof(List<PermissionGrantInput>), input }
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file is part of PermissionIntegrationClientProxy, you can customize it here
// ReSharper disable once CheckNamespace
namespace Volo.Abp.PermissionManagement.Integration;

public partial class PermissionIntegrationClientProxy
{
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// This file is automatically generated by ABP framework to use MVC Controllers from CSharp
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Http.Client;
using Volo.Abp.Http.Modeling;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Http.Client;
using Volo.Abp.Http.Client.ClientProxying;
using Volo.Abp.Http.Modeling;
using Volo.Abp.PermissionManagement;

// ReSharper disable once CheckNamespace
namespace Volo.Abp.PermissionManagement.ClientProxies;
namespace Volo.Abp.PermissionManagement;

[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(IPermissionAppService), typeof(PermissionsClientProxy))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of PermissionsClientProxy, you can customize it here
// ReSharper disable once CheckNamespace
namespace Volo.Abp.PermissionManagement.ClientProxies;
namespace Volo.Abp.PermissionManagement;

public partial class PermissionsClientProxy
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,74 @@
"Volo.Abp.PermissionManagement.PermissionsController": {
"controllerName": "Permissions",
"controllerGroupName": "Permissions",
"isRemoteService": true,
"isIntegrationService": false,
"apiVersion": null,
"type": "Volo.Abp.PermissionManagement.PermissionsController",
"interfaces": [
{
"type": "Volo.Abp.PermissionManagement.IPermissionAppService"
"type": "Volo.Abp.PermissionManagement.IPermissionAppService",
"name": "IPermissionAppService",
"methods": [
{
"name": "GetAsync",
"parametersOnMethod": [
{
"name": "providerName",
"typeAsString": "System.String, System.Private.CoreLib",
"type": "System.String",
"typeSimple": "string",
"isOptional": false,
"defaultValue": null
},
{
"name": "providerKey",
"typeAsString": "System.String, System.Private.CoreLib",
"type": "System.String",
"typeSimple": "string",
"isOptional": false,
"defaultValue": null
}
],
"returnValue": {
"type": "Volo.Abp.PermissionManagement.GetPermissionListResultDto",
"typeSimple": "Volo.Abp.PermissionManagement.GetPermissionListResultDto"
}
},
{
"name": "UpdateAsync",
"parametersOnMethod": [
{
"name": "providerName",
"typeAsString": "System.String, System.Private.CoreLib",
"type": "System.String",
"typeSimple": "string",
"isOptional": false,
"defaultValue": null
},
{
"name": "providerKey",
"typeAsString": "System.String, System.Private.CoreLib",
"type": "System.String",
"typeSimple": "string",
"isOptional": false,
"defaultValue": null
},
{
"name": "input",
"typeAsString": "Volo.Abp.PermissionManagement.UpdatePermissionsDto, Volo.Abp.PermissionManagement.Application.Contracts",
"type": "Volo.Abp.PermissionManagement.UpdatePermissionsDto",
"typeSimple": "Volo.Abp.PermissionManagement.UpdatePermissionsDto",
"isOptional": false,
"defaultValue": null
}
],
"returnValue": {
"type": "System.Void",
"typeSimple": "System.Void"
}
}
]
}
],
"actions": {
Expand Down Expand Up @@ -149,6 +213,78 @@
"implementFrom": "Volo.Abp.PermissionManagement.IPermissionAppService"
}
}
},
"Volo.Abp.PermissionManagement.Integration.PermissionIntegrationController": {
"controllerName": "PermissionIntegration",
"controllerGroupName": "PermissionIntegration",
"isRemoteService": true,
"isIntegrationService": true,
"apiVersion": null,
"type": "Volo.Abp.PermissionManagement.Integration.PermissionIntegrationController",
"interfaces": [
{
"type": "Volo.Abp.PermissionManagement.Integration.IPermissionIntegrationService",
"name": "IPermissionIntegrationService",
"methods": [
{
"name": "IsGrantedAsync",
"parametersOnMethod": [
{
"name": "input",
"typeAsString": "System.Collections.Generic.List`1[[Volo.Abp.PermissionManagement.Integration.PermissionGrantInput, Volo.Abp.PermissionManagement.Application.Contracts, Version=7.4.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib",
"type": "System.Collections.Generic.List<Volo.Abp.PermissionManagement.Integration.PermissionGrantInput>",
"typeSimple": "[Volo.Abp.PermissionManagement.Integration.PermissionGrantInput]",
"isOptional": false,
"defaultValue": null
}
],
"returnValue": {
"type": "Volo.Abp.Application.Dtos.ListResultDto<Volo.Abp.PermissionManagement.Integration.PermissionGrantOutput>",
"typeSimple": "Volo.Abp.Application.Dtos.ListResultDto<Volo.Abp.PermissionManagement.Integration.PermissionGrantOutput>"
}
}
]
}
],
"actions": {
"IsGrantedAsyncByInput": {
"uniqueName": "IsGrantedAsyncByInput",
"name": "IsGrantedAsync",
"httpMethod": "GET",
"url": "integration-api/permission-management/permissions/is-granted",
"supportedVersions": [],
"parametersOnMethod": [
{
"name": "input",
"typeAsString": "System.Collections.Generic.List`1[[Volo.Abp.PermissionManagement.Integration.PermissionGrantInput, Volo.Abp.PermissionManagement.Application.Contracts, Version=7.4.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib",
"type": "System.Collections.Generic.List<Volo.Abp.PermissionManagement.Integration.PermissionGrantInput>",
"typeSimple": "[Volo.Abp.PermissionManagement.Integration.PermissionGrantInput]",
"isOptional": false,
"defaultValue": null
}
],
"parameters": [
{
"nameOnMethod": "input",
"name": "input",
"jsonName": null,
"type": "System.Collections.Generic.List<Volo.Abp.PermissionManagement.Integration.PermissionGrantInput>",
"typeSimple": "[Volo.Abp.PermissionManagement.Integration.PermissionGrantInput]",
"isOptional": false,
"defaultValue": null,
"constraintTypes": null,
"bindingSourceId": "ModelBinding",
"descriptorName": ""
}
],
"returnValue": {
"type": "Volo.Abp.Application.Dtos.ListResultDto<Volo.Abp.PermissionManagement.Integration.PermissionGrantOutput>",
"typeSimple": "Volo.Abp.Application.Dtos.ListResultDto<Volo.Abp.PermissionManagement.Integration.PermissionGrantOutput>"
},
"allowAnonymous": null,
"implementFrom": "Volo.Abp.PermissionManagement.Integration.IPermissionIntegrationService"
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc;

namespace Volo.Abp.PermissionManagement.Integration;

[RemoteService(Name = PermissionManagementRemoteServiceConsts.RemoteServiceName)]
[Area(PermissionManagementRemoteServiceConsts.ModuleName)]
[ControllerName("PermissionIntegration")]
[Route("integration-api/permission-management/permissions")]
public class PermissionIntegrationController: AbpControllerBase, IPermissionIntegrationService
{
protected IPermissionIntegrationService PermissionIntegrationService { get; }

public PermissionIntegrationController(IPermissionIntegrationService permissionIntegrationService)
{
PermissionIntegrationService = permissionIntegrationService;
}

[HttpGet]
[Route("is-granted")]
public virtual Task<ListResultDto<PermissionGrantOutput>> IsGrantedAsync(List<PermissionGrantInput> input)
{
return PermissionIntegrationService.IsGrantedAsync(input);
}
}

0 comments on commit 631013c

Please sign in to comment.