c572fcfe04
Rename the Go module path from code.gitea.io/gitea to git.mokoconsulting.tech/MokoConsulting/MokoGitea across the entire codebase. Scope: - go.mod module declaration - 2,235 Go source files (import paths) - Dockerfile WORKDIR and COPY paths - Swagger API templates - golangci.yml linter config External dependencies (code.gitea.io/gitea-vet, code.gitea.io/sdk/gitea, gitea.com/gitea/act, etc.) are intentionally NOT renamed — they are separate upstream modules. Closes #132 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/models/organization"
|
|
repo_model "git.mokoconsulting.tech/MokoConsulting/MokoGitea/models/repo"
|
|
user_model "git.mokoconsulting.tech/MokoConsulting/MokoGitea/models/user"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/setting"
|
|
)
|
|
|
|
// CanUserForkBetweenOwners returns true if user can fork between owners.
|
|
// By default, a user can fork a repository from another owner, but not from themselves.
|
|
// Many users really like to fork their own repositories, so add an experimental setting to allow this.
|
|
func CanUserForkBetweenOwners(id1, id2 int64) bool {
|
|
if id1 != id2 {
|
|
return true
|
|
}
|
|
return setting.Repository.AllowForkIntoSameOwner
|
|
}
|
|
|
|
// CanUserForkRepo returns true if specified user can fork repository.
|
|
func CanUserForkRepo(ctx context.Context, user *user_model.User, repo *repo_model.Repository) (bool, error) {
|
|
if user == nil {
|
|
return false, nil
|
|
}
|
|
if CanUserForkBetweenOwners(repo.OwnerID, user.ID) && !repo_model.HasForkedRepo(ctx, user.ID, repo.ID) {
|
|
return true, nil
|
|
}
|
|
ownedOrgs, err := organization.GetOrgsCanCreateRepoByUserID(ctx, user.ID)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
for _, org := range ownedOrgs {
|
|
if repo.OwnerID != org.ID && !repo_model.HasForkedRepo(ctx, org.ID, repo.ID) {
|
|
return true, nil
|
|
}
|
|
}
|
|
return false, nil
|
|
}
|