This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestAlibabaCloudConfig_Marshal(t *testing.T) {
|
||||
v := new(AlibabaCloudConfig)
|
||||
t.Log(v.Marshal())
|
||||
}
|
||||
|
||||
func TestAlibabaCloudConfig_Unmarshal(t *testing.T) {
|
||||
|
||||
cfg := AlibabaCloudConfig{
|
||||
Access: "AccessKeyId",
|
||||
Secret: "AccessKeySecret",
|
||||
SignName: "SignName",
|
||||
Endpoint: "Endpoint",
|
||||
TemplateCode: "VerifyTemplateCode",
|
||||
}
|
||||
data := cfg.Marshal()
|
||||
v := new(AlibabaCloudConfig)
|
||||
err := v.Unmarshal(data)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
assert.Equal(t, "AccessKeyId", v.Access)
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNormalizeNodeTags(t *testing.T) {
|
||||
tags := normalizeNodeTags([]string{"美国", " 日本 ", "", "美国", " ", "日本"})
|
||||
require.Equal(t, []string{"美国", "日本"}, tags)
|
||||
}
|
||||
@@ -20,6 +20,7 @@ type Subscribe struct {
|
||||
SpeedLimit int64 `gorm:"type:int;not null;default:0;comment:Speed Limit"`
|
||||
DeviceLimit int64 `gorm:"type:int;not null;default:0;comment:Device Limit"`
|
||||
Quota int64 `gorm:"type:int;not null;default:0;comment:Quota"`
|
||||
NewUserOnly *bool `gorm:"type:tinyint(1);default:0;comment:New user only: allow purchase within 24h of registration, once per user"`
|
||||
Nodes string `gorm:"type:varchar(255);comment:Node Ids"`
|
||||
NodeTags string `gorm:"type:varchar(255);comment:Node Tags"`
|
||||
Show *bool `gorm:"type:tinyint(1);not null;default:0;comment:Show portal page"`
|
||||
|
||||
@@ -246,7 +246,7 @@ func (m *customUserModel) BatchDeleteUser(ctx context.Context, ids []int64, tx .
|
||||
if len(tx) > 0 {
|
||||
conn = tx[0]
|
||||
}
|
||||
return conn.Where("id in ?", ids).Find(&users).Error
|
||||
return conn.Where("id in ?", ids).Preload("AuthMethods").Find(&users).Error
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -88,15 +88,18 @@ func (m *defaultUserModel) FindOneSubscribe(ctx context.Context, id int64) (*Sub
|
||||
func (m *defaultUserModel) FindUsersSubscribeBySubscribeId(ctx context.Context, subscribeId int64) ([]*Subscribe, error) {
|
||||
var data []*Subscribe
|
||||
err := m.QueryNoCacheCtx(ctx, &data, func(conn *gorm.DB, v interface{}) error {
|
||||
err := conn.Model(&Subscribe{}).Where("subscribe_id = ? AND `status` IN ?", subscribeId, []int64{1, 0}).Find(v).Error
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// update user subscribe status
|
||||
return conn.Model(&Subscribe{}).Where("subscribe_id = ? AND `status` = ?", subscribeId, 0).Update("status", 1).Error
|
||||
return conn.Model(&Subscribe{}).Where("subscribe_id = ? AND `status` IN ?", subscribeId, []int64{1, 0}).Find(v).Error
|
||||
})
|
||||
return data, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Activate pending subscribes (status 0 -> 1) in a separate write operation
|
||||
if err := m.ExecNoCacheCtx(ctx, func(conn *gorm.DB) error {
|
||||
return conn.Model(&Subscribe{}).Where("subscribe_id = ? AND `status` = ?", subscribeId, 0).Update("status", 1).Error
|
||||
}); err != nil {
|
||||
return data, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// QueryUserSubscribe returns a list of records that meet the conditions.
|
||||
@@ -136,6 +139,7 @@ func (m *defaultUserModel) QueryUserSubscribe(ctx context.Context, userId int64,
|
||||
func (m *defaultUserModel) FindOneUserSubscribe(ctx context.Context, id int64) (subscribeDetails *SubscribeDetails, err error) {
|
||||
//TODO cache
|
||||
//key := fmt.Sprintf("%s%d", cacheUserSubscribeUserPrefix, userId)
|
||||
subscribeDetails = &SubscribeDetails{}
|
||||
err = m.QueryNoCacheCtx(ctx, subscribeDetails, func(conn *gorm.DB, v interface{}) error {
|
||||
return conn.Model(&Subscribe{}).Preload("Subscribe").Where("id = ?", id).First(&subscribeDetails).Error
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user