@@ -7,11 +7,11 @@ package admin
7
7
import (
8
8
"net/http"
9
9
"net/url"
10
+ "strconv"
10
11
"strings"
11
12
12
13
system_model "code.gitea.io/gitea/models/system"
13
14
"code.gitea.io/gitea/modules/base"
14
- "code.gitea.io/gitea/modules/container"
15
15
"code.gitea.io/gitea/modules/context"
16
16
"code.gitea.io/gitea/modules/git"
17
17
"code.gitea.io/gitea/modules/json"
@@ -24,7 +24,10 @@ import (
24
24
"gitea.com/go-chi/session"
25
25
)
26
26
27
- const tplConfig base.TplName = "admin/config"
27
+ const (
28
+ tplConfig base.TplName = "admin/config"
29
+ tplConfigSettings base.TplName = "admin/config_settings"
30
+ )
28
31
29
32
// SendTestMail send test mail to confirm mail service is OK
30
33
func SendTestMail (ctx * context.Context ) {
@@ -98,8 +101,9 @@ func shadowPassword(provider, cfgItem string) string {
98
101
99
102
// Config show admin config page
100
103
func Config (ctx * context.Context ) {
101
- ctx .Data ["Title" ] = ctx .Tr ("admin.config " )
104
+ ctx .Data ["Title" ] = ctx .Tr ("admin.config_summary " )
102
105
ctx .Data ["PageIsAdminConfig" ] = true
106
+ ctx .Data ["PageIsAdminConfigSummary" ] = true
103
107
104
108
ctx .Data ["CustomConf" ] = setting .CustomConf
105
109
ctx .Data ["AppUrl" ] = setting .AppURL
@@ -161,23 +165,70 @@ func Config(ctx *context.Context) {
161
165
162
166
ctx .Data ["Loggers" ] = log .GetManager ().DumpLoggers ()
163
167
config .GetDynGetter ().InvalidateCache ()
164
- ctx .Data ["SystemConfig" ] = setting .Config ()
165
168
prepareDeprecatedWarningsAlert (ctx )
166
169
167
170
ctx .HTML (http .StatusOK , tplConfig )
168
171
}
169
172
173
+ func ConfigSettings (ctx * context.Context ) {
174
+ ctx .Data ["Title" ] = ctx .Tr ("admin.config_settings" )
175
+ ctx .Data ["PageIsAdminConfig" ] = true
176
+ ctx .Data ["PageIsAdminConfigSettings" ] = true
177
+ ctx .Data ["DefaultOpenWithEditorAppsString" ] = setting .DefaultOpenWithEditorApps ().ToTextareaString ()
178
+ ctx .HTML (http .StatusOK , tplConfigSettings )
179
+ }
180
+
170
181
func ChangeConfig (ctx * context.Context ) {
171
182
key := strings .TrimSpace (ctx .FormString ("key" ))
172
183
value := ctx .FormString ("value" )
173
184
cfg := setting .Config ()
174
- allowedKeys := container .SetOf (cfg .Picture .DisableGravatar .DynKey (), cfg .Picture .EnableFederatedAvatar .DynKey ())
175
- if ! allowedKeys .Contains (key ) {
185
+
186
+ marshalBool := func (v string ) (string , error ) {
187
+ if b , _ := strconv .ParseBool (v ); b {
188
+ return "true" , nil
189
+ }
190
+ return "false" , nil
191
+ }
192
+ marshalOpenWithApps := func (value string ) (string , error ) {
193
+ lines := strings .Split (value , "\n " )
194
+ var openWithEditorApps setting.OpenWithEditorAppsType
195
+ for _ , line := range lines {
196
+ line = strings .TrimSpace (line )
197
+ if line == "" {
198
+ continue
199
+ }
200
+ displayName , openURL , ok := strings .Cut (line , "=" )
201
+ displayName , openURL = strings .TrimSpace (displayName ), strings .TrimSpace (openURL )
202
+ if ! ok || displayName == "" || openURL == "" {
203
+ continue
204
+ }
205
+ openWithEditorApps = append (openWithEditorApps , setting.OpenWithEditorApp {
206
+ DisplayName : strings .TrimSpace (displayName ),
207
+ OpenURL : strings .TrimSpace (openURL ),
208
+ })
209
+ }
210
+ b , err := json .Marshal (openWithEditorApps )
211
+ if err != nil {
212
+ return "" , err
213
+ }
214
+ return string (b ), nil
215
+ }
216
+ marshallers := map [string ]func (string ) (string , error ){
217
+ cfg .Picture .DisableGravatar .DynKey (): marshalBool ,
218
+ cfg .Picture .EnableFederatedAvatar .DynKey (): marshalBool ,
219
+ cfg .Repository .OpenWithEditorApps .DynKey (): marshalOpenWithApps ,
220
+ }
221
+ marshaller , hasMarshaller := marshallers [key ]
222
+ if ! hasMarshaller {
223
+ ctx .JSONError (ctx .Tr ("admin.config.set_setting_failed" , key ))
224
+ return
225
+ }
226
+ marshaledValue , err := marshaller (value )
227
+ if err != nil {
176
228
ctx .JSONError (ctx .Tr ("admin.config.set_setting_failed" , key ))
177
229
return
178
230
}
179
- if err := system_model .SetSettings (ctx , map [string ]string {key : value }); err != nil {
180
- log .Error ("set setting failed: %v" , err )
231
+ if err = system_model .SetSettings (ctx , map [string ]string {key : marshaledValue }); err != nil {
181
232
ctx .JSONError (ctx .Tr ("admin.config.set_setting_failed" , key ))
182
233
return
183
234
}
0 commit comments