mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-19 15:14:40 +09:00
Adds a repository-level **"Restrict to collaborators"** option under the Issues and Pull Request unit settings. When enabled, only users with collaborator access to the base repository (owner, team members, or explicit collaborators) can open issues or pull requests against it. Public repositories often need to be visible/cloneable by everyone, but owners may want to limit who can open pull requests (e.g. restrict to an internal team while still keeping the code public) * Fixes: https://github.com/go-gitea/gitea/issues/40015 * Fixes: https://github.com/go-gitea/gitea/issues/31890 * Fixes: https://github.com/go-gitea/gitea/issues/28021 * Fixes: https://github.com/go-gitea/gitea/issues/14801 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
30 lines
844 B
Go
30 lines
844 B
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package issue
|
|
|
|
import (
|
|
"gitea.dev/models/issues"
|
|
"gitea.dev/models/perm/access"
|
|
repo_model "gitea.dev/models/repo"
|
|
"gitea.dev/models/unit"
|
|
"gitea.dev/modules/util"
|
|
)
|
|
|
|
func CheckCreationRestriction(perm access.Permission, unitType unit.Type, restriction string) error {
|
|
switch restriction {
|
|
case repo_model.CreationRestrictionMember:
|
|
if !perm.CanRead(unitType) {
|
|
return issues.Errors().MustRepoUnitReader
|
|
}
|
|
if !perm.IsMemberOrCollaborator() {
|
|
return issues.Errors().MustMemberOrCollaborator
|
|
}
|
|
return nil
|
|
case repo_model.CreationRestrictionWriter:
|
|
return util.Iif(perm.CanWrite(unitType), nil, issues.Errors().MustRepoUnitWriter)
|
|
default:
|
|
return util.Iif(perm.CanRead(unitType), nil, issues.Errors().MustRepoUnitReader)
|
|
}
|
|
}
|