Improve behavior of "Fork" button (#17288)
* Improbe behaviour of fork button * Apply suggestions from code review * Remove old lines * Apply suggestions * Fix test * Remove unnecessary or * Update templates/repo/header.tmpl Co-authored-by: silverwind <me@silverwind.io> * Add comment * Fix situation if you can't fork but don't have forks * Fix lint * Apply changes from #17783 * fmt * fmt * Apply tweaks Co-authored by: silverwind <me@silverwind.io> * Rm dupl css * Fix build Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
e0118b0d9b
commit
c3eea2f8af
5 changed files with 97 additions and 5 deletions
|
@ -294,6 +294,36 @@ func CanUserForkRepo(user *user_model.User, repo *repo_model.Repository) (bool,
|
|||
return false, nil
|
||||
}
|
||||
|
||||
// GetForksByUserAndOrgs return forked repos of the user and owned orgs
|
||||
func GetForksByUserAndOrgs(user *user_model.User, repo *repo_model.Repository) ([]*repo_model.Repository, error) {
|
||||
var repoList []*repo_model.Repository
|
||||
if user == nil {
|
||||
return repoList, nil
|
||||
}
|
||||
var forkedRepo *repo_model.Repository
|
||||
forkedRepo, err := repo_model.GetUserFork(repo.ID, user.ID)
|
||||
if err != nil {
|
||||
return repoList, err
|
||||
}
|
||||
if forkedRepo != nil {
|
||||
repoList = append(repoList, forkedRepo)
|
||||
}
|
||||
canCreateRepos, err := GetOrgsCanCreateRepoByUserID(user.ID)
|
||||
if err != nil {
|
||||
return repoList, err
|
||||
}
|
||||
for _, org := range canCreateRepos {
|
||||
forkedRepo, err := repo_model.GetUserFork(repo.ID, org.ID)
|
||||
if err != nil {
|
||||
return repoList, err
|
||||
}
|
||||
if forkedRepo != nil {
|
||||
repoList = append(repoList, forkedRepo)
|
||||
}
|
||||
}
|
||||
return repoList, nil
|
||||
}
|
||||
|
||||
// CanUserDelete returns true if user could delete the repository
|
||||
func CanUserDelete(repo *repo_model.Repository, user *user_model.User) (bool, error) {
|
||||
if user.IsAdmin || user.ID == repo.OwnerID {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue