summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorDavid Svantesson <davidsvantesson@gmail.com>2019-11-20 12:27:49 +0100
committerLunny Xiao <xiaolunwen@gmail.com>2019-11-20 19:27:49 +0800
commit69a255defbf2747b066b2aeee66ba76cdd37104d (patch)
tree8cc6f166c06ff9ac334b3f5f69476fa4394ae6a2 /modules
parent35c3ea952a6eb558e69de55fc94d301676feb935 (diff)
downloadgitea-69a255defbf2747b066b2aeee66ba76cdd37104d.tar.gz
gitea-69a255defbf2747b066b2aeee66ba76cdd37104d.zip
Team permission to create repository in organization (#8312)
* Add team permission setting to allow creating repo in organization. Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Add test case for creating repo when have team creation access. Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * build error: should omit comparison to bool constant Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Add comment on exported functions * Fix fixture consistency, fix existing unit tests * Fix boolean comparison in xorm query. * addCollaborator and changeCollaborationAccessMode separate steps More clear to use different if-cases. * Create and commit xorm session * fix * Add information of create repo permission in team sidebar * Add migration step * Clarify that repository creator will be administrator. * Fix some things after merge * Fix language text that use html * migrations file * Create repository permission -> Create repositories * fix merge * fix review comments
Diffstat (limited to 'modules')
-rw-r--r--modules/auth/org.go11
-rw-r--r--modules/context/org.go21
-rw-r--r--modules/convert/convert.go1
-rw-r--r--modules/structs/org_team.go9
4 files changed, 28 insertions, 14 deletions
diff --git a/modules/auth/org.go b/modules/auth/org.go
index 509358882a..20e2b09997 100644
--- a/modules/auth/org.go
+++ b/modules/auth/org.go
@@ -58,11 +58,12 @@ func (f *UpdateOrgSettingForm) Validate(ctx *macaron.Context, errs binding.Error
// CreateTeamForm form for creating team
type CreateTeamForm struct {
- TeamName string `binding:"Required;AlphaDashDot;MaxSize(30)"`
- Description string `binding:"MaxSize(255)"`
- Permission string
- Units []models.UnitType
- RepoAccess string
+ TeamName string `binding:"Required;AlphaDashDot;MaxSize(30)"`
+ Description string `binding:"MaxSize(255)"`
+ Permission string
+ Units []models.UnitType
+ RepoAccess string
+ CanCreateOrgRepo bool
}
// Validate validates the fields
diff --git a/modules/context/org.go b/modules/context/org.go
index 10791c9d01..ae19aebfcc 100644
--- a/modules/context/org.go
+++ b/modules/context/org.go
@@ -15,12 +15,13 @@ import (
// Organization contains organization context
type Organization struct {
- IsOwner bool
- IsMember bool
- IsTeamMember bool // Is member of team.
- IsTeamAdmin bool // In owner team or team that has admin permission level.
- Organization *models.User
- OrgLink string
+ IsOwner bool
+ IsMember bool
+ IsTeamMember bool // Is member of team.
+ IsTeamAdmin bool // In owner team or team that has admin permission level.
+ Organization *models.User
+ OrgLink string
+ CanCreateOrgRepo bool
Team *models.Team
}
@@ -73,6 +74,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
ctx.Org.IsMember = true
ctx.Org.IsTeamMember = true
ctx.Org.IsTeamAdmin = true
+ ctx.Org.CanCreateOrgRepo = true
} else if ctx.IsSigned {
ctx.Org.IsOwner, err = org.IsOwnedBy(ctx.User.ID)
if err != nil {
@@ -84,12 +86,18 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
ctx.Org.IsMember = true
ctx.Org.IsTeamMember = true
ctx.Org.IsTeamAdmin = true
+ ctx.Org.CanCreateOrgRepo = true
} else {
ctx.Org.IsMember, err = org.IsOrgMember(ctx.User.ID)
if err != nil {
ctx.ServerError("IsOrgMember", err)
return
}
+ ctx.Org.CanCreateOrgRepo, err = org.CanCreateOrgRepo(ctx.User.ID)
+ if err != nil {
+ ctx.ServerError("CanCreateOrgRepo", err)
+ return
+ }
}
} else {
// Fake data.
@@ -102,6 +110,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
}
ctx.Data["IsOrganizationOwner"] = ctx.Org.IsOwner
ctx.Data["IsOrganizationMember"] = ctx.Org.IsMember
+ ctx.Data["CanCreateOrgRepo"] = ctx.Org.CanCreateOrgRepo
ctx.Org.OrgLink = setting.AppSubURL + "/org/" + org.Name
ctx.Data["OrgLink"] = ctx.Org.OrgLink
diff --git a/modules/convert/convert.go b/modules/convert/convert.go
index f65e4b4fe2..d3b2e38165 100644
--- a/modules/convert/convert.go
+++ b/modules/convert/convert.go
@@ -249,6 +249,7 @@ func ToTeam(team *models.Team) *api.Team {
Name: team.Name,
Description: team.Description,
IncludesAllRepositories: team.IncludesAllRepositories,
+ CanCreateOrgRepo: team.CanCreateOrgRepo,
Permission: team.Authorize.String(),
Units: team.GetUnitNames(),
}
diff --git a/modules/structs/org_team.go b/modules/structs/org_team.go
index 5053468b4a..16f83823d6 100644
--- a/modules/structs/org_team.go
+++ b/modules/structs/org_team.go
@@ -15,7 +15,8 @@ type Team struct {
// enum: none,read,write,admin,owner
Permission string `json:"permission"`
// example: ["repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.pulls","repo.releases","repo.ext_wiki"]
- Units []string `json:"units"`
+ Units []string `json:"units"`
+ CanCreateOrgRepo bool `json:"can_create_org_repo"`
}
// CreateTeamOption options for creating a team
@@ -27,7 +28,8 @@ type CreateTeamOption struct {
// enum: read,write,admin
Permission string `json:"permission"`
// example: ["repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.pulls","repo.releases","repo.ext_wiki"]
- Units []string `json:"units"`
+ Units []string `json:"units"`
+ CanCreateOrgRepo bool `json:"can_create_org_repo"`
}
// EditTeamOption options for editing a team
@@ -39,5 +41,6 @@ type EditTeamOption struct {
// enum: read,write,admin
Permission string `json:"permission"`
// example: ["repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.pulls","repo.releases","repo.ext_wiki"]
- Units []string `json:"units"`
+ Units []string `json:"units"`
+ CanCreateOrgRepo bool `json:"can_create_org_repo"`
}