Skip to content

Commit 7009459

Browse files
authored
Merge branch 'main' into also_auto-merge_on_review_updates
2 parents 7199292 + 9de5e39 commit 7009459

File tree

11 files changed

+59
-11
lines changed

11 files changed

+59
-11
lines changed

custom/conf/app.example.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,8 +1480,9 @@ LEVEL = Info
14801480
;;
14811481
;; Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled
14821482
;DEFAULT_EMAIL_NOTIFICATIONS = enabled
1483-
;; Disabled features for users, could be "deletion", more features can be disabled in future
1483+
;; Disabled features for users, could be "deletion","manage_gpg_keys" more features can be disabled in future
14841484
;; - deletion: a user cannot delete their own account
1485+
;; - manage_gpg_keys: a user cannot configure gpg keys
14851486
;USER_DISABLED_FEATURES =
14861487

14871488
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,9 @@ 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.
521+
- `USER_DISABLED_FEATURES`: **_empty_** Disabled features for users, could be `deletion`, `manage_gpg_keys` and more features can be added in future.
522522
- `deletion`: User cannot delete their own account.
523+
- `manage_gpg_keys`: User cannot configure gpg keys
523524

524525
## Security (`security`)
525526

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,9 @@ Gitea 创建以下非唯一队列:
497497

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

503504
## 安全性 (`security`)
504505

models/issues/content_history.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,9 @@ func FetchIssueContentHistoryList(dbCtx context.Context, issueID, commentID int6
172172

173173
// HasIssueContentHistory check if a ContentHistory entry exists
174174
func HasIssueContentHistory(dbCtx context.Context, issueID, commentID int64) (bool, error) {
175-
exists, err := db.GetEngine(dbCtx).Cols("id").Exist(&ContentHistory{
176-
IssueID: issueID,
177-
CommentID: commentID,
178-
})
175+
exists, err := db.GetEngine(dbCtx).Where(builder.Eq{"issue_id": issueID, "comment_id": commentID}).Exist(&ContentHistory{})
179176
if err != nil {
180-
log.Error("can not fetch issue content history. err=%v", err)
181-
return false, err
177+
return false, fmt.Errorf("can not check issue content history. err: %w", err)
182178
}
183179
return exists, err
184180
}

models/issues/content_history_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,22 @@ func TestContentHistory(t *testing.T) {
7878
assert.EqualValues(t, 7, list2[1].HistoryID)
7979
assert.EqualValues(t, 4, list2[2].HistoryID)
8080
}
81+
82+
func TestHasIssueContentHistoryForCommentOnly(t *testing.T) {
83+
assert.NoError(t, unittest.PrepareTestDatabase())
84+
85+
_ = db.TruncateBeans(db.DefaultContext, &issues_model.ContentHistory{})
86+
87+
hasHistory1, _ := issues_model.HasIssueContentHistory(db.DefaultContext, 10, 0)
88+
assert.False(t, hasHistory1)
89+
hasHistory2, _ := issues_model.HasIssueContentHistory(db.DefaultContext, 10, 100)
90+
assert.False(t, hasHistory2)
91+
92+
_ = issues_model.SaveIssueContentHistory(db.DefaultContext, 1, 10, 100, timeutil.TimeStampNow(), "c-a", true)
93+
_ = issues_model.SaveIssueContentHistory(db.DefaultContext, 1, 10, 100, timeutil.TimeStampNow().Add(5), "c-b", false)
94+
95+
hasHistory1, _ = issues_model.HasIssueContentHistory(db.DefaultContext, 10, 0)
96+
assert.False(t, hasHistory1)
97+
hasHistory2, _ = issues_model.HasIssueContentHistory(db.DefaultContext, 10, 100)
98+
assert.True(t, hasHistory2)
99+
}

modules/setting/admin.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ func loadAdminFrom(rootCfg ConfigProvider) {
2020
}
2121

2222
const (
23-
UserFeatureDeletion = "deletion"
23+
UserFeatureDeletion = "deletion"
24+
UserFeatureManageGPGKeys = "manage_gpg_keys"
2425
)

options/locale/locale_fr-FR.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ authorization_failed_desc=L'autorisation a échoué car nous avons détecté une
424424
sspi_auth_failed=Échec de l'authentification SSPI
425425
password_pwned=Le mot de passe que vous avez choisi se trouve sur la liste <a target="_blank" rel="noopener noreferrer" href="https://haveibeenpwned.com/Passwords">des mots de passe ayant fuité</a> sur internet. Veuillez réessayer avec un mot de passe différent et considérer remplacer ce mot de passe si vous l'utilisez ailleurs.
426426
password_pwned_err=Impossible d'envoyer la demande à HaveIBeenPwned
427+
last_admin=Vous ne pouvez pas supprimer ce compte car au moins un administrateur est requis.
427428

428429
[mail]
429430
view_it_on=Voir sur %s
@@ -1714,6 +1715,7 @@ pulls.select_commit_hold_shift_for_range=Maintenir Maj et cliquer sur des révis
17141715
pulls.review_only_possible_for_full_diff=Une évaluation n'est possible que lorsque vous affichez le différentiel complet.
17151716
pulls.filter_changes_by_commit=Filtrer par révision
17161717
pulls.nothing_to_compare=Ces branches sont identiques. Il n’y a pas besoin de créer une demande d'ajout.
1718+
pulls.nothing_to_compare_have_tag=Les branches/étiquettes sélectionnées sont équivalentes.
17171719
pulls.nothing_to_compare_and_allow_empty_pr=Ces branches sont égales. Cette demande d'ajout sera vide.
17181720
pulls.has_pull_request='Il existe déjà une demande d'ajout entre ces deux branches : <a href="%[1]s">%[2]s#%[3]d</a>'
17191721
pulls.create=Créer une demande d'ajout

routers/api/v1/user/gpg_key.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
asymkey_model "code.gitea.io/gitea/models/asymkey"
1212
"code.gitea.io/gitea/models/db"
13+
"code.gitea.io/gitea/modules/setting"
1314
api "code.gitea.io/gitea/modules/structs"
1415
"code.gitea.io/gitea/modules/web"
1516
"code.gitea.io/gitea/routers/api/v1/utils"
@@ -132,6 +133,11 @@ func GetGPGKey(ctx *context.APIContext) {
132133

133134
// CreateUserGPGKey creates new GPG key to given user by ID.
134135
func CreateUserGPGKey(ctx *context.APIContext, form api.CreateGPGKeyOption, uid int64) {
136+
if setting.Admin.UserDisabledFeatures.Contains(setting.UserFeatureManageGPGKeys) {
137+
ctx.NotFound("Not Found", fmt.Errorf("gpg keys setting is not allowed to be visited"))
138+
return
139+
}
140+
135141
token := asymkey_model.VerificationToken(ctx.Doer, 1)
136142
lastToken := asymkey_model.VerificationToken(ctx.Doer, 0)
137143

@@ -268,6 +274,11 @@ func DeleteGPGKey(ctx *context.APIContext) {
268274
// "404":
269275
// "$ref": "#/responses/notFound"
270276

277+
if setting.Admin.UserDisabledFeatures.Contains(setting.UserFeatureManageGPGKeys) {
278+
ctx.NotFound("Not Found", fmt.Errorf("gpg keys setting is not allowed to be visited"))
279+
return
280+
}
281+
271282
if err := asymkey_model.DeleteGPGKey(ctx, ctx.Doer, ctx.ParamsInt64(":id")); err != nil {
272283
if asymkey_model.IsErrGPGKeyAccessDenied(err) {
273284
ctx.Error(http.StatusForbidden, "", "You do not have access to this key")

routers/web/repo/issue_content_history.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func canSoftDeleteContentHistory(ctx *context.Context, issue *issues_model.Issue
9494
// CanWrite means the doer can manage the issue/PR list
9595
if ctx.Repo.IsOwner() || ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
9696
canSoftDelete = true
97-
} else {
97+
} else if ctx.Doer != nil {
9898
// for read-only users, they could still post issues or comments,
9999
// they should be able to delete the history related to their own issue/comment, a case is:
100100
// 1. the user posts some sensitive data
@@ -186,6 +186,10 @@ func SoftDeleteContentHistory(ctx *context.Context) {
186186
if ctx.Written() {
187187
return
188188
}
189+
if ctx.Doer == nil {
190+
ctx.NotFound("Require SignIn", nil)
191+
return
192+
}
189193

190194
commentID := ctx.FormInt64("comment_id")
191195
historyID := ctx.FormInt64("history_id")

routers/web/user/setting/keys.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package setting
66

77
import (
8+
"fmt"
89
"net/http"
910

1011
asymkey_model "code.gitea.io/gitea/models/asymkey"
@@ -77,6 +78,11 @@ func KeysPost(ctx *context.Context) {
7778
ctx.Flash.Success(ctx.Tr("settings.add_principal_success", form.Content))
7879
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
7980
case "gpg":
81+
if setting.Admin.UserDisabledFeatures.Contains(setting.UserFeatureManageGPGKeys) {
82+
ctx.NotFound("Not Found", fmt.Errorf("gpg keys setting is not allowed to be visited"))
83+
return
84+
}
85+
8086
token := asymkey_model.VerificationToken(ctx.Doer, 1)
8187
lastToken := asymkey_model.VerificationToken(ctx.Doer, 0)
8288

@@ -224,6 +230,10 @@ func KeysPost(ctx *context.Context) {
224230
func DeleteKey(ctx *context.Context) {
225231
switch ctx.FormString("type") {
226232
case "gpg":
233+
if setting.Admin.UserDisabledFeatures.Contains(setting.UserFeatureManageGPGKeys) {
234+
ctx.NotFound("Not Found", fmt.Errorf("gpg keys setting is not allowed to be visited"))
235+
return
236+
}
227237
if err := asymkey_model.DeleteGPGKey(ctx, ctx.Doer, ctx.FormInt64("id")); err != nil {
228238
ctx.Flash.Error("DeleteGPGKey: " + err.Error())
229239
} else {

templates/user/settings/keys.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<div class="user-setting-content">
33
{{template "user/settings/keys_ssh" .}}
44
{{template "user/settings/keys_principal" .}}
5+
{{if not ($.UserDisabledFeatures.Contains "manage_gpg_keys")}}
56
{{template "user/settings/keys_gpg" .}}
7+
{{end}}
68
</div>
79
{{template "user/settings/layout_footer" .}}

0 commit comments

Comments
 (0)