Remove unit types commits and settings (#2161)
* Remove unit types commits and settings * Can not limit units in administrator teams * Limit changing units only to teams with read and write access mode * Small code optimization
This commit is contained in:
parent
047a67a90b
commit
f33e6ae09e
20 changed files with 174 additions and 104 deletions
|
@ -171,14 +171,18 @@ func NewTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
|
|||
ctx.Data["Title"] = ctx.Org.Organization.FullName
|
||||
ctx.Data["PageIsOrgTeams"] = true
|
||||
ctx.Data["PageIsOrgTeamsNew"] = true
|
||||
ctx.Data["Units"] = models.Units
|
||||
|
||||
t := &models.Team{
|
||||
OrgID: ctx.Org.Organization.ID,
|
||||
Name: form.TeamName,
|
||||
Description: form.Description,
|
||||
Authorize: models.ParseAccessMode(form.Permission),
|
||||
UnitTypes: form.Units,
|
||||
}
|
||||
if t.Authorize < models.AccessModeAdmin {
|
||||
t.UnitTypes = form.Units
|
||||
}
|
||||
|
||||
ctx.Data["Team"] = t
|
||||
|
||||
if ctx.HasError() {
|
||||
|
@ -186,6 +190,11 @@ func NewTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
|
|||
return
|
||||
}
|
||||
|
||||
if t.Authorize < models.AccessModeAdmin && len(form.Units) == 0 {
|
||||
ctx.RenderWithErr(ctx.Tr("form.team_no_units_error"), tplTeamNew, &form)
|
||||
return
|
||||
}
|
||||
|
||||
if err := models.NewTeam(t); err != nil {
|
||||
ctx.Data["Err_TeamName"] = true
|
||||
switch {
|
||||
|
@ -238,27 +247,12 @@ func EditTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
|
|||
ctx.Data["Title"] = ctx.Org.Organization.FullName
|
||||
ctx.Data["PageIsOrgTeams"] = true
|
||||
ctx.Data["Team"] = t
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, tplTeamNew)
|
||||
return
|
||||
}
|
||||
ctx.Data["Units"] = models.Units
|
||||
|
||||
isAuthChanged := false
|
||||
if !t.IsOwnerTeam() {
|
||||
// Validate permission level.
|
||||
var auth models.AccessMode
|
||||
switch form.Permission {
|
||||
case "read":
|
||||
auth = models.AccessModeRead
|
||||
case "write":
|
||||
auth = models.AccessModeWrite
|
||||
case "admin":
|
||||
auth = models.AccessModeAdmin
|
||||
default:
|
||||
ctx.Error(401)
|
||||
return
|
||||
}
|
||||
auth := models.ParseAccessMode(form.Permission)
|
||||
|
||||
t.Name = form.TeamName
|
||||
if t.Authorize != auth {
|
||||
|
@ -267,7 +261,22 @@ func EditTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
|
|||
}
|
||||
}
|
||||
t.Description = form.Description
|
||||
t.UnitTypes = form.Units
|
||||
if t.Authorize < models.AccessModeAdmin {
|
||||
t.UnitTypes = form.Units
|
||||
} else {
|
||||
t.UnitTypes = nil
|
||||
}
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, tplTeamNew)
|
||||
return
|
||||
}
|
||||
|
||||
if t.Authorize < models.AccessModeAdmin && len(form.Units) == 0 {
|
||||
ctx.RenderWithErr(ctx.Tr("form.team_no_units_error"), tplTeamNew, &form)
|
||||
return
|
||||
}
|
||||
|
||||
if err := models.UpdateTeam(t, isAuthChanged); err != nil {
|
||||
ctx.Data["Err_TeamName"] = true
|
||||
switch {
|
||||
|
|
|
@ -450,8 +450,8 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
|
||||
}, func(ctx *context.Context) {
|
||||
ctx.Data["PageIsSettings"] = true
|
||||
}, context.UnitTypes(), context.LoadRepoUnits(), context.CheckUnit(models.UnitTypeSettings))
|
||||
}, reqSignIn, context.RepoAssignment(), reqRepoAdmin, context.RepoRef())
|
||||
})
|
||||
}, reqSignIn, context.RepoAssignment(), reqRepoAdmin, context.UnitTypes(), context.LoadRepoUnits(), context.RepoRef())
|
||||
|
||||
m.Get("/:username/:reponame/action/:action", reqSignIn, context.RepoAssignment(), repo.Action)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue