Skip to content

Commit dc4aa3f

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Add missing translation (go-gitea#26926) Vendor `jquery.are-you-sure` with strict mode fixes (go-gitea#26901) Fix the secret regexp pattern on web page (go-gitea#26910) Add @chenrui333 as maintainer (go-gitea#26917) Move notification interface to services layer (go-gitea#26915) fetch emails of currently displayed user on admin page (go-gitea#26918) Improve LDAP group config documentation, fixes go-gitea#21159 (go-gitea#21227) update footer link to new landing page (go-gitea#26916) Remove `Named` interface (go-gitea#26913) Refactor secrets modification logic (go-gitea#26873) Add missing `reqToken()` to notifications endpoints (go-gitea#26914) feat(API): add routes and functions for managing user's secrets (go-gitea#26909) Move feed notification service layer (go-gitea#26908) Extract common code to new template (go-gitea#26903) Move ui notification to service layer (go-gitea#26907) Remove duplicated notify mail configuration on tests (go-gitea#26912) Move indexer notification to service layer (go-gitea#26906) # Conflicts: # templates/base/footer_content.tmpl
2 parents cefe080 + 31c92d9 commit dc4aa3f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1775
-1284
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ Philip Peterson <[email protected]> (@philip-peterson)
5555
Denys Konovalov <[email protected]> (@denyskon)
5656
Punit Inani <[email protected]> (@puni9869)
5757
CaiCandong <[email protected]> (@caicandong)
58+
Rui Chen <[email protected]> (@chenrui333)

docs/content/usage/authentication.en-us.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,13 @@ Uses the following fields:
157157

158158
- User Attribute in Group (optional)
159159

160-
- Which user LDAP attribute is listed in the group.
161-
- Example: `uid`
160+
- The user attribute that is used to reference a user in the group object.
161+
- Example: `uid` if the group objects contains a `member: bender` and the user object contains a `uid: bender`.
162+
- Example: `dn` if the group object contains a `member: uid=bender,ou=users,dc=planetexpress,dc=com`.
162163

163164
- Group Attribute for User (optional)
164-
- Which group LDAP attribute contains an array above user attribute names.
165-
- Example: `memberUid`
165+
- The attribute of the group object that lists/contains the group members.
166+
- Example: `memberUid` or `member`
166167

167168
## PAM (Pluggable Authentication Module)
168169

models/secret/secret.go

Lines changed: 23 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ type ErrSecretNotFound struct {
3333
Name string
3434
}
3535

36-
// IsErrSecretNotFound checks if an error is a ErrSecretNotFound.
37-
func IsErrSecretNotFound(err error) bool {
38-
_, ok := err.(ErrSecretNotFound)
39-
return ok
40-
}
41-
4236
func (err ErrSecretNotFound) Error() string {
4337
return fmt.Sprintf("secret was not found [name: %s]", err.Name)
4438
}
@@ -47,23 +41,18 @@ func (err ErrSecretNotFound) Unwrap() error {
4741
return util.ErrNotExist
4842
}
4943

50-
// newSecret Creates a new already encrypted secret
51-
func newSecret(ownerID, repoID int64, name, data string) *Secret {
52-
return &Secret{
53-
OwnerID: ownerID,
54-
RepoID: repoID,
55-
Name: strings.ToUpper(name),
56-
Data: data,
57-
}
58-
}
59-
6044
// InsertEncryptedSecret Creates, encrypts, and validates a new secret with yet unencrypted data and insert into database
6145
func InsertEncryptedSecret(ctx context.Context, ownerID, repoID int64, name, data string) (*Secret, error) {
6246
encrypted, err := secret_module.EncryptSecret(setting.SecretKey, data)
6347
if err != nil {
6448
return nil, err
6549
}
66-
secret := newSecret(ownerID, repoID, name, encrypted)
50+
secret := &Secret{
51+
OwnerID: ownerID,
52+
RepoID: repoID,
53+
Name: strings.ToUpper(name),
54+
Data: encrypted,
55+
}
6756
if err := secret.Validate(); err != nil {
6857
return secret, err
6958
}
@@ -83,8 +72,10 @@ func (s *Secret) Validate() error {
8372

8473
type FindSecretsOptions struct {
8574
db.ListOptions
86-
OwnerID int64
87-
RepoID int64
75+
OwnerID int64
76+
RepoID int64
77+
SecretID int64
78+
Name string
8879
}
8980

9081
func (opts *FindSecretsOptions) toConds() builder.Cond {
@@ -95,6 +86,12 @@ func (opts *FindSecretsOptions) toConds() builder.Cond {
9586
if opts.RepoID > 0 {
9687
cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
9788
}
89+
if opts.SecretID != 0 {
90+
cond = cond.And(builder.Eq{"id": opts.SecretID})
91+
}
92+
if opts.Name != "" {
93+
cond = cond.And(builder.Eq{"name": strings.ToUpper(opts.Name)})
94+
}
9895

9996
return cond
10097
}
@@ -116,75 +113,18 @@ func CountSecrets(ctx context.Context, opts *FindSecretsOptions) (int64, error)
116113
}
117114

118115
// UpdateSecret changes org or user reop secret.
119-
func UpdateSecret(ctx context.Context, orgID, repoID int64, name, data string) error {
120-
sc := new(Secret)
121-
name = strings.ToUpper(name)
122-
has, err := db.GetEngine(ctx).
123-
Where("owner_id=?", orgID).
124-
And("repo_id=?", repoID).
125-
And("name=?", name).
126-
Get(sc)
127-
if err != nil {
128-
return err
129-
} else if !has {
130-
return ErrSecretNotFound{Name: name}
131-
}
132-
116+
func UpdateSecret(ctx context.Context, secretID int64, data string) error {
133117
encrypted, err := secret_module.EncryptSecret(setting.SecretKey, data)
134118
if err != nil {
135119
return err
136120
}
137121

138-
sc.Data = encrypted
139-
_, err = db.GetEngine(ctx).ID(sc.ID).Cols("data").Update(sc)
140-
return err
141-
}
142-
143-
// DeleteSecret deletes secret from an organization.
144-
func DeleteSecret(ctx context.Context, orgID, repoID int64, name string) error {
145-
sc := new(Secret)
146-
has, err := db.GetEngine(ctx).
147-
Where("owner_id=?", orgID).
148-
And("repo_id=?", repoID).
149-
And("name=?", strings.ToUpper(name)).
150-
Get(sc)
151-
if err != nil {
152-
return err
153-
} else if !has {
154-
return ErrSecretNotFound{Name: name}
155-
}
156-
157-
if _, err := db.GetEngine(ctx).ID(sc.ID).Delete(new(Secret)); err != nil {
158-
return fmt.Errorf("Delete: %w", err)
159-
}
160-
161-
return nil
162-
}
163-
164-
// CreateOrUpdateSecret creates or updates a secret and returns true if it was created
165-
func CreateOrUpdateSecret(ctx context.Context, orgID, repoID int64, name, data string) (bool, error) {
166-
sc := new(Secret)
167-
name = strings.ToUpper(name)
168-
has, err := db.GetEngine(ctx).
169-
Where("owner_id=?", orgID).
170-
And("repo_id=?", repoID).
171-
And("name=?", name).
172-
Get(sc)
173-
if err != nil {
174-
return false, err
122+
s := &Secret{
123+
Data: encrypted,
175124
}
176-
177-
if !has {
178-
_, err = InsertEncryptedSecret(ctx, orgID, repoID, name, data)
179-
if err != nil {
180-
return false, err
181-
}
182-
return true, nil
125+
affected, err := db.GetEngine(ctx).ID(secretID).Cols("data").Update(s)
126+
if affected != 1 {
127+
return ErrSecretNotFound{}
183128
}
184-
185-
if err := UpdateSecret(ctx, orgID, repoID, name, data); err != nil {
186-
return false, err
187-
}
188-
189-
return false, nil
129+
return err
190130
}

modules/notification/base/notifier.go

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

0 commit comments

Comments
 (0)