Skip to content

Commit

Permalink
Merge pull request #68 from EasyAbp/redesigned-management-permissions
Browse files Browse the repository at this point in the history
Redesign management permissions as read-write separation
  • Loading branch information
gdlcf88 authored Oct 31, 2023
2 parents f77aca2 + 5ca3e91 commit 6a62f64
Show file tree
Hide file tree
Showing 37 changed files with 181 additions and 38 deletions.
2 changes: 1 addition & 1 deletion common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>2.8.0</Version>
<Version>2.9.0</Version>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>EasyAbp Team</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ public class PrepaymentPermissionDefinitionProvider : PermissionDefinitionProvid
{
public override void Define(IPermissionDefinitionContext context)
{
var myGroup = context.AddGroup(PrepaymentPermissions.GroupName, L("Permission:Prepayment"));
var myGroup = context.AddGroup(PrepaymentPermissions.GroupName, L("Permission:PaymentServicePrepayment"));

var accountPermission = myGroup.AddPermission(PrepaymentPermissions.Account.Default, L("Permission:Account"));
accountPermission.AddChild(PrepaymentPermissions.Account.Manage, L("Permission:Manage"));
accountPermission.AddChild(PrepaymentPermissions.Account.Manage.ManageDefault, L("Permission:Manage"));
accountPermission.AddChild(PrepaymentPermissions.Account.Manage.ChangeBalance, L("Permission:ChangeBalance"));
accountPermission.AddChild(PrepaymentPermissions.Account.Manage.ChangeLockedBalance, L("Permission:ChangeLockedBalance"));
accountPermission.AddChild(PrepaymentPermissions.Account.TopUp, L("Permission:TopUp"));
accountPermission.AddChild(PrepaymentPermissions.Account.Withdraw, L("Permission:Withdraw"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ public static string[] GetAll()
public class Account
{
public const string Default = GroupName + ".Account";
public const string Manage = Default + ".Manage";
public const string TopUp = Default + ".TopUp";
public const string Withdraw = Default + ".Withdraw";

public class Manage
{
public const string ManageDefault = Default + ".Manage";
public const string ChangeBalance = ManageDefault + ".ChangeBalance";
public const string ChangeLockedBalance = ManageDefault + ".ChangeLockedBalance";
}
}

public class Transaction
Expand All @@ -38,4 +44,4 @@ public class WithdrawalRequest
public const string Review = Default + ".Review";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override async Task<AccountDto> GetAsync(Guid id)

if (dto.UserId != CurrentUser.GetId())
{
await AuthorizationService.CheckAsync(PrepaymentPermissions.Account.Manage);
await AuthorizationService.CheckAsync(PrepaymentPermissions.Account.Manage.ManageDefault);
}

return dto;
Expand All @@ -68,7 +68,7 @@ public override async Task<PagedResultDto<AccountDto>> GetListAsync(GetAccountLi
{
if (input.UserId != CurrentUser.GetId())
{
await AuthorizationService.CheckAsync(PrepaymentPermissions.Account.Manage);
await AuthorizationService.CheckAsync(PrepaymentPermissions.Account.Manage.ManageDefault);
}

var result = await base.GetListAsync(input);
Expand Down Expand Up @@ -97,7 +97,7 @@ await _repository.InsertAsync(new Account(GuidGenerator.Create(), CurrentTenant.
return result;
}

[Authorize(PrepaymentPermissions.Account.Manage)]
[Authorize(PrepaymentPermissions.Account.Manage.ChangeBalance)]
public virtual async Task<AccountDto> ChangeBalanceAsync(Guid id, ChangeBalanceInput input)
{
var account = await _repository.GetAsync(id);
Expand All @@ -120,7 +120,7 @@ public virtual async Task<AccountDto> ChangeBalanceAsync(Guid id, ChangeBalanceI
return await MapToGetOutputDtoAsync(account);
}

[Authorize(PrepaymentPermissions.Account.Manage)]
[Authorize(PrepaymentPermissions.Account.Manage.ChangeLockedBalance)]
public virtual async Task<AccountDto> ChangeLockedBalanceAsync(Guid id, ChangeLockedBalanceInput input)
{
var account = await _repository.GetAsync(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
"texts": {
"Menu:PaymentService": "Payment service",
"Menu:PrepaymentManagement": "Prepayment",
"Permission:PaymentServicePrepayment": "Payment service - Prepayment",
"Permission:Account": "Account",
"Permission:Create": "Create",
"Permission:Update": "Update",
"Permission:Delete": "Delete",
"Permission:Manage": "Manage",
"Permission:ChangeBalance": "Change balance",
"Permission:ChangeLockedBalance": "Changed locked balance",
"Permission:TopUp": "TopUp",
"Permission:Withdraw": "Withdraw",
"Permission:Review": "Review",
"Menu:Account": "Account",
"Account": "Account",
"AccountAccountGroupName": "Account group name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
"texts": {
"Menu:PaymentService": "Payment service",
"Menu:PrepaymentManagement": "Prepayment",
"Permission:PaymentServicePrepayment": "Payment service - Prepayment",
"Permission:Account": "Account",
"Permission:Create": "Create",
"Permission:Update": "Update",
"Permission:Delete": "Delete",
"Permission:Manage": "Manage",
"Permission:ChangeBalance": "Change balance",
"Permission:ChangeLockedBalance": "Changed locked balance",
"Permission:TopUp": "TopUp",
"Permission:Withdraw": "Withdraw",
"Permission:Review": "Review",
"Menu:Account": "Account",
"Account": "Account",
"AccountAccountGroupName": "Account group name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
"texts": {
"Menu:PaymentService": "Payment service",
"Menu:PrepaymentManagement": "Prepayment",
"Permission:PaymentServicePrepayment": "Payment service - Prepayment",
"Permission:Account": "Account",
"Permission:Create": "Create",
"Permission:Update": "Update",
"Permission:Delete": "Delete",
"Permission:Manage": "Manage",
"Permission:ChangeBalance": "Change balance",
"Permission:ChangeLockedBalance": "Changed locked balance",
"Permission:TopUp": "TopUp",
"Permission:Withdraw": "Withdraw",
"Permission:Review": "Review",
"Menu:Account": "Account",
"Account": "Account",
"AccountAccountGroupName": "Account group name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
"texts": {
"Menu:PaymentService": "Payment service",
"Menu:PrepaymentManagement": "Prepayment",
"Permission:PaymentServicePrepayment": "Payment service - Prepayment",
"Permission:Account": "Account",
"Permission:Create": "Create",
"Permission:Update": "Update",
"Permission:Delete": "Delete",
"Permission:Manage": "Manage",
"Permission:ChangeBalance": "Change balance",
"Permission:ChangeLockedBalance": "Changed locked balance",
"Permission:TopUp": "TopUp",
"Permission:Withdraw": "Withdraw",
"Permission:Review": "Review",
"Menu:Account": "Account",
"Account": "Account",
"AccountAccountGroupName": "Account group name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
"texts": {
"Menu:PaymentService": "Payment service",
"Menu:PrepaymentManagement": "Prepayment",
"Permission:PaymentServicePrepayment": "Payment service - Prepayment",
"Permission:Account": "Account",
"Permission:Create": "Create",
"Permission:Update": "Update",
"Permission:Delete": "Delete",
"Permission:Manage": "Manage",
"Permission:ChangeBalance": "Change balance",
"Permission:ChangeLockedBalance": "Changed locked balance",
"Permission:TopUp": "TopUp",
"Permission:Withdraw": "Withdraw",
"Permission:Review": "Review",
"Menu:Account": "Account",
"Account": "Account",
"AccountAccountGroupName": "Account group name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
"texts": {
"Menu:PaymentService": "Payment service",
"Menu:PrepaymentManagement": "Prepayment",
"Permission:PaymentServicePrepayment": "Payment service - Prepayment",
"Permission:Account": "Account",
"Permission:Create": "Create",
"Permission:Update": "Update",
"Permission:Delete": "Delete",
"Permission:Manage": "Manage",
"Permission:ChangeBalance": "Change balance",
"Permission:ChangeLockedBalance": "Changed locked balance",
"Permission:TopUp": "TopUp",
"Permission:Withdraw": "Withdraw",
"Permission:Review": "Review",
"Menu:Account": "Account",
"Account": "Account",
"AccountAccountGroupName": "Account group name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
"texts": {
"Menu:PaymentService": "Payment service",
"Menu:PrepaymentManagement": "Prepayment",
"Permission:PaymentServicePrepayment": "Payment service - Prepayment",
"Permission:Account": "Account",
"Permission:Create": "Create",
"Permission:Update": "Update",
"Permission:Delete": "Delete",
"Permission:Manage": "Manage",
"Permission:ChangeBalance": "Change balance",
"Permission:ChangeLockedBalance": "Changed locked balance",
"Permission:TopUp": "TopUp",
"Permission:Withdraw": "Withdraw",
"Permission:Review": "Review",
"Menu:Account": "Account",
"Account": "Account",
"AccountAccountGroupName": "Account group name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
"texts": {
"Menu:PaymentService": "支付服务",
"Menu:PrepaymentManagement": "储值卡",
"Permission:PaymentServicePrepayment": "支付服务 - 储值卡",
"Permission:Account": "账户",
"Permission:Create": "新建",
"Permission:Update": "编辑",
"Permission:Delete": "删除",
"Permission:Manage": "管理",
"Permission:ChangeBalance": "调整余额",
"Permission:ChangeLockedBalance": "调整锁定余额",
"Permission:TopUp": "充值",
"Permission:Withdraw": "提现",
"Permission:Review": "审核",
"Menu:Account": "账户",
"Account": "账户",
"AccountAccountGroupName": "账户组",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
"texts": {
"Menu:PaymentService": "支付服務",
"Menu:PrepaymentManagement": "儲值卡",
"Permission:PaymentServicePrepayment": "支付服務 - 儲值卡",
"Permission:Account": "賬戶",
"Permission:Create": "新建",
"Permission:Update": "編輯",
"Permission:Delete": "刪除",
"Permission:Manage": "管理",
"Permission:ChangeBalance": "調整餘額",
"Permission:ChangeLockedBalance": "調整鎖定餘額",
"Permission:TopUp": "充值",
"Permission:Withdraw": "提現",
"Permission:Review": "審核",
"Menu:Account": "賬戶",
"Account": "賬戶",
"AccountAccountGroupName": "賬戶組",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private async Task ConfigureMainMenu(MenuConfigurationContext context)

var prepaymentManagementMenuItem = new ApplicationMenuItem(PrepaymentMenus.Prefix, l["Menu:PrepaymentManagement"]);

if (await context.IsGrantedAsync(PrepaymentPermissions.Account.Manage))
if (await context.IsGrantedAsync(PrepaymentPermissions.Account.Manage.ManageDefault))
{
prepaymentManagementMenuItem.AddItem(
new ApplicationMenuItem(PrepaymentMenus.Account, l["Menu:Account"], "/PaymentService/Prepayment/Accounts/Account")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class WeChatPayPermissionDefinitionProvider : PermissionDefinitionProvide
{
public override void Define(IPermissionDefinitionContext context)
{
var moduleGroup = context.AddGroup(WeChatPayPermissions.GroupName, L("Permission:WeChatPay"));
var moduleGroup = context.AddGroup(WeChatPayPermissions.GroupName, L("Permission:PaymentServiceWeChatPay"));

var paymentRecord = moduleGroup.AddPermission(WeChatPayPermissions.PaymentRecords.Default,
L("Permission:PaymentRecord"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"Menu:PaymentService": "Payment service",
"Menu:WeChatPayManagement": "WeChat Pay",
"Menu:RefundRecord": "Refund record",
"Permission:PaymentServiceWeChatPay": "Payment service - WeChat Pay",
"Permission:PaymentRecord": "PaymentRecord",
"Permission:RefundRecord": "RefundRecord",
"RefundRecord": "Refund record",
"RefundRecordPaymentId": "Payment ID",
"RefundRecordReturnCode": "ReturnCode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"Menu:PaymentService": "Payment service",
"Menu:WeChatPayManagement": "WeChat Pay",
"Menu:RefundRecord": "Refund record",
"Permission:PaymentServiceWeChatPay": "Payment service - WeChat Pay",
"Permission:PaymentRecord": "PaymentRecord",
"Permission:RefundRecord": "RefundRecord",
"RefundRecord": "Refund record",
"RefundRecordPaymentId": "Payment ID",
"RefundRecordReturnCode": "ReturnCode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"Menu:PaymentService": "Payment service",
"Menu:WeChatPayManagement": "WeChat Pay",
"Menu:RefundRecord": "Refund record",
"Permission:PaymentServiceWeChatPay": "Payment service - WeChat Pay",
"Permission:PaymentRecord": "PaymentRecord",
"Permission:RefundRecord": "RefundRecord",
"RefundRecord": "Refund record",
"RefundRecordPaymentId": "Payment ID",
"RefundRecordReturnCode": "ReturnCode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"Menu:PaymentService": "Payment service",
"Menu:WeChatPayManagement": "WeChat Pay",
"Menu:RefundRecord": "Refund record",
"Permission:PaymentServiceWeChatPay": "Payment service - WeChat Pay",
"Permission:PaymentRecord": "PaymentRecord",
"Permission:RefundRecord": "RefundRecord",
"RefundRecord": "Refund record",
"RefundRecordPaymentId": "Payment ID",
"RefundRecordReturnCode": "ReturnCode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"Menu:PaymentService": "Payment service",
"Menu:WeChatPayManagement": "WeChat Pay",
"Menu:RefundRecord": "Refund record",
"Permission:PaymentServiceWeChatPay": "Payment service - WeChat Pay",
"Permission:PaymentRecord": "PaymentRecord",
"Permission:RefundRecord": "RefundRecord",
"RefundRecord": "Refund record",
"RefundRecordPaymentId": "Payment ID",
"RefundRecordReturnCode": "ReturnCode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"Menu:PaymentService": "Payment service",
"Menu:WeChatPayManagement": "WeChat Pay",
"Menu:RefundRecord": "Refund record",
"Permission:PaymentServiceWeChatPay": "Payment service - WeChat Pay",
"Permission:PaymentRecord": "PaymentRecord",
"Permission:RefundRecord": "RefundRecord",
"RefundRecord": "Refund record",
"RefundRecordPaymentId": "Payment ID",
"RefundRecordReturnCode": "ReturnCode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"Menu:PaymentService": "Payment service",
"Menu:WeChatPayManagement": "WeChat Pay",
"Menu:RefundRecord": "Refund record",
"Permission:PaymentServiceWeChatPay": "Payment service - WeChat Pay",
"Permission:PaymentRecord": "PaymentRecord",
"Permission:RefundRecord": "RefundRecord",
"RefundRecord": "Refund record",
"RefundRecordPaymentId": "Payment ID",
"RefundRecordReturnCode": "ReturnCode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"Menu:PaymentService": "支付服务",
"Menu:WeChatPayManagement": "微信支付",
"Menu:RefundRecord": "退款记录",
"Permission:PaymentServiceWeChatPay": "支付服务 - 微信支付",
"Permission:PaymentRecord": "支付记录",
"Permission:RefundRecord": "退款记录",
"RefundRecord": "退款记录",
"RefundRecordPaymentId": "支付 ID",
"RefundRecordReturnCode": "ReturnCode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"Menu:PaymentService": "支付服務",
"Menu:WeChatPayManagement": "微信支付",
"Menu:RefundRecord": "退款記錄",
"Permission:PaymentServiceWeChatPay": "支付服務 - 微信支付",
"Permission:PaymentRecord": "付款記錄",
"Permission:RefundRecord": "退款紀錄",
"RefundRecord": "退款記錄",
"RefundRecordPaymentId": "支付 ID",
"RefundRecordReturnCode": "ReturnCode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@ public override void Define(IPermissionDefinitionContext context)
var moduleGroup = context.AddGroup(PaymentServicePermissions.GroupName, L("Permission:PaymentService"));

var payment = moduleGroup.AddPermission(PaymentServicePermissions.Payments.Default, L("Permission:Payment"));
payment.AddChild(PaymentServicePermissions.Payments.Manage, L("Permission:Manage"));
payment.AddChild(PaymentServicePermissions.Payments.Create, L("Permission:Create"));
payment.AddChild(PaymentServicePermissions.Payments.Manage.ManageDefault, L("Permission:Manage"));
payment.AddChild(PaymentServicePermissions.Payments.Manage.Cancel, L("Permission:Cancel"));
payment.AddChild(PaymentServicePermissions.Payments.Manage.RollbackRefund, L("Permission:RollbackRefund"));

var refund = moduleGroup.AddPermission(PaymentServicePermissions.Refunds.Default, L("Permission:Refund"));
refund.AddChild(PaymentServicePermissions.Refunds.Manage, L("Permission:Manage"));
refund.AddChild(PaymentServicePermissions.Refunds.Create, L("Permission:Create"));

var withdrawalRecordPermission = moduleGroup.AddPermission(PaymentServicePermissions.WithdrawalRecord.Default, L("Permission:WithdrawalRecord"));
withdrawalRecordPermission.AddChild(PaymentServicePermissions.WithdrawalRecord.Create, L("Permission:Create"));
withdrawalRecordPermission.AddChild(PaymentServicePermissions.WithdrawalRecord.Update, L("Permission:Update"));
withdrawalRecordPermission.AddChild(PaymentServicePermissions.WithdrawalRecord.Delete, L("Permission:Delete"));
}

private static LocalizableString L(string name)
Expand Down
Loading

0 comments on commit 6a62f64

Please sign in to comment.