Skip to content

Commit 3ef6252

Browse files
lunnywxiaoguang
andauthored
Allow options to disable user deletion from the interface on app.ini (#29275)
Extract from #20549 This PR added a new option on app.ini `[admin]USER_DISABLED_FEATURES` to allow the site administrator to disable users visiting deletion user interface or allow. This options are also potentially allowed to define more features in future PRs. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent 7fbdb60 commit 3ef6252

File tree

6 files changed

+34
-12
lines changed

6 files changed

+34
-12
lines changed

custom/conf/app.example.ini

+3
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,9 @@ LEVEL = Info
14741474
;;
14751475
;; Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled
14761476
;DEFAULT_EMAIL_NOTIFICATIONS = enabled
1477+
;; Disabled features for users, could be "deletion", more features can be disabled in future
1478+
;; - deletion: a user cannot delete their own account
1479+
;USER_DISABLED_FEATURES =
14771480

14781481
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14791482
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/administration/config-cheat-sheet.en-us.md

+2
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ And the following unique queues:
518518

519519
- `DEFAULT_EMAIL_NOTIFICATIONS`: **enabled**: Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled
520520
- `DISABLE_REGULAR_ORG_CREATION`: **false**: Disallow regular (non-admin) users from creating organizations.
521+
- `USER_DISABLED_FEATURES`: **_empty_** Disabled features for users, could be `deletion` and more features can be added in future.
522+
- `deletion`: User cannot delete their own account.
521523

522524
## Security (`security`)
523525

docs/content/administration/config-cheat-sheet.zh-cn.md

+2
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,8 @@ Gitea 创建以下非唯一队列:
497497

498498
- `DEFAULT_EMAIL_NOTIFICATIONS`: **enabled**:用户电子邮件通知的默认配置(用户可配置)。选项:enabled、onmention、disabled
499499
- `DISABLE_REGULAR_ORG_CREATION`: **false**:禁止普通(非管理员)用户创建组织。
500+
- `USER_DISABLED_FEATURES`:**_empty_** 禁用的用户特性,当前允许为空或者 `deletion`, 未来可以增加更多设置。
501+
- `deletion`: 用户不能通过界面或者API删除他自己。
500502

501503
## 安全性 (`security`)
502504

modules/setting/admin.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@
33

44
package setting
55

6+
import "code.gitea.io/gitea/modules/container"
7+
68
// Admin settings
79
var Admin struct {
810
DisableRegularOrgCreation bool
911
DefaultEmailNotification string
12+
UserDisabledFeatures container.Set[string]
1013
}
1114

1215
func loadAdminFrom(rootCfg ConfigProvider) {
13-
mustMapSetting(rootCfg, "admin", &Admin)
1416
sec := rootCfg.Section("admin")
17+
Admin.DisableRegularOrgCreation = sec.Key("DISABLE_REGULAR_ORG_CREATION").MustBool(false)
1518
Admin.DefaultEmailNotification = sec.Key("DEFAULT_EMAIL_NOTIFICATIONS").MustString("enabled")
19+
Admin.UserDisabledFeatures = container.SetOf(sec.Key("USER_DISABLED_FEATURES").Strings(",")...)
1620
}
21+
22+
const (
23+
UserFeatureDeletion = "deletion"
24+
)

routers/web/user/setting/account.go

+6
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ func DeleteEmail(ctx *context.Context) {
233233

234234
// DeleteAccount render user suicide page and response for delete user himself
235235
func DeleteAccount(ctx *context.Context) {
236+
if setting.Admin.UserDisabledFeatures.Contains(setting.UserFeatureDeletion) {
237+
ctx.Error(http.StatusNotFound)
238+
return
239+
}
240+
236241
ctx.Data["Title"] = ctx.Tr("settings")
237242
ctx.Data["PageIsSettingsAccount"] = true
238243

@@ -299,6 +304,7 @@ func loadAccountData(ctx *context.Context) {
299304
ctx.Data["EmailNotificationsPreference"] = ctx.Doer.EmailNotificationsPreference
300305
ctx.Data["ActivationsPending"] = pendingActivation
301306
ctx.Data["CanAddEmails"] = !pendingActivation || !setting.Service.RegisterEmailConfirm
307+
ctx.Data["UserDisabledFeatures"] = &setting.Admin.UserDisabledFeatures
302308

303309
if setting.Service.UserDeleteWithCommentsMaxTime != 0 {
304310
ctx.Data["UserDeleteWithCommentsMaxTime"] = setting.Service.UserDeleteWithCommentsMaxTime.String()

templates/user/settings/account.tmpl

+12-11
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
{{end}}
129129
</div>
130130

131+
{{if not ($.UserDisabledFeatures.Contains "deletion")}}
131132
<h4 class="ui top attached error header">
132133
{{ctx.Locale.Tr "settings.delete_account"}}
133134
</h4>
@@ -151,7 +152,18 @@
151152
</button>
152153
</div>
153154
</form>
155+
<div class="ui g-modal-confirm delete modal" id="delete-account">
156+
<div class="header">
157+
{{svg "octicon-trash"}}
158+
{{ctx.Locale.Tr "settings.delete_account_title"}}
159+
</div>
160+
<div class="content">
161+
<p>{{ctx.Locale.Tr "settings.delete_account_desc"}}</p>
162+
</div>
163+
{{template "base/modal_actions_confirm" .}}
164+
</div>
154165
</div>
166+
{{end}}
155167
</div>
156168

157169
<div class="ui g-modal-confirm delete modal" id="delete-email">
@@ -165,15 +177,4 @@
165177
{{template "base/modal_actions_confirm" .}}
166178
</div>
167179

168-
<div class="ui g-modal-confirm delete modal" id="delete-account">
169-
<div class="header">
170-
{{svg "octicon-trash"}}
171-
{{ctx.Locale.Tr "settings.delete_account_title"}}
172-
</div>
173-
<div class="content">
174-
<p>{{ctx.Locale.Tr "settings.delete_account_desc"}}</p>
175-
</div>
176-
{{template "base/modal_actions_confirm" .}}
177-
</div>
178-
179180
{{template "user/settings/layout_footer" .}}

0 commit comments

Comments
 (0)