Skip to content

Commit ad47535

Browse files
committed
Disabling application elements fixed
Gitea does not remove all elements (UI, cron tasks) of some disabled features which makes UI unnecessarily complicated. This mod removes these unnecessary elements from UI/cron: * token edition in user settings is not available when ENABLE_SWAGGER=false, * application tab is not available in user settings if swagger and oauth2 are both disabled, * SSH keys editor is not displayed if SSH is disabled and tab name changed to more general "Keys", * resync_all_sshkeys cron task is disabled if SSH is disabled, * deploy keys tab is not displayed if SSH is disabled, * git hook access option hidden in user settings when git hooks are disabled, * git hook sync cron task removed when git hooks are disabled. Author-Change-Id: IB#1105071
1 parent 95ff559 commit ad47535

37 files changed

+56
-46
lines changed

modules/cron/tasks_extended.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,12 @@ func initExtendedTasks() {
111111
registerDeleteInactiveUsers()
112112
registerDeleteRepositoryArchives()
113113
registerGarbageCollectRepositories()
114-
registerRewriteAllPublicKeys()
115-
registerRepositoryUpdateHook()
114+
if !setting.SSH.Disabled {
115+
registerRewriteAllPublicKeys()
116+
}
117+
if !setting.DisableGitHooks {
118+
registerRepositoryUpdateHook()
119+
}
116120
registerReinitMissingRepositories()
117121
registerDeleteMissingRepositories()
118122
registerRemoveRandomAvatars()

modules/templates/helper.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,15 @@ func NewFuncMap() []template.FuncMap {
228228
"DisableImportLocal": func() bool {
229229
return !setting.ImportLocalPaths
230230
},
231+
"DisableSSH": func() bool {
232+
return setting.SSH.Disabled
233+
},
234+
"DisableSwagger": func() bool {
235+
return !setting.API.EnableSwagger
236+
},
237+
"DisableOAuth2": func() bool {
238+
return !setting.OAuth2.Enable
239+
},
231240
"TrN": TrN,
232241
"Dict": func(values ...interface{}) (map[string]interface{}, error) {
233242
if len(values)%2 != 0 {

options/locale/locale_bg-BG.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ account=Профил
358358
password=Парола
359359
security=Сигурност
360360
avatar=Аватар
361-
ssh_gpg_keys=SSH / GPG ключове
362361
social=Социални профили
363362
applications=Приложения
364363
orgs=Управление на организации

options/locale/locale_cs-CZ.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ account=Účet
410410
password=Heslo
411411
security=Zabezpečení
412412
avatar=Avatar
413-
ssh_gpg_keys=SSH / GPG klíče
414413
social=Účty sociálních sítí
415414
applications=Aplikace
416415
orgs=Spravovat organizace

options/locale/locale_de-DE.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ account=Account
412412
password=Passwort
413413
security=Sicherheit
414414
avatar=Profilbild
415-
ssh_gpg_keys=SSH- / GPG-Schlüssel
416415
social=Soziale Konten
417416
applications=Anwendungen
418417
orgs=Organisationen verwalten

options/locale/locale_en-US.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ account = Account
417417
password = Password
418418
security = Security
419419
avatar = Avatar
420-
ssh_gpg_keys = SSH / GPG Keys
420+
keys = Keys
421421
social = Social Accounts
422422
applications = Applications
423423
orgs = Manage Organizations

options/locale/locale_es-ES.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ account=Cuenta
412412
password=Contraseña
413413
security=Seguridad
414414
avatar=Avatar
415-
ssh_gpg_keys=SSH / claves GPG
416415
social=Redes Sociales
417416
applications=Aplicaciones
418417
orgs=Administrar organizaciones

options/locale/locale_fa-IR.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ account=حساب کاربری
407407
password=گذرواژه
408408
security=امنیت
409409
avatar=آواتار
410-
ssh_gpg_keys=کلید‌های SSH / GPG
411410
social=حساب های اجتماعی
412411
applications=برنامه‌ها
413412
orgs=مدیریت سازمان‌ها

options/locale/locale_fi-FI.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ account=Tili
348348
password=Salasana
349349
security=Turvallisuus
350350
avatar=Profiilikuva
351-
ssh_gpg_keys=SSH / GPG-avaimet
352351
social=Sosiaaliset tilit
353352
applications=Sovellukset
354353
orgs=Hallitse organisaatioita

options/locale/locale_fr-FR.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ account=Compte
394394
password=Mot de passe
395395
security=Sécurité
396396
avatar=Avatar
397-
ssh_gpg_keys=Clés SSH / GPG
398397
social=Réseaux Sociaux
399398
applications=Applications
400399
orgs=Gérer les organisations

options/locale/locale_hu-HU.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ account=Fiók
380380
password=Jelszó
381381
security=Biztonság
382382
avatar=Profilkép
383-
ssh_gpg_keys=SSH / GPG kulcsok
384383
social=Közösségi fiókok
385384
applications=Alkalmazások
386385
orgs=Szervezetek kezelése

options/locale/locale_id-ID.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@ account=Akun
384384
password=Kata Sandi
385385
security=Keamanan
386386
avatar=Avatar
387-
ssh_gpg_keys=Kunci SSH / GPG
388387
social=Akun Sosial
389388
applications=Aplikasi
390389
orgs=Kelola organisasi

options/locale/locale_it-IT.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ account=Account
388388
password=Password
389389
security=Sicurezza
390390
avatar=Avatar
391-
ssh_gpg_keys=Chiavi SSH / GPG
392391
social=Account Sociali
393392
applications=Applicazioni
394393
orgs=Gestisci le organizzazioni

options/locale/locale_ja-JP.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ account=アカウント
412412
password=パスワード
413413
security=セキュリティ
414414
avatar=アバター
415-
ssh_gpg_keys=SSH / GPGキー
416415
social=ソーシャルアカウント
417416
applications=アプリケーション
418417
orgs=組織の管理

options/locale/locale_ko-KR.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ account=계정
365365
password=비밀번호
366366
security=보안
367367
avatar=아바타
368-
ssh_gpg_keys=SSH / GPG 키
369368
social=소셜 계정
370369
applications=어플리케이션
371370
orgs=조직 관리

options/locale/locale_lv-LV.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ account=Konts
412412
password=Parole
413413
security=Drošība
414414
avatar=Profila attēls
415-
ssh_gpg_keys=SSH / GPG atslēgas
416415
social=Sociālie konti
417416
applications=Lietotnes
418417
orgs=Pārvaldīt organizācijas

options/locale/locale_ml-IN.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,6 @@ account=അക്കൗണ്ട്
356356
password=രഹസ്യവാക്കു്
357357
security=സുരക്ഷ
358358
avatar=അവതാര്‍
359-
ssh_gpg_keys=SSH / GPG കീകള്‍
360359
social=സോഷ്യൽ അക്കൗണ്ടുകൾ
361360
applications=അപ്ലിക്കേഷനുകൾ
362361
orgs=സംഘടനകളെ നിയന്ത്രിക്കുക

options/locale/locale_nl-NL.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ account=Account
400400
password=Wachtwoord
401401
security=Beveiliging
402402
avatar=Profielfoto
403-
ssh_gpg_keys=SSH / GPG sleutels
404403
social=Sociale netwerk-accounts
405404
applications=Applicaties
406405
orgs=Beheer organisaties

options/locale/locale_pl-PL.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ account=Konto
407407
password=Hasło
408408
security=Bezpieczeństwo
409409
avatar=Awatar
410-
ssh_gpg_keys=Klucze SSH / GPG
410+
keys=Klucze
411411
social=Konta społecznościowe
412412
applications=Aplikacje
413413
orgs=Zarządzaj organizacjami

options/locale/locale_pt-BR.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ account=Conta
396396
password=Senha
397397
security=Segurança
398398
avatar=Avatar
399-
ssh_gpg_keys=Chaves SSH / GPG
400399
social=Contas sociais
401400
applications=Aplicativos
402401
orgs=Gerenciar organizações

options/locale/locale_pt-PT.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ account=Conta
412412
password=Senha
413413
security=Segurança
414414
avatar=Avatar
415-
ssh_gpg_keys=Chaves SSH / GPG
416415
social=Contas sociais
417416
applications=Aplicações
418417
orgs=Gerir organizações

options/locale/locale_ru-RU.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ account=Аккаунт
412412
password=Пароль
413413
security=Безопасность
414414
avatar=Аватар
415-
ssh_gpg_keys=SSH / GPG ключи
416415
social=Учетные записи в соцсетях
417416
applications=Приложения
418417
orgs=Управление организациями

options/locale/locale_sv-SE.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ account=Konto
391391
password=Lösenord
392392
security=Säkerhet
393393
avatar=Visningsbild
394-
ssh_gpg_keys=SSH / GPG-nycklar
395394
social=Sociala konton
396395
applications=Applikationer
397396
orgs=Hantera Organisationer

options/locale/locale_tr-TR.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ account=Hesap
416416
password=Parola
417417
security=Güvenlik
418418
avatar=Avatar
419-
ssh_gpg_keys=SSH / GPG Anahtarları
420419
social=Sosyal Medya Hesapları
421420
applications=Uygulamalar
422421
orgs=Organizasyonları Yönet

options/locale/locale_uk-UA.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ account=Обліковий запис
407407
password=Пароль
408408
security=Безпека
409409
avatar=Аватар
410-
ssh_gpg_keys=SSH / GPG ключі
411410
social=Соціальні облікові записи
412411
applications=Додатки
413412
orgs=Керування організаціями

options/locale/locale_zh-CN.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ account=账号
412412
password=修改密码
413413
security=安全
414414
avatar=头像设置
415-
ssh_gpg_keys=SSH / GPG 密钥
416415
social=社交帐号绑定
417416
applications=应用
418417
orgs=管理组织

options/locale/locale_zh-HK.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ form.name_reserved=這個使用者名稱已被系統保留,請改用其他名
167167
profile=個人訊息
168168
password=修改密碼
169169
avatar=頭像
170-
ssh_gpg_keys=SSH / GPG 金鑰
171170
social=社交帳號綁定
172171
delete=刪除帳戶
173172
twofa=兩步驟驗證

options/locale/locale_zh-TW.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ account=帳戶
405405
password=修改密碼
406406
security=安全性
407407
avatar=大頭貼
408-
ssh_gpg_keys=SSH / GPG 金鑰
409408
social=社群帳戶
410409
applications=應用程式
411410
orgs=管理組織

routers/user/setting/applications.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
package setting
77

88
import (
9+
"fmt"
10+
911
"code.gitea.io/gitea/models"
1012
"code.gitea.io/gitea/modules/auth"
1113
"code.gitea.io/gitea/modules/base"
@@ -39,6 +41,11 @@ func ApplicationsPost(ctx *context.Context, form auth.NewAccessTokenForm) {
3941
return
4042
}
4143

44+
if !setting.API.EnableSwagger {
45+
ctx.ServerError("AccessToken", fmt.Errorf("cannot modify access tokens; swagger disabled"))
46+
return
47+
}
48+
4249
t := &models.AccessToken{
4350
UID: ctx.User.ID,
4451
Name: form.Name,
@@ -68,6 +75,11 @@ func ApplicationsPost(ctx *context.Context, form auth.NewAccessTokenForm) {
6875

6976
// DeleteApplication response for delete user access token
7077
func DeleteApplication(ctx *context.Context) {
78+
if !setting.API.EnableSwagger {
79+
ctx.ServerError("DeleteAccessToken", fmt.Errorf("cannot delete access token; swagger disabled"))
80+
return
81+
}
82+
7183
if err := models.DeleteAccessTokenByID(ctx.QueryInt64("id"), ctx.User.ID); err != nil {
7284
ctx.Flash.Error("DeleteAccessTokenByID: " + err.Error())
7385
} else {
@@ -80,14 +92,17 @@ func DeleteApplication(ctx *context.Context) {
8092
}
8193

8294
func loadApplicationsData(ctx *context.Context) {
83-
tokens, err := models.ListAccessTokens(models.ListAccessTokensOptions{UserID: ctx.User.ID})
84-
if err != nil {
85-
ctx.ServerError("ListAccessTokens", err)
86-
return
95+
if setting.API.EnableSwagger {
96+
tokens, err := models.ListAccessTokens(models.ListAccessTokensOptions{UserID: ctx.User.ID})
97+
if err != nil {
98+
ctx.ServerError("ListAccessTokens", err)
99+
return
100+
}
101+
ctx.Data["Tokens"] = tokens
87102
}
88-
ctx.Data["Tokens"] = tokens
89103
ctx.Data["EnableOAuth2"] = setting.OAuth2.Enable
90104
if setting.OAuth2.Enable {
105+
var err error
91106
ctx.Data["Applications"], err = models.GetOAuth2ApplicationsByUserID(ctx.User.ID)
92107
if err != nil {
93108
ctx.ServerError("GetOAuth2ApplicationsByUserID", err)

templates/admin/dashboard.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,19 @@
3535
<td>{{.i18n.Tr "admin.dashboard.git_gc_repos"}}</td>
3636
<td><button type="submit" class="ui green button" name="op" value="git_gc_repos">{{svg "octicon-play"}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
3737
</tr>
38+
{{if not DisableSSH}}
3839
<tr>
3940
<td>{{.i18n.Tr "admin.dashboard.resync_all_sshkeys"}}<br/>
4041
{{.i18n.Tr "admin.dashboard.resync_all_sshkeys.desc"}}</td>
4142
<td><button type="submit" class="ui green button" name="op" value="resync_all_sshkeys">{{svg "octicon-play"}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
4243
</tr>
44+
{{end}}
45+
{{if not DisableGitHooks}}
4346
<tr>
4447
<td>{{.i18n.Tr "admin.dashboard.resync_all_hooks"}}</td>
4548
<td><button type="submit" class="ui green button" name="op" value="resync_all_hooks">{{svg "octicon-play"}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
4649
</tr>
50+
{{end}}
4751
<tr>
4852
<td>{{.i18n.Tr "admin.dashboard.reinit_missing_repos"}}</td>
4953
<td><button type="submit" class="ui green button" name="op" value="reinit_missing_repos">{{svg "octicon-play"}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>

templates/admin/user/edit.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<input name="restricted" type="checkbox" {{if .User.IsRestricted}}checked{{end}}>
9090
</div>
9191
</div>
92-
<div class="inline field">
92+
<div class="inline field"{{if DisableGitHooks}} hidden{{end}}>
9393
<div class="ui checkbox" data-tooltip="{{.i18n.Tr "admin.users.allow_git_hook_tooltip"}}">
9494
<label><strong>{{.i18n.Tr "admin.users.allow_git_hook"}}</strong></label>
9595
<input name="allow_git_hook" type="checkbox" {{if .User.CanEditGitHook}}checked{{end}} {{if DisableGitHooks}}disabled{{end}}>

templates/repo/settings/deploy_keys.tmpl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
<h4 class="ui top attached header">
88
{{.i18n.Tr "repo.settings.deploy_keys"}}
99
<div class="ui right">
10-
{{if not .DisableSSH}}
1110
<div class="ui blue tiny show-panel button" data-panel="#add-deploy-key-panel">{{.i18n.Tr "repo.settings.add_deploy_key"}}</div>
12-
{{else}}
13-
<div class="ui blue tiny button disabled">{{.i18n.Tr "settings.ssh_disabled"}}</div>
14-
{{end}}
1511
</div>
1612
</h4>
1713
<div class="ui attached segment">

templates/repo/settings/nav.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
{{if or .SignedUser.AllowGitHook .SignedUser.IsAdmin}}
1010
<li {{if .PageIsSettingsGitHooks}}class="current"{{end}}><a href="{{.RepoLink}}/settings/hooks/git">{{.i18n.Tr "repo.settings.githooks"}}</a></li>
1111
{{end}}
12+
{{if not DisableSSH}}
1213
<li {{if .PageIsSettingsKeys}}class="current"{{end}}><a href="{{.RepoLink}}/settings/keys">{{.i18n.Tr "repo.settings.deploy_keys"}}</a></li>
14+
{{end}}
1315
</ul>
1416
</div>
1517
</div>

templates/repo/settings/navbar.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
{{.i18n.Tr "repo.settings.githooks"}}
1919
</a>
2020
{{end}}
21+
{{if not DisableSSH}}
2122
<a class="{{if .PageIsSettingsKeys}}active{{end}} item" href="{{.RepoLink}}/settings/keys">
2223
{{.i18n.Tr "repo.settings.deploy_keys"}}
2324
</a>
25+
{{end}}
2426
{{if .LFSStartServer}}
2527
<a class="{{if .PageIsSettingsLFS}}active{{end}} item" href="{{.RepoLink}}/settings/lfs">
2628
{{.i18n.Tr "repo.settings.lfs"}}

templates/user/settings/applications.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{{template "user/settings/navbar" .}}
44
<div class="ui container">
55
{{template "base/alert" .}}
6+
{{if not DisableSwagger}}
67
<h4 class="ui top attached header">
78
{{.i18n.Tr "settings.manage_access_token"}}
89
</h4>
@@ -45,6 +46,7 @@
4546
</button>
4647
</form>
4748
</div>
49+
{{end}}
4850

4951
{{if .EnableOAuth2}}
5052
{{template "user/settings/grants_oauth2" .}}

templates/user/settings/keys_ssh.tmpl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1+
{{if not DisableSSH}}
12
<h4 class="ui top attached header">
23
{{.i18n.Tr "settings.manage_ssh_keys"}}
34
<div class="ui right">
4-
{{if not .DisableSSH}}
55
<div class="ui blue tiny show-panel button" data-panel="#add-ssh-key-panel">{{.i18n.Tr "settings.add_key"}}</div>
6-
{{else}}
7-
<div class="ui blue tiny button disabled">{{.i18n.Tr "settings.ssh_disabled"}}</div>
8-
{{end}}
96
</div>
107
</h4>
118
<div class="ui attached segment">
@@ -71,3 +68,4 @@
7168
</div>
7269
{{template "base/delete_modal_actions" .}}
7370
</div>
71+
{{end}}

0 commit comments

Comments
 (0)