aboutsummaryrefslogtreecommitdiffstats
path: root/models/organization
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-12-07 15:27:36 +0800
committerGitHub <noreply@github.com>2023-12-07 15:27:36 +0800
commitdd30d9d5c0f577cb6e084aae6de2752ad43474d8 (patch)
tree1e3799a672a23424484b849827ba39eae447856a /models/organization
parentbeb71f5ef6e8074dc744ac995c15f7b5947a3f2e (diff)
downloadgitea-dd30d9d5c0f577cb6e084aae6de2752ad43474d8.tar.gz
gitea-dd30d9d5c0f577cb6e084aae6de2752ad43474d8.zip
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}) ```
Diffstat (limited to 'models/organization')
-rw-r--r--models/organization/team.go10
1 files changed, 4 insertions, 6 deletions
diff --git a/models/organization/team.go b/models/organization/team.go
index 72afc67369..17db11c42d 100644
--- a/models/organization/team.go
+++ b/models/organization/team.go
@@ -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