mirror of https://github.com/gogits/gogs.git
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.
169 lines
4.5 KiB
169 lines
4.5 KiB
11 years ago
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package org
|
||
|
|
||
|
import (
|
||
9 years ago
|
"strings"
|
||
|
|
||
8 years ago
|
log "gopkg.in/clog.v1"
|
||
|
|
||
11 years ago
|
"github.com/gogits/gogs/models"
|
||
8 years ago
|
"github.com/gogits/gogs/models/errors"
|
||
8 years ago
|
"github.com/gogits/gogs/pkg/context"
|
||
|
"github.com/gogits/gogs/pkg/form"
|
||
|
"github.com/gogits/gogs/pkg/setting"
|
||
8 years ago
|
"github.com/gogits/gogs/routes/user"
|
||
11 years ago
|
)
|
||
|
|
||
|
const (
|
||
8 years ago
|
SETTINGS_OPTIONS = "org/settings/options"
|
||
|
SETTINGS_DELETE = "org/settings/delete"
|
||
|
SETTINGS_WEBHOOKS = "org/settings/webhooks"
|
||
11 years ago
|
)
|
||
|
|
||
8 years ago
|
func Settings(c *context.Context) {
|
||
|
c.Data["Title"] = c.Tr("org.settings")
|
||
|
c.Data["PageIsSettingsOptions"] = true
|
||
|
c.HTML(200, SETTINGS_OPTIONS)
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
func SettingsPost(c *context.Context, f form.UpdateOrgSetting) {
|
||
|
c.Data["Title"] = c.Tr("org.settings")
|
||
|
c.Data["PageIsSettingsOptions"] = true
|
||
11 years ago
|
|
||
8 years ago
|
if c.HasError() {
|
||
|
c.HTML(200, SETTINGS_OPTIONS)
|
||
11 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
org := c.Org.Organization
|
||
11 years ago
|
|
||
|
// Check if organization name has been changed.
|
||
8 years ago
|
if org.LowerName != strings.ToLower(f.Name) {
|
||
|
isExist, err := models.IsUserExist(org.ID, f.Name)
|
||
11 years ago
|
if err != nil {
|
||
8 years ago
|
c.Handle(500, "IsUserExist", err)
|
||
11 years ago
|
return
|
||
|
} else if isExist {
|
||
8 years ago
|
c.Data["OrgName"] = true
|
||
|
c.RenderWithErr(c.Tr("form.username_been_taken"), SETTINGS_OPTIONS, &f)
|
||
11 years ago
|
return
|
||
8 years ago
|
} else if err = models.ChangeUserName(org, f.Name); err != nil {
|
||
8 years ago
|
c.Data["OrgName"] = true
|
||
8 years ago
|
switch {
|
||
|
case models.IsErrNameReserved(err):
|
||
8 years ago
|
c.RenderWithErr(c.Tr("user.form.name_reserved"), SETTINGS_OPTIONS, &f)
|
||
8 years ago
|
case models.IsErrNamePatternNotAllowed(err):
|
||
8 years ago
|
c.RenderWithErr(c.Tr("user.form.name_pattern_not_allowed"), SETTINGS_OPTIONS, &f)
|
||
8 years ago
|
default:
|
||
8 years ago
|
c.Handle(500, "ChangeUserName", err)
|
||
11 years ago
|
}
|
||
|
return
|
||
|
}
|
||
8 years ago
|
// reset c.org.OrgLink with new name
|
||
|
c.Org.OrgLink = setting.AppSubURL + "/org/" + f.Name
|
||
8 years ago
|
log.Trace("Organization name changed: %s -> %s", org.Name, f.Name)
|
||
11 years ago
|
}
|
||
9 years ago
|
// In case it's just a case change.
|
||
8 years ago
|
org.Name = f.Name
|
||
|
org.LowerName = strings.ToLower(f.Name)
|
||
11 years ago
|
|
||
8 years ago
|
if c.User.IsAdmin {
|
||
8 years ago
|
org.MaxRepoCreation = f.MaxRepoCreation
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
org.FullName = f.FullName
|
||
|
org.Description = f.Description
|
||
|
org.Website = f.Website
|
||
|
org.Location = f.Location
|
||
11 years ago
|
if err := models.UpdateUser(org); err != nil {
|
||
8 years ago
|
c.Handle(500, "UpdateUser", err)
|
||
11 years ago
|
return
|
||
|
}
|
||
|
log.Trace("Organization setting updated: %s", org.Name)
|
||
8 years ago
|
c.Flash.Success(c.Tr("org.settings.update_setting_success"))
|
||
|
c.Redirect(c.Org.OrgLink + "/settings")
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
func SettingsAvatar(c *context.Context, f form.Avatar) {
|
||
8 years ago
|
f.Source = form.AVATAR_LOCAL
|
||
8 years ago
|
if err := user.UpdateAvatarSetting(c, f, c.Org.Organization); err != nil {
|
||
|
c.Flash.Error(err.Error())
|
||
9 years ago
|
} else {
|
||
8 years ago
|
c.Flash.Success(c.Tr("org.settings.update_avatar_success"))
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
c.Redirect(c.Org.OrgLink + "/settings")
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
func SettingsDeleteAvatar(c *context.Context) {
|
||
|
if err := c.Org.Organization.DeleteAvatar(); err != nil {
|
||
|
c.Flash.Error(err.Error())
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
c.Redirect(c.Org.OrgLink + "/settings")
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
func SettingsDelete(c *context.Context) {
|
||
|
c.Data["Title"] = c.Tr("org.settings")
|
||
|
c.Data["PageIsSettingsDelete"] = true
|
||
11 years ago
|
|
||
8 years ago
|
org := c.Org.Organization
|
||
|
if c.Req.Method == "POST" {
|
||
|
if _, err := models.UserSignIn(c.User.Name, c.Query("password")); err != nil {
|
||
8 years ago
|
if errors.IsUserNotExist(err) {
|
||
8 years ago
|
c.RenderWithErr(c.Tr("form.enterred_invalid_password"), SETTINGS_DELETE, nil)
|
||
9 years ago
|
} else {
|
||
8 years ago
|
c.Handle(500, "UserSignIn", err)
|
||
9 years ago
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
11 years ago
|
if err := models.DeleteOrganization(org); err != nil {
|
||
10 years ago
|
if models.IsErrUserOwnRepos(err) {
|
||
8 years ago
|
c.Flash.Error(c.Tr("form.org_still_own_repo"))
|
||
|
c.Redirect(c.Org.OrgLink + "/settings/delete")
|
||
10 years ago
|
} else {
|
||
8 years ago
|
c.Handle(500, "DeleteOrganization", err)
|
||
11 years ago
|
}
|
||
|
} else {
|
||
10 years ago
|
log.Trace("Organization deleted: %s", org.Name)
|
||
8 years ago
|
c.Redirect(setting.AppSubURL + "/")
|
||
11 years ago
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
c.HTML(200, SETTINGS_DELETE)
|
||
11 years ago
|
}
|
||
10 years ago
|
|
||
8 years ago
|
func Webhooks(c *context.Context) {
|
||
|
c.Data["Title"] = c.Tr("org.settings")
|
||
|
c.Data["PageIsSettingsHooks"] = true
|
||
|
c.Data["BaseLink"] = c.Org.OrgLink
|
||
|
c.Data["Description"] = c.Tr("org.settings.hooks_desc")
|
||
|
c.Data["Types"] = setting.Webhook.Types
|
||
10 years ago
|
|
||
8 years ago
|
ws, err := models.GetWebhooksByOrgID(c.Org.Organization.ID)
|
||
10 years ago
|
if err != nil {
|
||
8 years ago
|
c.Handle(500, "GetWebhooksByOrgId", err)
|
||
10 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
c.Data["Webhooks"] = ws
|
||
|
c.HTML(200, SETTINGS_WEBHOOKS)
|
||
10 years ago
|
}
|
||
9 years ago
|
|
||
8 years ago
|
func DeleteWebhook(c *context.Context) {
|
||
|
if err := models.DeleteWebhookOfOrgByID(c.Org.Organization.ID, c.QueryInt64("id")); err != nil {
|
||
|
c.Flash.Error("DeleteWebhookByOrgID: " + err.Error())
|
||
9 years ago
|
} else {
|
||
8 years ago
|
c.Flash.Success(c.Tr("repo.settings.webhook_deletion_success"))
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
c.JSON(200, map[string]interface{}{
|
||
|
"redirect": c.Org.OrgLink + "/settings/hooks",
|
||
9 years ago
|
})
|
||
|
}
|