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