summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorqwerty287 <80460567+qwerty287@users.noreply.github.com>2021-12-13 02:59:09 +0100
committerGitHub <noreply@github.com>2021-12-13 09:59:09 +0800
commitc3eea2f8af599c94e49e687a80e91a14144b5ea6 (patch)
treee8253fe995d4bfec5ca1f629aac1a0981eda06fd /models
parente0118b0d9b1a8fe85c0ccfbbf0df87dd57b9241a (diff)
downloadgitea-c3eea2f8af599c94e49e687a80e91a14144b5ea6.tar.gz
gitea-c3eea2f8af599c94e49e687a80e91a14144b5ea6.zip
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>
Diffstat (limited to 'models')
-rw-r--r--models/repo.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/models/repo.go b/models/repo.go
index 397b4380d6..897ceeede9 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -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 {