mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.5 KiB
80 lines
2.5 KiB
11 years ago
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||
6 years ago
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||
11 years ago
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
11 years ago
|
package org
|
||
|
|
||
|
import (
|
||
8 years ago
|
"errors"
|
||
4 years ago
|
"net/http"
|
||
8 years ago
|
|
||
8 years ago
|
"code.gitea.io/gitea/models"
|
||
|
"code.gitea.io/gitea/modules/base"
|
||
|
"code.gitea.io/gitea/modules/context"
|
||
|
"code.gitea.io/gitea/modules/log"
|
||
|
"code.gitea.io/gitea/modules/setting"
|
||
4 years ago
|
"code.gitea.io/gitea/modules/web"
|
||
4 years ago
|
"code.gitea.io/gitea/services/forms"
|
||
11 years ago
|
)
|
||
|
|
||
|
const (
|
||
8 years ago
|
// tplCreateOrg template path for create organization
|
||
|
tplCreateOrg base.TplName = "org/create"
|
||
11 years ago
|
)
|
||
|
|
||
8 years ago
|
// Create render the page for create organization
|
||
9 years ago
|
func Create(ctx *context.Context) {
|
||
10 years ago
|
ctx.Data["Title"] = ctx.Tr("new_org")
|
||
6 years ago
|
ctx.Data["DefaultOrgVisibilityMode"] = setting.Service.DefaultOrgVisibilityMode
|
||
8 years ago
|
if !ctx.User.CanCreateOrganization() {
|
||
7 years ago
|
ctx.ServerError("Not allowed", errors.New(ctx.Tr("org.form.create_org_not_allowed")))
|
||
8 years ago
|
return
|
||
|
}
|
||
4 years ago
|
ctx.HTML(http.StatusOK, tplCreateOrg)
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
// CreatePost response for create organization
|
||
4 years ago
|
func CreatePost(ctx *context.Context) {
|
||
4 years ago
|
form := *web.GetForm(ctx).(*forms.CreateOrgForm)
|
||
7 years ago
|
ctx.Data["Title"] = ctx.Tr("new_org")
|
||
|
|
||
7 years ago
|
if !ctx.User.CanCreateOrganization() {
|
||
7 years ago
|
ctx.ServerError("Not allowed", errors.New(ctx.Tr("org.form.create_org_not_allowed")))
|
||
|
return
|
||
7 years ago
|
}
|
||
|
|
||
11 years ago
|
if ctx.HasError() {
|
||
4 years ago
|
ctx.HTML(http.StatusOK, tplCreateOrg)
|
||
11 years ago
|
return
|
||
|
}
|
||
|
|
||
|
org := &models.User{
|
||
5 years ago
|
Name: form.OrgName,
|
||
|
IsActive: true,
|
||
|
Type: models.UserTypeOrganization,
|
||
|
Visibility: form.Visibility,
|
||
|
RepoAdminChangeTeamAccess: form.RepoAdminChangeTeamAccess,
|
||
11 years ago
|
}
|
||
|
|
||
9 years ago
|
if err := models.CreateOrganization(org, ctx.User); err != nil {
|
||
|
ctx.Data["Err_OrgName"] = true
|
||
10 years ago
|
switch {
|
||
|
case models.IsErrUserAlreadyExist(err):
|
||
8 years ago
|
ctx.RenderWithErr(ctx.Tr("form.org_name_been_taken"), tplCreateOrg, &form)
|
||
10 years ago
|
case models.IsErrNameReserved(err):
|
||
8 years ago
|
ctx.RenderWithErr(ctx.Tr("org.form.name_reserved", err.(models.ErrNameReserved).Name), tplCreateOrg, &form)
|
||
10 years ago
|
case models.IsErrNamePatternNotAllowed(err):
|
||
8 years ago
|
ctx.RenderWithErr(ctx.Tr("org.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplCreateOrg, &form)
|
||
8 years ago
|
case models.IsErrUserNotAllowedCreateOrg(err):
|
||
|
ctx.RenderWithErr(ctx.Tr("org.form.create_org_not_allowed"), tplCreateOrg, &form)
|
||
11 years ago
|
default:
|
||
7 years ago
|
ctx.ServerError("CreateOrganization", err)
|
||
11 years ago
|
}
|
||
|
return
|
||
|
}
|
||
10 years ago
|
log.Trace("Organization created: %s", org.Name)
|
||
11 years ago
|
|
||
4 years ago
|
ctx.Redirect(org.DashboardLink())
|
||
11 years ago
|
}
|