diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-22 23:21:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-22 23:21:55 +0800 |
commit | baed01f24753afb600a2984dcb9bcda0bb8502b6 (patch) | |
tree | 5621ef980b6b0067a21c86be7e4808d83c0538ab /models/org.go | |
parent | c2ab19888f92fbdec4276a16d224e8de80d1d1dd (diff) | |
download | gitea-baed01f24753afb600a2984dcb9bcda0bb8502b6.tar.gz gitea-baed01f24753afb600a2984dcb9bcda0bb8502b6.zip |
Remove unnecessary attributes of User struct (#17745)
* Remove unnecessary functions of User struct
* Move more database methods out of user struct
* Move more database methods out of user struct
* Fix template failure
* Fix bug
* Remove finished FIXME
* remove unnecessary code
Diffstat (limited to 'models/org.go')
-rw-r--r-- | models/org.go | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/models/org.go b/models/org.go index b3e67fb521..ea73d03d42 100644 --- a/models/org.go +++ b/models/org.go @@ -125,6 +125,12 @@ func (org *Organization) HomeLink() string { return org.AsUser().HomeLink() } +// CanCreateRepo returns if user login can create a repository +// NOTE: functions calling this assume a failure due to repository count limit; if new checks are added, those functions should be revised +func (org *Organization) CanCreateRepo() bool { + return org.AsUser().CanCreateRepo() +} + // FindOrgMembersOpts represensts find org members conditions type FindOrgMembersOpts struct { db.ListOptions @@ -240,7 +246,7 @@ func CreateOrganization(org *Organization, owner *User) (err error) { if err = db.Insert(ctx, org); err != nil { return fmt.Errorf("insert organization: %v", err) } - if err = org.AsUser().generateRandomAvatar(db.GetEngine(ctx)); err != nil { + if err = generateRandomAvatar(db.GetEngine(ctx), org.AsUser()); err != nil { return fmt.Errorf("generate random avatar: %v", err) } @@ -546,8 +552,8 @@ func CountOrgs(opts FindOrgOptions) (int64, error) { Count(new(User)) } -func getOwnedOrgsByUserID(sess db.Engine, userID int64) ([]*User, error) { - orgs := make([]*User, 0, 10) +func getOwnedOrgsByUserID(sess db.Engine, userID int64) ([]*Organization, error) { + orgs := make([]*Organization, 0, 10) return orgs, sess. Join("INNER", "`team_user`", "`team_user`.org_id=`user`.id"). Join("INNER", "`team`", "`team`.id=`team_user`.team_id"). @@ -593,20 +599,20 @@ func HasOrgsVisible(orgs []*Organization, user *User) bool { } // GetOwnedOrgsByUserID returns a list of organizations are owned by given user ID. -func GetOwnedOrgsByUserID(userID int64) ([]*User, error) { +func GetOwnedOrgsByUserID(userID int64) ([]*Organization, error) { return getOwnedOrgsByUserID(db.GetEngine(db.DefaultContext), userID) } // GetOwnedOrgsByUserIDDesc returns a list of organizations are owned by // given user ID, ordered descending by the given condition. -func GetOwnedOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) { +func GetOwnedOrgsByUserIDDesc(userID int64, desc string) ([]*Organization, error) { return getOwnedOrgsByUserID(db.GetEngine(db.DefaultContext).Desc(desc), userID) } // GetOrgsCanCreateRepoByUserID returns a list of organizations where given user ID // are allowed to create repos. -func GetOrgsCanCreateRepoByUserID(userID int64) ([]*User, error) { - orgs := make([]*User, 0, 10) +func GetOrgsCanCreateRepoByUserID(userID int64) ([]*Organization, error) { + orgs := make([]*Organization, 0, 10) return orgs, db.GetEngine(db.DefaultContext).Where(builder.In("id", builder.Select("`user`.id").From("`user`"). Join("INNER", "`team_user`", "`team_user`.org_id = `user`.id"). |