Skip to content

Commit

Permalink
fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsvantesson committed Nov 12, 2019
1 parent 55f7cb3 commit 8e14c34
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
26 changes: 11 additions & 15 deletions models/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,17 +389,6 @@ func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) {
Find(&orgs)
}

func getOrgsCanCreateRepoByUserIDDesc(sess *xorm.Session, userID int64) ([]*User, error) {
orgs := make([]*User, 0, 10)
return orgs, sess.
Join("INNER", "`team_user`", "`team_user`.org_id=`user`.id").
Join("INNER", "`team`", "`team`.id=`team_user`.team_id").
Where("`team_user`.uid=?", userID).
And(builder.Eq{"`team`.authorize": AccessModeOwner}.Or(builder.Eq{"`team`.can_create_org_repo": true})).
Asc("`user`.name").
Find(&orgs)
}

// HasOrgVisible tells if the given user can see the given org
func HasOrgVisible(org *User, user *User) bool {
return hasOrgVisible(x, org, user)
Expand Down Expand Up @@ -448,10 +437,17 @@ func GetOwnedOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) {
return getOwnedOrgsByUserID(x.Desc(desc), userID)
}

// GetOrgsCanCreateRepoByUserIDDesc returns a list of organizations where given user ID
// are allowed to create repos, ordered descending by the given condition.
func GetOrgsCanCreateRepoByUserIDDesc(userID int64, desc string) ([]*User, error) {
return getOrgsCanCreateRepoByUserIDDesc(x.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)

return orgs, x.Join("INNER", "`team_user`", "`team_user`.org_id=`user`.id").
Join("INNER", "`team`", "`team`.id=`team_user`.team_id").
Where("`team_user`.uid=?", userID).
And(builder.Eq{"`team`.authorize": AccessModeOwner}.Or(builder.Eq{"`team`.can_create_org_repo": true})).
Desc("`user`.updated_unix").
Find(&orgs)
}

// GetOrgUsersByUserID returns all organization-user relations by user ID.
Expand Down
6 changes: 2 additions & 4 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1586,11 +1586,9 @@ func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err err
}
}

isAdmin, err := isUserRepoAdmin(e, repo, doer)
if err != nil {
if isAdmin, err := isUserRepoAdmin(e, repo, doer); err != nil {
return fmt.Errorf("isUserRepoAdmin: %v", err)
}
if !isAdmin {
} else if !isAdmin {
// Make creator repo admin if it wan't assigned automatically
if err = repo.addCollaborator(e, doer); err != nil {
return fmt.Errorf("AddCollaborator: %v", err)
Expand Down
6 changes: 1 addition & 5 deletions models/repo_collaboration.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ func (repo *Repository) addCollaborator(e Engine, u *User) error {
return err
}

if err = repo.recalculateUserAccess(e, u.ID); err != nil {
return fmt.Errorf("recalculateAccesses 'team=%v': %v", repo.Owner.IsOrganization(), err)
}

return nil
return repo.recalculateUserAccess(e, u.ID)
}

// AddCollaborator adds new collaboration to a repository with default access mode.
Expand Down
4 changes: 2 additions & 2 deletions routers/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func MustBeAbleToUpload(ctx *context.Context) {
}

func checkContextUser(ctx *context.Context, uid int64) *models.User {
orgs, err := models.GetOrgsCanCreateRepoByUserIDDesc(ctx.User.ID, "updated_unix")
orgs, err := models.GetOrgsCanCreateRepoByUserID(ctx.User.ID)
if err != nil {
ctx.ServerError("GetOrgsCanCreateRepoByUserIDDesc", err)
ctx.ServerError("GetOrgsCanCreateRepoByUserID", err)
return nil
}
ctx.Data["Orgs"] = orgs
Expand Down

0 comments on commit 8e14c34

Please sign in to comment.