@@ -130,15 +130,11 @@ func (datasets DatasetList) loadAttachmentAttributes(opts *SearchDatasetOptions) | |||||
permission = false | permission = false | ||||
datasets[i].Repo.GetOwner() | datasets[i].Repo.GetOwner() | ||||
if datasets[i].Repo.Owner.IsOrganization() { | |||||
if datasets[i].Repo.Owner.IsUserPartOfOrg(opts.User.ID) { | |||||
log.Info("user is member of org.") | |||||
permission = true | |||||
} | |||||
} | |||||
if !permission { | if !permission { | ||||
isCollaborator, _ := datasets[i].Repo.IsCollaborator(opts.User.ID) | isCollaborator, _ := datasets[i].Repo.IsCollaborator(opts.User.ID) | ||||
if isCollaborator ||datasets[i].Repo.IsOwnedBy(opts.User.ID){ | |||||
isInRepoTeam,_:=datasets[i].Repo.IsInRepoTeam(opts.User.ID) | |||||
if isCollaborator ||isInRepoTeam { | |||||
log.Info("Collaborator user may visit the attach.") | log.Info("Collaborator user may visit the attach.") | ||||
permission = true | permission = true | ||||
} | } | ||||
@@ -130,6 +130,20 @@ func (repo *Repository) IsCollaborator(userID int64) (bool, error) { | |||||
return repo.isCollaborator(x, userID) | return repo.isCollaborator(x, userID) | ||||
} | } | ||||
func (repo *Repository) IsInRepoTeam(userID int64) (bool, error) { | |||||
teams,err:=repo.GetRepoTeams() | |||||
if err!=nil || len(teams)==0{ | |||||
return false,err | |||||
} | |||||
for _,team :=range teams{ | |||||
if team.IsMember(userID){ | |||||
return true,nil | |||||
} | |||||
} | |||||
return false,nil | |||||
} | |||||
func (repo *Repository) changeCollaborationAccessMode(e Engine, uid int64, mode AccessMode) error { | func (repo *Repository) changeCollaborationAccessMode(e Engine, uid int64, mode AccessMode) error { | ||||
// Discard invalid input | // Discard invalid input | ||||
if mode <= AccessModeNone || mode > AccessModeOwner { | if mode <= AccessModeNone || mode > AccessModeOwner { | ||||
@@ -45,15 +45,10 @@ func newFilterPrivateAttachments(ctx *context.Context, list []*models.Attachment | |||||
repo.GetOwner() | repo.GetOwner() | ||||
} | } | ||||
permission := false | permission := false | ||||
if repo.Owner.IsOrganization() && ctx.User != nil { | |||||
if repo.Owner.IsUserPartOfOrg(ctx.User.ID) { | |||||
log.Info("user is member of org.") | |||||
permission = true | |||||
} | |||||
} | |||||
if !permission && ctx.User != nil { | if !permission && ctx.User != nil { | ||||
isCollaborator, _ := repo.IsCollaborator(ctx.User.ID) | isCollaborator, _ := repo.IsCollaborator(ctx.User.ID) | ||||
if isCollaborator { | |||||
isInRepoTeam,_:=repo.IsInRepoTeam(ctx.User.ID) | |||||
if isCollaborator ||isInRepoTeam { | |||||
log.Info("Collaborator user may visit the attach.") | log.Info("Collaborator user may visit the attach.") | ||||
permission = true | permission = true | ||||
} | } | ||||