Skip to content

Commit 7a8a44a

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Include encoding in signature payload (go-gitea#30174) Add `stylelint-value-no-unknown-custom-properties` and convert stylelint config to js (go-gitea#30117) Remove jQuery class from the commit button (go-gitea#30178) Remove jQuery class from the diff view (go-gitea#30176) Remove jQuery class from the notification count (go-gitea#30172) Remove jQuery class from the code range selection (go-gitea#30173) Fix:the rounded corners of the folded file are not displayed correctly (go-gitea#29953) Add setting to disable user features when user login type is not plain (go-gitea#29615) # Conflicts: # models/user/user.go
2 parents 1ba6108 + b6a3cd4 commit 7a8a44a

File tree

24 files changed

+474
-280
lines changed

24 files changed

+474
-280
lines changed

.github/labeler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ modifies/internal:
5353
- ".gitpod.yml"
5454
- ".markdownlint.yaml"
5555
- ".spectral.yaml"
56-
- ".stylelintrc.yaml"
56+
- "stylelint.config.js"
5757
- ".yamllint.yaml"
5858
- ".github/**"
5959
- ".gitea/"

.github/workflows/files-changed.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
- "package-lock.json"
5959
- "Makefile"
6060
- ".eslintrc.yaml"
61-
- ".stylelintrc.yaml"
61+
- "stylelint.config.js"
6262
- ".npmrc"
6363
6464
docs:

.stylelintrc.yaml

Lines changed: 0 additions & 223 deletions
This file was deleted.

custom/conf/app.example.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,11 @@ LEVEL = Info
14851485
;; - manage_ssh_keys: a user cannot configure ssh keys
14861486
;; - manage_gpg_keys: a user cannot configure gpg keys
14871487
;USER_DISABLED_FEATURES =
1488+
;; Comma separated list of disabled features ONLY if the user has an external login type (eg. LDAP, Oauth, etc.), could be `deletion`, `manage_ssh_keys`, `manage_gpg_keys`. This setting is independent from `USER_DISABLED_FEATURES` and supplements its behavior.
1489+
;; - deletion: a user cannot delete their own account
1490+
;; - manage_ssh_keys: a user cannot configure ssh keys
1491+
;; - manage_gpg_keys: a user cannot configure gpg keys
1492+
;;EXTERNAL_USER_DISABLE_FEATURES =
14881493

14891494
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14901495
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,10 @@ And the following unique queues:
522522
- `deletion`: User cannot delete their own account.
523523
- `manage_ssh_keys`: User cannot configure ssh keys.
524524
- `manage_gpg_keys`: User cannot configure gpg keys.
525+
- `EXTERNAL_USER_DISABLE_FEATURES`: **_empty_**: Comma separated list of disabled features ONLY if the user has an external login type (eg. LDAP, Oauth, etc.), could be `deletion`, `manage_ssh_keys`, `manage_gpg_keys`. This setting is independent from `USER_DISABLED_FEATURES` and supplements its behavior.
526+
- `deletion`: User cannot delete their own account.
527+
- `manage_ssh_keys`: User cannot configure ssh keys.
528+
- `manage_gpg_keys`: User cannot configure gpg keys.
525529

526530
## Security (`security`)
527531

models/user/user.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,27 @@ func GetOrderByName() string {
12331233
return "name"
12341234
}
12351235

1236+
1237+
1238+
// IsFeatureDisabledWithLoginType checks if a user feature is disabled, taking into account the login type of the
1239+
// user if applicable
1240+
func IsFeatureDisabledWithLoginType(user *User, feature string) bool {
1241+
// NOTE: in the long run it may be better to check the ExternalLoginUser table rather than user.LoginType
1242+
return (user != nil && user.LoginType > auth.Plain && setting.Admin.ExternalUserDisableFeatures.Contains(feature)) ||
1243+
setting.Admin.UserDisabledFeatures.Contains(feature)
1244+
}
1245+
1246+
// DisabledFeaturesWithLoginType returns the set of user features disabled, taking into account the login type
1247+
// of the user if applicable
1248+
func DisabledFeaturesWithLoginType(user *User) *container.Set[string] {
1249+
// NOTE: in the long run it may be better to check the ExternalLoginUser table rather than user.LoginType
1250+
if user != nil && user.LoginType > auth.Plain {
1251+
return &setting.Admin.ExternalUserDisableFeatures
1252+
}
1253+
return &setting.Admin.UserDisabledFeatures
1254+
}
1255+
1256+
12361257
// user customer funtions
12371258
/*
12381259
func contain(s []string, e string) bool {
@@ -1249,4 +1270,4 @@ func (u *User) ThemeContainsPark() bool {
12491270
ars := []string{"plex", "aquamarine", "dark", "dracula", "hotline", "organizr", "space-gray", "hotpink", "onedark", "overseerr", "nord"}
12501271
//return contain(ars, u.Theme)
12511272
return util.SliceContainsString(ars, u.Theme)
1252-
}
1273+
}

models/user/user_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"code.gitea.io/gitea/models/unittest"
1717
user_model "code.gitea.io/gitea/models/user"
1818
"code.gitea.io/gitea/modules/auth/password/hash"
19+
"code.gitea.io/gitea/modules/container"
1920
"code.gitea.io/gitea/modules/optional"
2021
"code.gitea.io/gitea/modules/setting"
2122
"code.gitea.io/gitea/modules/structs"
@@ -526,3 +527,37 @@ func Test_NormalizeUserFromEmail(t *testing.T) {
526527
}
527528
}
528529
}
530+
531+
func TestDisabledUserFeatures(t *testing.T) {
532+
assert.NoError(t, unittest.PrepareTestDatabase())
533+
534+
testValues := container.SetOf(setting.UserFeatureDeletion,
535+
setting.UserFeatureManageSSHKeys,
536+
setting.UserFeatureManageGPGKeys)
537+
538+
oldSetting := setting.Admin.ExternalUserDisableFeatures
539+
defer func() {
540+
setting.Admin.ExternalUserDisableFeatures = oldSetting
541+
}()
542+
setting.Admin.ExternalUserDisableFeatures = testValues
543+
544+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
545+
546+
assert.Len(t, setting.Admin.UserDisabledFeatures.Values(), 0)
547+
548+
// no features should be disabled with a plain login type
549+
assert.LessOrEqual(t, user.LoginType, auth.Plain)
550+
assert.Len(t, user_model.DisabledFeaturesWithLoginType(user).Values(), 0)
551+
for _, f := range testValues.Values() {
552+
assert.False(t, user_model.IsFeatureDisabledWithLoginType(user, f))
553+
}
554+
555+
// check disabled features with external login type
556+
user.LoginType = auth.OAuth2
557+
558+
// all features should be disabled
559+
assert.NotEmpty(t, user_model.DisabledFeaturesWithLoginType(user).Values())
560+
for _, f := range testValues.Values() {
561+
assert.True(t, user_model.IsFeatureDisabledWithLoginType(user, f))
562+
}
563+
}

modules/git/commit_convert_gogit.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ func convertPGPSignature(c *object.Commit) *CommitGPGSignature {
4747
return nil
4848
}
4949

50+
if c.Encoding != "" && c.Encoding != "UTF-8" {
51+
if _, err = fmt.Fprintf(&w, "\nencoding %s\n", c.Encoding); err != nil {
52+
return nil
53+
}
54+
}
55+
5056
if _, err = fmt.Fprintf(&w, "\n\n%s", c.Message); err != nil {
5157
return nil
5258
}

modules/git/commit_reader.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ readLoop:
8484
commit.Committer = &Signature{}
8585
commit.Committer.Decode(data)
8686
_, _ = payloadSB.Write(line)
87+
case "encoding":
88+
_, _ = payloadSB.Write(line)
8789
case "gpgsig":
8890
fallthrough
8991
case "gpgsig-sha256": // FIXME: no intertop, so only 1 exists at present.

0 commit comments

Comments
 (0)