// 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 ( "github.com/Unknwon/com" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/setting" ) const ( SETTINGS_OPTIONS base.TplName = "org/settings/options" SETTINGS_DELETE base.TplName = "org/settings/delete" SETTINGS_HOOKS base.TplName = "org/settings/hooks" ) func Settings(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("org.settings") ctx.Data["PageIsSettingsOptions"] = true ctx.HTML(200, SETTINGS_OPTIONS) } func SettingsPost(ctx *middleware.Context, form auth.UpdateOrgSettingForm) { ctx.Data["Title"] = ctx.Tr("org.settings") ctx.Data["PageIsSettingsOptions"] = true if ctx.HasError() { ctx.HTML(200, SETTINGS_OPTIONS) return } org := ctx.Org.Organization // Check if organization name has been changed. if org.Name != form.OrgUserName { isExist, err := models.IsUserExist(org.Id, form.OrgUserName) if err != nil { ctx.Handle(500, "IsUserExist", err) return } else if isExist { ctx.Data["Err_UserName"] = true ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), SETTINGS_OPTIONS, &form) return } else if err = models.ChangeUserName(org, form.OrgUserName); err != nil { if err == models.ErrUserNameIllegal { ctx.Data["Err_UserName"] = true ctx.RenderWithErr(ctx.Tr("form.illegal_username"), SETTINGS_OPTIONS, &form) } else { ctx.Handle(500, "ChangeUserName", err) } return } log.Trace("Organization name changed: %s -> %s", org.Name, form.OrgUserName) org.Name = form.OrgUserName } org.FullName = form.OrgFullName org.Email = form.Email org.Description = form.Description org.Website = form.Website org.Location = form.Location org.Avatar = base.EncodeMd5(form.Avatar) org.AvatarEmail = form.Avatar if err := models.UpdateUser(org); err != nil { if err == models.ErrEmailAlreadyUsed { ctx.Data["Err_Email"] = true ctx.RenderWithErr(ctx.Tr("form.email_been_used"), SETTINGS_OPTIONS, &form) } else { ctx.Handle(500, "UpdateUser", err) } return } log.Trace("Organization setting updated: %s", org.Name) ctx.Flash.Success(ctx.Tr("org.settings.update_setting_success")) ctx.Redirect(setting.AppSubUrl + "/org/" + org.Name + "/settings") } func SettingsDelete(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("org.settings") ctx.Data["PageIsSettingsDelete"] = true org := ctx.Org.Organization if ctx.Req.Method == "POST" { // FIXME: validate password. if err := models.DeleteOrganization(org); err != nil { if models.IsErrUserOwnRepos(err) { ctx.Flash.Error(ctx.Tr("form.org_still_own_repo")) ctx.Redirect(setting.AppSubUrl + "/org/" + org.LowerName + "/settings/delete") } else { ctx.Handle(500, "DeleteOrganization", err) } } else { log.Trace("Organization deleted: %s", org.Name) ctx.Redirect(setting.AppSubUrl + "/" backport/48689/stable29 backport/48689/stable30 backport/48696/stable28 backport/48696/stable29 backport/48696/stable30 backport/48723/stable30 backport/48728/stable30 backport/48736/stable27 backport/48736/stable28 backport/48736/stable29 backport/48736/stable30 backport/48737/stable30 backport/48743/stable29 backport/48743/stable30 backport/48749/stable27 backport/48760/stable30 backport/48766/stable28 backport/48766/stable29 backport/48766/stable30 backport/48769/stable29 backport/48769/stable30 backport/48787/stable30 backport/48788/stable27 backport/48788/stable28 backport/48788/stable29 backport/48788/stable30 backport/48799/stable30 backport/48809/stable30 backport/48824/stable29 backport/48833/stable30 backport/48839/stable28 backport/48839/stable29 backport/48839/stable30 backport/48850/stable30 backport/48852/stable30 backport/48853/stable30 backport/48854/stable30 backport/48863/stable30 backport/48871/stable29 backport/48871/stable30 backport/48882/stable30 backport/48887/stable29 backport/48887/stable30 backport/48889/stable28 backport/48898/stable28 backport/48898/stable29 backport/48898/stable30 backport/48912/stable30 backport/48915/stable28 backport/48915/stable29 backport/48915/stable30 backport/48917/stable25 backport/48917/stable26 backport/48917/stable27 backport/48917/stable28 backport/48917/stable29 backport/48917/stable30 backport/48918/stable28 backport/48918/stable29 backport/48918/stable30 backport/48921/stable25 backport/48921/stable26 backport/48921/stable27 backport/48921/stable28 backport/48921/stable29 backport/48921/stable30 backport/48933/stable28 backport/48933/stable29 backport/48933/stable30 backport/48934/stable28 backport/48947/stable28 backport/48947/stable29 backport/48947/stable30 backport/48991/stable29 backport/48991/stable30 backport/48992/stable27 backport/48992/stable28 backport/48992/stable29 backport/48992/stable30 backport/49004/stable28 backport/49004/stable29 backport/49004/stable30 backport/49009/49009-stable29