mirror of
https://github.com/go-gitea/gitea.git
synced 2025-12-09 04:41:48 +01:00
Revert "Add UnitCommitStatus"
This reverts commit 7c5cc63dc61f96ab94eb188e9103f9d1b5d8a493.
This commit is contained in:
parent
7c5cc63dc6
commit
d9e9f8878d
@ -33,7 +33,6 @@ const (
|
|||||||
TypeProjects // 8 Projects
|
TypeProjects // 8 Projects
|
||||||
TypePackages // 9 Packages
|
TypePackages // 9 Packages
|
||||||
TypeActions // 10 Actions
|
TypeActions // 10 Actions
|
||||||
TypeCommitStatus // 11 Commit Status
|
|
||||||
|
|
||||||
// FIXME: TEAM-UNIT-PERMISSION: the team unit "admin" permission's design is not right, when a new unit is added in the future,
|
// FIXME: TEAM-UNIT-PERMISSION: the team unit "admin" permission's design is not right, when a new unit is added in the future,
|
||||||
// admin team won't inherit the correct admin permission for the new unit, need to have a complete fix before adding any new unit.
|
// admin team won't inherit the correct admin permission for the new unit, need to have a complete fix before adding any new unit.
|
||||||
@ -66,7 +65,6 @@ var (
|
|||||||
TypeProjects,
|
TypeProjects,
|
||||||
TypePackages,
|
TypePackages,
|
||||||
TypeActions,
|
TypeActions,
|
||||||
TypeCommitStatus,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultRepoUnits contains the default unit types
|
// DefaultRepoUnits contains the default unit types
|
||||||
@ -79,10 +77,8 @@ var (
|
|||||||
TypeProjects,
|
TypeProjects,
|
||||||
TypePackages,
|
TypePackages,
|
||||||
TypeActions,
|
TypeActions,
|
||||||
TypeCommitStatus,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(not7cd): Defaults that need TypeCommitStatus
|
|
||||||
// ForkRepoUnits contains the default unit types for forks
|
// ForkRepoUnits contains the default unit types for forks
|
||||||
DefaultForkRepoUnits = []Type{
|
DefaultForkRepoUnits = []Type{
|
||||||
TypeCode,
|
TypeCode,
|
||||||
@ -241,7 +237,6 @@ func (u Unit) MaxPerm() perm.AccessMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Enumerate all the units
|
// Enumerate all the units
|
||||||
// TODO(not7cd): Add TypeCommitStatus
|
|
||||||
var (
|
var (
|
||||||
UnitCode = Unit{
|
UnitCode = Unit{
|
||||||
TypeCode,
|
TypeCode,
|
||||||
@ -333,16 +328,6 @@ var (
|
|||||||
perm.AccessModeOwner,
|
perm.AccessModeOwner,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(not7cd): Just copied this
|
|
||||||
UnitCommitStatus = Unit{
|
|
||||||
TypeCommitStatus,
|
|
||||||
"repo.commitstatus",
|
|
||||||
"/statuses",
|
|
||||||
"commitstatus.unit.desc",
|
|
||||||
8,
|
|
||||||
perm.AccessModeOwner,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Units contains all the units
|
// Units contains all the units
|
||||||
Units = map[Type]Unit{
|
Units = map[Type]Unit{
|
||||||
TypeCode: UnitCode,
|
TypeCode: UnitCode,
|
||||||
@ -355,7 +340,6 @@ var (
|
|||||||
TypeProjects: UnitProjects,
|
TypeProjects: UnitProjects,
|
||||||
TypePackages: UnitPackages,
|
TypePackages: UnitPackages,
|
||||||
TypeActions: UnitActions,
|
TypeActions: UnitActions,
|
||||||
TypeCommitStatus: UnitCommitStatus,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -455,6 +455,28 @@ func reqRepoWriter(unitTypes ...unit.Type) func(ctx *context.APIContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reqRepoCommitStatusWriter user should have a permission to write to commit
|
||||||
|
// statuses, or write to a repo, or be a site admin
|
||||||
|
func reqRepoCommitStatusWriter(unitTypes ...unit.Type) func(ctx *context.APIContext) {
|
||||||
|
return func(ctx *context.APIContext) {
|
||||||
|
// TODO(not7cd)
|
||||||
|
if !ctx.IsUserRepoWriter(unitTypes) && !ctx.IsUserRepoAdmin() && !ctx.IsUserSiteAdmin() {
|
||||||
|
ctx.APIError(http.StatusForbidden, "user should have a permission to write to a repo")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(not7cd): do I need this?
|
||||||
|
// // reqRepoBranchWriter user should have a permission to write to a branch, or be a site admin
|
||||||
|
// func reqRepoBranchWriter(ctx *context.APIContext) {
|
||||||
|
// options, ok := web.GetForm(ctx).(api.FileOptionInterface)
|
||||||
|
// if !ok || (!ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, options.Branch()) && !ctx.IsUserSiteAdmin()) {
|
||||||
|
// ctx.APIError(http.StatusForbidden, "user should have a permission to write to this branch")
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// reqRepoReader user should have specific read permission or be a repo admin or a site admin
|
// reqRepoReader user should have specific read permission or be a repo admin or a site admin
|
||||||
func reqRepoReader(unitType unit.Type) func(ctx *context.APIContext) {
|
func reqRepoReader(unitType unit.Type) func(ctx *context.APIContext) {
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
@ -465,6 +487,18 @@ func reqRepoReader(unitType unit.Type) func(ctx *context.APIContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reqRepoReader user should have specific commit status read permission, or
|
||||||
|
// repo read permission, or be a repo admin or a site admin
|
||||||
|
func reqRepoCommitStatusReader(unitType unit.Type) func(ctx *context.APIContext) {
|
||||||
|
return func(ctx *context.APIContext) {
|
||||||
|
// TODO(not7cd)
|
||||||
|
if !ctx.Repo.CanRead(unitType) && !ctx.IsUserRepoAdmin() && !ctx.IsUserSiteAdmin() {
|
||||||
|
ctx.APIError(http.StatusForbidden, "user should have specific read permission or be a repo admin or a site admin")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// reqAnyRepoReader user should have any permission to read repository or permissions of site admin
|
// reqAnyRepoReader user should have any permission to read repository or permissions of site admin
|
||||||
func reqAnyRepoReader() func(ctx *context.APIContext) {
|
func reqAnyRepoReader() func(ctx *context.APIContext) {
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
@ -1399,8 +1433,8 @@ func Routes() *web.Router {
|
|||||||
}, mustAllowPulls, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo())
|
}, mustAllowPulls, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo())
|
||||||
m.Group("/statuses", func() {
|
m.Group("/statuses", func() {
|
||||||
m.Combo("/{sha}").Get(repo.GetCommitStatuses).
|
m.Combo("/{sha}").Get(repo.GetCommitStatuses).
|
||||||
Post(reqToken(), reqRepoWriter(unit.TypeCommitStatus), bind(api.CreateStatusOption{}), repo.NewCommitStatus)
|
Post(reqToken(), reqRepoCommitStatusWriter(unit.TypeCode), bind(api.CreateStatusOption{}), repo.NewCommitStatus)
|
||||||
}, reqRepoWriter(unit.TypeCommitStatus))
|
}, reqRepoCommitStatusReader(unit.TypeCode))
|
||||||
m.Group("/commits", func() {
|
m.Group("/commits", func() {
|
||||||
m.Get("", context.ReferencesGitRepo(), repo.GetAllCommits)
|
m.Get("", context.ReferencesGitRepo(), repo.GetAllCommits)
|
||||||
m.Group("/{ref}", func() {
|
m.Group("/{ref}", func() {
|
||||||
|
|||||||
@ -367,3 +367,15 @@ func (ctx *APIContext) IsUserRepoAdmin() bool {
|
|||||||
func (ctx *APIContext) IsUserRepoWriter(unitTypes []unit.Type) bool {
|
func (ctx *APIContext) IsUserRepoWriter(unitTypes []unit.Type) bool {
|
||||||
return slices.ContainsFunc(unitTypes, ctx.Repo.CanWrite)
|
return slices.ContainsFunc(unitTypes, ctx.Repo.CanWrite)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsUserRepoWriter returns true if current user has write commit status privilege in current repo
|
||||||
|
func (ctx *APIContext) IsUserCommitStatusWriter(unitTypes []unit.Type) bool {
|
||||||
|
for _, unitType := range unitTypes {
|
||||||
|
// TODO
|
||||||
|
if ctx.Repo.CanWrite(unitType) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user