parent
2935ee440c
commit
5acc948562
@ -0,0 +1,55 @@ |
||||
// 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 middleware |
||||
|
||||
import ( |
||||
"github.com/Unknwon/macaron" |
||||
|
||||
"github.com/gogits/gogs/models" |
||||
) |
||||
|
||||
func OrgAssignment(redirect bool, args ...bool) macaron.Handler { |
||||
return func(ctx *Context) { |
||||
var ( |
||||
requireMember bool |
||||
requireOwner bool |
||||
) |
||||
if len(args) >= 1 { |
||||
requireMember = args[0] |
||||
} |
||||
if len(args) >= 2 { |
||||
requireOwner = args[1] |
||||
} |
||||
|
||||
orgName := ctx.Params(":org") |
||||
|
||||
var err error |
||||
ctx.Org.Organization, err = models.GetUserByName(orgName) |
||||
if err != nil { |
||||
if err == models.ErrUserNotExist { |
||||
ctx.Handle(404, "GetUserByName", err) |
||||
} else if redirect { |
||||
ctx.Redirect("/") |
||||
} else { |
||||
ctx.Handle(500, "GetUserByName", err) |
||||
} |
||||
return |
||||
} |
||||
ctx.Data["Org"] = ctx.Org.Organization |
||||
|
||||
if ctx.IsSigned { |
||||
ctx.Org.IsOwner = ctx.Org.Organization.IsOrgOwner(ctx.User.Id) |
||||
if ctx.Org.IsOwner { |
||||
ctx.Org.IsMember = true |
||||
} else { |
||||
ctx.Org.IsMember = ctx.Org.Organization.IsOrgMember(ctx.User.Id) |
||||
} |
||||
} |
||||
if (requireMember && !ctx.Org.IsMember) || (requireOwner && !ctx.Org.IsOwner) { |
||||
ctx.Handle(404, "OrgAssignment", err) |
||||
return |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,99 @@ |
||||
// 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/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" |
||||
) |
||||
|
||||
const ( |
||||
SETTINGS_OPTIONS base.TplName = "org/settings/options" |
||||
SETTINGS_DELETE base.TplName = "org/settings/delete" |
||||
) |
||||
|
||||
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(form.OrgUserName) |
||||
if err != nil { |
||||
ctx.Handle(500, "IsUserExist", err) |
||||
return |
||||
} else if isExist { |
||||
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.Flash.Error(ctx.Tr("form.illegal_username")) |
||||
ctx.Redirect("/org/" + org.LowerName + "/settings") |
||||
return |
||||
} 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 { |
||||
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("/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" { |
||||
// TODO: validate password.
|
||||
if err := models.DeleteOrganization(org); err != nil { |
||||
switch err { |
||||
case models.ErrUserOwnRepos: |
||||
ctx.Flash.Error(ctx.Tr("form.org_still_own_repo")) |
||||
ctx.Redirect("/org/" + org.LowerName + "/settings/delete") |
||||
default: |
||||
ctx.Handle(500, "DeleteOrganization", err) |
||||
} |
||||
} else { |
||||
log.Trace("Organization deleted: %s", ctx.User.Name) |
||||
ctx.Redirect("/") |
||||
} |
||||
return |
||||
} |
||||
|
||||
ctx.HTML(200, SETTINGS_DELETE) |
||||
} |
@ -1 +1 @@ |
||||
0.4.7.0810 Alpha |
||||
0.4.7.0814 Alpha |
@ -0,0 +1,28 @@ |
||||
{{template "ng/base/head" .}} |
||||
{{template "ng/base/header" .}} |
||||
<div id="setting-wrapper" class="main-wrapper"> |
||||
<div id="org-setting" class="container clear"> |
||||
{{template "org/settings/nav" .}} |
||||
<div class="grid-4-5 left"> |
||||
<div class="setting-content"> |
||||
{{template "ng/base/alert" .}} |
||||
<div id="setting-content"> |
||||
<div id="user-profile-setting-content" class="panel panel-warning panel-radius"> |
||||
<p class="panel-header"><strong>{{.i18n.Tr "org.settings.delete_account"}}</strong></p> |
||||
<div class="panel-body panel-content"> |
||||
<span class="alert alert-red alert-radius block"><i class="octicon octicon-alert"></i>{{.i18n.Tr "org.settings.delete_prompt" | Str2html}}</span> |
||||
<form action="/org/{{.Org.LowerName}}/settings/delete" method="post"> |
||||
{{.CsrfTokenHtml}} |
||||
<p class="field"> |
||||
<span class="form-label"></span> |
||||
<button class="btn btn-red btn-large btn-radius" id="delete-org-button">{{.i18n.Tr "org.settings.confirm_delete_account"}}</button> |
||||
</p> |
||||
</form> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
{{template "ng/base/footer" .}} |
@ -0,0 +1,11 @@ |
||||
<div id="setting-menu" class="grid-1-5 panel panel-radius left"> |
||||
<div class="panel-header"> |
||||
<strong>{{.i18n.Tr "org.settings"}}</strong> |
||||
</div> |
||||
<div class="panel-body"> |
||||
<ul class="menu menu-vertical switching-list grid-1-5 left"> |
||||
<li {{if .PageIsSettingsOptions}}class="current"{{end}}><a href="/org/{{.Org.LowerName}}/settings">{{.i18n.Tr "org.settings.options"}}</a></li> |
||||
<li {{if .PageIsSettingsDelete}}class="current"{{end}}><a href="/org/{{.Org.LowerName}}/settings/delete">{{.i18n.Tr "org.settings.delete"}}</a></li> |
||||
</ul> |
||||
</div> |
||||
</div> |
@ -0,0 +1,56 @@ |
||||
{{template "ng/base/head" .}} |
||||
{{template "ng/base/header" .}} |
||||
<div id="setting-wrapper" class="main-wrapper"> |
||||
<div id="org-setting" class="container clear"> |
||||
{{template "org/settings/nav" .}} |
||||
<div class="grid-4-5 left"> |
||||
<div class="setting-content"> |
||||
{{template "ng/base/alert" .}} |
||||
<div id="setting-content"> |
||||
<div id="user-profile-setting-content" class="panel panel-radius"> |
||||
<div class="panel-header"> |
||||
<strong>{{.i18n.Tr "org.settings.options"}}</strong> |
||||
</div> |
||||
<form class="form form-align panel-body" id="org-setting-form" action="/org/{{.Org.LowerName}}/settings" method="post"> |
||||
{{.CsrfTokenHtml}} |
||||
<input type="hidden" name="action" value="update"> |
||||
<div class="field"> |
||||
<label class="req" for="orgname">{{.i18n.Tr "username"}}</label> |
||||
<input class="ipt ipt-large ipt-radius {{if .Err_UserName}}ipt-error{{end}}" id="orgname" name="uname" value="{{.Org.Name}}" data-orgname="{{.Org.Name}}" required /> |
||||
</div> |
||||
<div class="field"> |
||||
<label for="full-name">{{.i18n.Tr "org.settings.full_name"}}</label> |
||||
<input class="ipt ipt-large ipt-radius {{if .Err_FullName}}ipt-error{{end}}" id="full-name" name="fullname" value="{{.Org.FullName}}" /> |
||||
</div> |
||||
<div class="field"> |
||||
<label class="req" for="email">{{.i18n.Tr "email"}}</label> |
||||
<input class="ipt ipt-large ipt-radius {{if .Err_Email}}ipt-error{{end}}" id="email" name="email" type="email" value="{{.Org.Email}}" required /> |
||||
</div> |
||||
<div class="field clear"> |
||||
<label class="left" for="desc">{{.i18n.Tr "org.org_desc"}}</label> |
||||
<textarea class="ipt ipt-large ipt-radius {{if .Err_Description}}ipt-error{{end}}" id="desc" name="desc">{{.Org.Description}}</textarea> |
||||
</div> |
||||
<div class="field"> |
||||
<label for="website">{{.i18n.Tr "org.settings.website"}}</label> |
||||
<input class="ipt ipt-large ipt-radius {{if .Err_Website}}ipt-error{{end}}" id="website" name="website" type="url" value="{{.Org.Website}}" /> |
||||
</div> |
||||
<div class="field"> |
||||
<label for="location">{{.i18n.Tr "org.settings.location"}}</label> |
||||
<input class="ipt ipt-large ipt-radius {{if .Err_Location}}ipt-error{{end}}" id="location" name="location" type="text" value="{{.Org.Location}}" /> |
||||
</div> |
||||
<div class="field"> |
||||
<label for="gravatar-email">Gravatar {{.i18n.Tr "email"}}</label> |
||||
<input class="ipt ipt-large ipt-radius {{if .Err_Avatar}}ipt-error{{end}}" id="gravatar-email" name="avatar" type="text" value="{{.Org.AvatarEmail}}" /> |
||||
</div> |
||||
<div class="field"> |
||||
<span class="form-label"></span> |
||||
<button class="btn btn-green btn-large btn-radius">{{.i18n.Tr "org.settings.update_settings"}}</button> |
||||
</div> |
||||
</form> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
{{template "ng/base/footer" .}} |
Loading…
Reference in new issue