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 5 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 @@ -1470,6 +1470,8 @@ LEVEL = Info
;;
;; Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled
;DEFAULT_EMAIL_NOTIFICATIONS = enabled
; Disabled modules from user settings, could be deletion now, more moudels can be defined in future
lunny marked this conversation as resolved.
Show resolved Hide resolved
;USER_SETTING_DISABLED_MODULES =

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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 @@ -517,6 +517,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_SETTING_DISABLED_MODULES`:**_empty_** Disabled modules from user settings, could be `deletion` and more moudels can be defined in future.
lunny 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
5 changes: 5 additions & 0 deletions docs/content/administration/config-cheat-sheet.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,11 @@ PROXY_HOSTS = *.github.com
但是,如果您想要使用其他 Git 服务器中的操作,您可以在 `uses` 字段中使用完整的 URL,Gitea 支持此功能(GitHub 不支持)。
例如 `uses: https://gitea.com/actions/checkout@v4` 或 `uses: http://your-git-server/actions/checkout@v4`。

## User (`user`)

- `SETTING_DISABLED_MODULES`:**_empty_** 禁用的用户设置模块,当前允许为空或者 `deletion` 未来可以增加更多设置.
- `deletion`: 用户不能通过界面或者API删除他自己。

## 其他 (`other`)

- `SHOW_FOOTER_VERSION`: **true**: 在页面底部显示Gitea的版本。
Expand Down
10 changes: 10 additions & 0 deletions 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
UserDisabledModules container.Set[string]
}

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

values := sec.Key("USER_SETTING_DISABLED_MODULES").Strings(",")
Admin.UserDisabledModules = container.SetOf(values...)
}

const (
UserDeletionKey = "deletion"
lunny marked this conversation as resolved.
Show resolved Hide resolved
)
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.UserDisabledModules.Contains(setting.UserDeletionKey) {
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["UserDisabledModules"] = &setting.Admin.UserDisabledModules

if setting.Service.UserDeleteWithCommentsMaxTime != 0 {
ctx.Data["UserDeleteWithCommentsMaxTime"] = setting.Service.UserDeleteWithCommentsMaxTime.String()
Expand Down
2 changes: 2 additions & 0 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 $.UserDisabledModules.Contains "deletion"}}
<h4 class="ui top attached error header">
{{ctx.Locale.Tr "settings.delete_account"}}
</h4>
Expand All @@ -152,6 +153,7 @@
</div>
</form>
</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 Down
Loading