From 94a7790d61fb4af7d5ee460f17fb8bfcdbed7d9e Mon Sep 17 00:00:00 2001 From: okatu-loli Date: Mon, 18 Aug 2025 14:55:38 +0800 Subject: [PATCH] feat(register-and-statistics): improve role handling logic - Switch from role names to role IDs for better consistency. - Update logic to prioritize "guest" for default role ID. - Adjust `DefaultRole` setting to use role IDs. - Refactor `getRoleOptions` to return role IDs as a comma-separated string. --- internal/bootstrap/data/setting.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/bootstrap/data/setting.go b/internal/bootstrap/data/setting.go index 0b4a366c..39c3b1be 100644 --- a/internal/bootstrap/data/setting.go +++ b/internal/bootstrap/data/setting.go @@ -97,8 +97,15 @@ func InitialSettings() []model.SettingItem { utils.Log.Fatalf("failed get roles: %+v", err) } roleNames := make([]string, len(roles)) + defaultRoleID := "" for i, role := range roles { roleNames[i] = role.Name + if role.Name == "guest" { + defaultRoleID = strconv.Itoa(int(role.ID)) + } + } + if defaultRoleID == "" && len(roles) > 0 { + defaultRoleID = strconv.Itoa(int(roles[0].ID)) } initialSettingItems = []model.SettingItem{ // site settings @@ -113,7 +120,7 @@ func InitialSettings() []model.SettingItem { {Key: conf.AllowMounted, Value: "true", Type: conf.TypeBool, Group: model.SITE}, {Key: conf.RobotsTxt, Value: "User-agent: *\nAllow: /", Type: conf.TypeText, Group: model.SITE}, {Key: conf.AllowRegister, Value: "false", Type: conf.TypeBool, Group: model.SITE}, - {Key: conf.DefaultRole, Value: "guest", Type: conf.TypeSelect, Options: strings.Join(roleNames, ","), Group: model.SITE}, + {Key: conf.DefaultRole, Value: defaultRoleID, Type: conf.TypeSelect, Options: strings.Join(roleNames, ","), Group: model.SITE}, // newui settings {Key: conf.UseNewui, Value: "false", Type: conf.TypeBool, Group: model.SITE}, // style settings