修复节点无法编辑的错误
This commit is contained in:
@@ -18,6 +18,8 @@ func ipv6StatusPresentation(status string, allowed bool) (string, string, string
|
||||
switch status {
|
||||
case "active":
|
||||
return "active", "IPv6 enabled", ""
|
||||
case "disabled":
|
||||
return "disabled", "IPv6 disabled", ""
|
||||
case "eligible":
|
||||
return "eligible", "Ready to enable", ""
|
||||
case "", "not_allowed", "not_eligible", "disallowed":
|
||||
@@ -233,7 +235,7 @@ func AdminIPv6SubscriptionUsers(c *gin.Context) {
|
||||
planNameValue := planNames[shadowPlanID]
|
||||
if hasShadowUser {
|
||||
planID = intFromPointer(shadowUser.PlanID)
|
||||
planNameValue = planName(shadowUser.Plan)
|
||||
planNameValue = firstString(planName(shadowUser.Plan), planNames[planID])
|
||||
}
|
||||
shadowUserID := 0
|
||||
shadowUpdatedAt := int64(0)
|
||||
@@ -346,6 +348,11 @@ func AdminIPv6SubscriptionEnable(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var payload struct {
|
||||
PlanID int `json:"plan_id"`
|
||||
}
|
||||
_ = c.ShouldBindJSON(&payload)
|
||||
|
||||
var user model.User
|
||||
if err := database.DB.Preload("Plan").First(&user, userID).Error; err != nil {
|
||||
Fail(c, 404, "user not found")
|
||||
@@ -356,14 +363,35 @@ func AdminIPv6SubscriptionEnable(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if !service.SyncIPv6ShadowAccount(&user) {
|
||||
Fail(c, 403, "user plan does not support ipv6 subscription")
|
||||
if !service.SyncIPv6ShadowAccountWithPlan(&user, payload.PlanID) {
|
||||
Fail(c, 500, "failed to create/sync IPv6 subscription")
|
||||
return
|
||||
}
|
||||
|
||||
SuccessMessage(c, "IPv6 subscription enabled/synced", true)
|
||||
}
|
||||
|
||||
func AdminIPv6SubscriptionDisable(c *gin.Context) {
|
||||
userID := parsePositiveInt(c.Param("userId"), 0)
|
||||
if userID == 0 {
|
||||
Fail(c, 400, "invalid user id")
|
||||
return
|
||||
}
|
||||
|
||||
var user model.User
|
||||
if err := database.DB.First(&user, userID).Error; err != nil {
|
||||
Fail(c, 404, "user not found")
|
||||
return
|
||||
}
|
||||
|
||||
if !service.DisableIPv6ShadowAccount(&user) {
|
||||
Fail(c, 500, "failed to disable IPv6 subscription")
|
||||
return
|
||||
}
|
||||
|
||||
SuccessMessage(c, "IPv6 subscription disabled", true)
|
||||
}
|
||||
|
||||
func AdminIPv6SubscriptionSyncPassword(c *gin.Context) {
|
||||
userID := parsePositiveInt(c.Param("userId"), 0)
|
||||
if userID == 0 {
|
||||
|
||||
Reference in New Issue
Block a user