Disable manager resource grants by default
This commit is contained in:
parent
919364d4d0
commit
e50d273ae2
8
scripts/mysql/039_disable_manager_resource_grants.sql
Normal file
8
scripts/mysql/039_disable_manager_resource_grants.sql
Normal file
@ -0,0 +1,8 @@
|
||||
USE hyapp_wallet;
|
||||
|
||||
ALTER TABLE resources
|
||||
MODIFY COLUMN manager_grant_enabled BOOLEAN NOT NULL DEFAULT FALSE COMMENT '管理端是否允许发放';
|
||||
|
||||
UPDATE resources
|
||||
SET manager_grant_enabled = FALSE
|
||||
WHERE manager_grant_enabled <> FALSE;
|
||||
@ -460,7 +460,7 @@ func (r resourceShopItemsRequest) upsertProto(c *gin.Context) *walletv1.UpsertRe
|
||||
}
|
||||
|
||||
func managerGrantEnabledOrDefault(value *bool) *bool {
|
||||
enabled := true
|
||||
enabled := false
|
||||
if value != nil {
|
||||
enabled = *value
|
||||
}
|
||||
|
||||
@ -52,6 +52,38 @@ func TestGiftRequestProtoClearsCPRelationTypeForNonCPGift(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceRequestDefaultsManagerGrantDisabled(t *testing.T) {
|
||||
req := resourceRequest{
|
||||
ResourceCode: "badge_default_manager_disabled",
|
||||
ResourceType: resourceTypeBadge,
|
||||
Name: "Default Manager Disabled Badge",
|
||||
Status: "active",
|
||||
}
|
||||
|
||||
proto := req.createProto(newGiftRequestTestContext())
|
||||
|
||||
if proto.ManagerGrantEnabled == nil || proto.GetManagerGrantEnabled() {
|
||||
t.Fatalf("manager grant should default to disabled, got %v", proto.GetManagerGrantEnabled())
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceRequestKeepsExplicitManagerGrantEnabled(t *testing.T) {
|
||||
enabled := true
|
||||
req := resourceRequest{
|
||||
ResourceCode: "badge_manager_enabled",
|
||||
ResourceType: resourceTypeBadge,
|
||||
Name: "Manager Enabled Badge",
|
||||
Status: "active",
|
||||
ManagerGrantEnabled: &enabled,
|
||||
}
|
||||
|
||||
proto := req.createProto(newGiftRequestTestContext())
|
||||
|
||||
if proto.ManagerGrantEnabled == nil || !proto.GetManagerGrantEnabled() {
|
||||
t.Fatalf("explicit manager grant enabled should be preserved, got %v", proto.GetManagerGrantEnabled())
|
||||
}
|
||||
}
|
||||
|
||||
func newGiftRequestTestContext() *gin.Context {
|
||||
gin.SetMode(gin.TestMode)
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
@ -584,7 +584,7 @@ CREATE TABLE IF NOT EXISTS resources (
|
||||
name VARCHAR(128) NOT NULL COMMENT '名称',
|
||||
status VARCHAR(32) NOT NULL COMMENT '业务状态',
|
||||
grantable BOOLEAN NOT NULL DEFAULT TRUE COMMENT '是否允许发放',
|
||||
manager_grant_enabled BOOLEAN NOT NULL DEFAULT TRUE COMMENT '管理端是否允许发放',
|
||||
manager_grant_enabled BOOLEAN NOT NULL DEFAULT FALSE COMMENT '管理端是否允许发放',
|
||||
grant_strategy VARCHAR(32) NOT NULL COMMENT '发放策略',
|
||||
wallet_asset_type VARCHAR(32) NOT NULL DEFAULT '' COMMENT '钱包资产类型',
|
||||
wallet_asset_amount BIGINT NOT NULL DEFAULT 0 COMMENT '钱包资产数量',
|
||||
@ -608,7 +608,7 @@ CREATE TABLE IF NOT EXISTS resources (
|
||||
|
||||
SET @ddl := IF(
|
||||
(SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'resources' AND COLUMN_NAME = 'manager_grant_enabled') = 0,
|
||||
'ALTER TABLE resources ADD COLUMN manager_grant_enabled BOOLEAN NOT NULL DEFAULT TRUE COMMENT ''管理端是否允许发放'' AFTER grantable',
|
||||
'ALTER TABLE resources ADD COLUMN manager_grant_enabled BOOLEAN NOT NULL DEFAULT FALSE COMMENT ''管理端是否允许发放'' AFTER grantable',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE stmt FROM @ddl;
|
||||
|
||||
@ -619,8 +619,8 @@ func resourceShopPurchaseReceiptToProto(receipt resourcedomain.ResourceShopPurch
|
||||
|
||||
func managerGrantEnabledOrDefault(value *bool) bool {
|
||||
if value == nil {
|
||||
// 新建/编辑入口如果没显式携带开关,仍按产品规则默认允许经理中心赠送。
|
||||
return true
|
||||
// 新建/编辑入口如果没显式携带开关,按产品规则默认关闭经理中心赠送。
|
||||
return false
|
||||
}
|
||||
return *value
|
||||
}
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
walletv1 "hyapp.local/api/proto/wallet/v1"
|
||||
)
|
||||
|
||||
func TestResourceCommandDefaultsManagerGrantDisabled(t *testing.T) {
|
||||
command := resourceCommandFromCreate(&walletv1.CreateResourceRequest{
|
||||
ResourceCode: "badge_default_manager_disabled",
|
||||
ResourceType: "badge",
|
||||
Name: "Default Manager Disabled Badge",
|
||||
Status: "active",
|
||||
Grantable: true,
|
||||
})
|
||||
|
||||
if command.ManagerGrantEnabled {
|
||||
t.Fatalf("manager grant should default to disabled")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceCommandKeepsExplicitManagerGrantEnabled(t *testing.T) {
|
||||
enabled := true
|
||||
command := resourceCommandFromCreate(&walletv1.CreateResourceRequest{
|
||||
ResourceCode: "badge_manager_enabled",
|
||||
ResourceType: "badge",
|
||||
Name: "Manager Enabled Badge",
|
||||
Status: "active",
|
||||
Grantable: true,
|
||||
ManagerGrantEnabled: &enabled,
|
||||
})
|
||||
|
||||
if !command.ManagerGrantEnabled {
|
||||
t.Fatalf("explicit manager grant enabled should be preserved")
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user