Add youth mode restriction labels
This commit is contained in:
+48
-6
@@ -8166,12 +8166,13 @@ func appReleasePayload(release *types.AppRelease) map[string]any {
|
||||
|
||||
func youthModePayload(settings *types.YouthModeSettings) map[string]any {
|
||||
data := map[string]any{
|
||||
"enabled": settings.Enabled,
|
||||
"policy_version": settings.PolicyVersion,
|
||||
"restrictions": settings.Restrictions,
|
||||
"password_set": settings.PasswordSet,
|
||||
"can_enable": settings.CanEnable,
|
||||
"updated_at": settings.UpdatedAt.UTC().Format(time.RFC3339Nano),
|
||||
"enabled": settings.Enabled,
|
||||
"policy_version": settings.PolicyVersion,
|
||||
"restrictions": settings.Restrictions,
|
||||
"restriction_items": youthModeRestrictionItems(settings.Restrictions),
|
||||
"password_set": settings.PasswordSet,
|
||||
"can_enable": settings.CanEnable,
|
||||
"updated_at": settings.UpdatedAt.UTC().Format(time.RFC3339Nano),
|
||||
}
|
||||
if settings.EnabledAt != nil {
|
||||
data["enabled_at"] = settings.EnabledAt.UTC().Format(time.RFC3339Nano)
|
||||
@@ -8179,6 +8180,47 @@ func youthModePayload(settings *types.YouthModeSettings) map[string]any {
|
||||
return data
|
||||
}
|
||||
|
||||
func youthModeRestrictionItems(restrictions []string) []map[string]any {
|
||||
catalog := map[string]map[string]any{
|
||||
"night_quiet": {
|
||||
"code": "night_quiet",
|
||||
"title": "深夜免打扰",
|
||||
"description": "夜间减少消息提醒打扰,帮助用户保持健康作息。",
|
||||
"enforced": false,
|
||||
},
|
||||
"content_filter": {
|
||||
"code": "content_filter",
|
||||
"title": "内容过滤",
|
||||
"description": "对不适合青少年的内容进行识别和限制展示。",
|
||||
"enforced": false,
|
||||
},
|
||||
"payment_guard": {
|
||||
"code": "payment_guard",
|
||||
"title": "支付守护",
|
||||
"description": "限制或确认支付、充值等敏感消费行为。",
|
||||
"enforced": false,
|
||||
},
|
||||
}
|
||||
items := make([]map[string]any, 0, len(restrictions))
|
||||
for _, code := range restrictions {
|
||||
code = strings.TrimSpace(code)
|
||||
if code == "" {
|
||||
continue
|
||||
}
|
||||
if item, ok := catalog[code]; ok {
|
||||
items = append(items, item)
|
||||
continue
|
||||
}
|
||||
items = append(items, map[string]any{
|
||||
"code": code,
|
||||
"title": code,
|
||||
"description": "",
|
||||
"enforced": false,
|
||||
})
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func devicePushTokenPayload(token *types.DevicePushToken) map[string]any {
|
||||
return map[string]any{
|
||||
"device_id": token.DeviceID,
|
||||
|
||||
@@ -3186,6 +3186,14 @@ func TestServeIMYouthModeEnableDisable(t *testing.T) {
|
||||
if data["enabled"] != true || data["policy_version"].(float64) != 2 {
|
||||
t.Fatalf("unexpected youth enable payload: %#v", data)
|
||||
}
|
||||
items := data["restriction_items"].([]any)
|
||||
if len(items) != 3 {
|
||||
t.Fatalf("restriction_items: got %#v", items)
|
||||
}
|
||||
firstItem := items[0].(map[string]any)
|
||||
if firstItem["code"] != "night_quiet" || firstItem["title"] != "深夜免打扰" || firstItem["enforced"] != false {
|
||||
t.Fatalf("unexpected restriction item: %#v", firstItem)
|
||||
}
|
||||
|
||||
security.actionToken = &types.ActionToken{Action: "close_youth_mode", Target: "youth_mode"}
|
||||
expectIMBearer(t, ctrl, "token-disable", 7, 42)
|
||||
|
||||
Reference in New Issue
Block a user