mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-10-26 12:01:08 +00:00
Remove GetByBean method because sometimes it's danger when query condition parameter is zero and also introduce new generic methods (#28220)
The function `GetByBean` has an obvious defect that when the fields are
empty values, it will be ignored. Then users will get a wrong result
which is possibly used to make a security problem.
To avoid the possibility, this PR removed function `GetByBean` and all
references.
And some new generic functions have been introduced to be used.
The recommand usage like below.
```go
// if query an object according id
obj, err := db.GetByID[Object](ctx, id)
// query with other conditions
obj, err := db.Get[Object](ctx, builder.Eq{"a": a, "b":b})
```
This commit is contained in:
parent
beb71f5ef6
commit
dd30d9d5c0
28 changed files with 189 additions and 174 deletions
|
|
@ -16,6 +16,8 @@ import (
|
|||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
// ___________
|
||||
|
|
@ -203,14 +205,10 @@ func IsUsableTeamName(name string) error {
|
|||
|
||||
// GetTeam returns team by given team name and organization.
|
||||
func GetTeam(ctx context.Context, orgID int64, name string) (*Team, error) {
|
||||
t := &Team{
|
||||
OrgID: orgID,
|
||||
LowerName: strings.ToLower(name),
|
||||
}
|
||||
has, err := db.GetByBean(ctx, t)
|
||||
t, exist, err := db.Get[Team](ctx, builder.Eq{"org_id": orgID, "lower_name": strings.ToLower(name)})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
} else if !exist {
|
||||
return nil, ErrTeamNotExist{orgID, 0, name}
|
||||
}
|
||||
return t, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue