Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow options to disable user deletion from the interface on app.ini #29275

Merged
merged 14 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,8 @@ LEVEL = Info
;;
;; Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled
;DEFAULT_EMAIL_NOTIFICATIONS = enabled
;; Disabled features from user, could be "deletion" now, more features can be disabled in future
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
;USER_DISABLED_FEATURES =

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
2 changes: 2 additions & 0 deletions docs/content/administration/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ And the following unique queues:

- `DEFAULT_EMAIL_NOTIFICATIONS`: **enabled**: Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled
- `DISABLE_REGULAR_ORG_CREATION`: **false**: Disallow regular (non-admin) users from creating organizations.
- `USER_DISABLED_FEATURES`: **_empty_** Disabled features from user, could be `deletion` and more features can be added in future.
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
- `deletion`: User cannot remove himself from the website.
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved

## Security (`security`)

Expand Down
2 changes: 2 additions & 0 deletions docs/content/administration/config-cheat-sheet.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ Gitea 创建以下非唯一队列:

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

## 安全性 (`security`)

Expand Down
12 changes: 11 additions & 1 deletion modules/setting/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@

package setting

import "code.gitea.io/gitea/modules/container"

// Admin settings
var Admin struct {
DisableRegularOrgCreation bool
DefaultEmailNotification string
UserDisabledFeatures container.Set[string]
}

func loadAdminFrom(rootCfg ConfigProvider) {
mustMapSetting(rootCfg, "admin", &Admin)
sec := rootCfg.Section("admin")
Admin.DisableRegularOrgCreation = sec.Key("DISABLE_REGULAR_ORG_CREATION").MustBool(false)
Admin.DefaultEmailNotification = sec.Key("DEFAULT_EMAIL_NOTIFICATIONS").MustString("enabled")

values := sec.Key("USER_DISABLED_FEATURES").Strings(",")
Admin.UserDisabledFeatures = container.SetOf(values...)
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
}

const (
UserFeatureDeletion = "deletion"
)
6 changes: 6 additions & 0 deletions routers/web/user/setting/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ func DeleteEmail(ctx *context.Context) {

// DeleteAccount render user suicide page and response for delete user himself
func DeleteAccount(ctx *context.Context) {
if setting.Admin.UserDisabledFeatures.Contains(setting.UserFeatureDeletion) {
ctx.Error(http.StatusNotFound)
return
}

ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsAccount"] = true

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

if setting.Service.UserDeleteWithCommentsMaxTime != 0 {
ctx.Data["UserDeleteWithCommentsMaxTime"] = setting.Service.UserDeleteWithCommentsMaxTime.String()
Expand Down
24 changes: 13 additions & 11 deletions templates/user/settings/account.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
{{end}}
</div>

{{if not ($.UserDisabledFeatures.Contains "deletion")}}
<h4 class="ui top attached error header">
{{ctx.Locale.Tr "settings.delete_account"}}
</h4>
Expand All @@ -152,6 +153,18 @@
</div>
</form>
</div>

<div class="ui g-modal-confirm delete modal" id="delete-account">
<div class="header">
{{svg "octicon-trash"}}
{{ctx.Locale.Tr "settings.delete_account_title"}}
</div>
<div class="content">
<p>{{ctx.Locale.Tr "settings.delete_account_desc"}}</p>
</div>
{{template "base/modal_actions_confirm" .}}
</div>
{{end}}
lunny marked this conversation as resolved.
Show resolved Hide resolved
</div>

<div class="ui g-modal-confirm delete modal" id="delete-email">
Expand All @@ -165,15 +178,4 @@
{{template "base/modal_actions_confirm" .}}
</div>

<div class="ui g-modal-confirm delete modal" id="delete-account">
<div class="header">
{{svg "octicon-trash"}}
{{ctx.Locale.Tr "settings.delete_account_title"}}
</div>
<div class="content">
<p>{{ctx.Locale.Tr "settings.delete_account_desc"}}</p>
</div>
{{template "base/modal_actions_confirm" .}}
</div>

{{template "user/settings/layout_footer" .}}
Loading