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.
124 lines
2.6 KiB
124 lines
2.6 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 (
|
||
11 years ago
|
"github.com/Unknwon/com"
|
||
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/setting"
|
||
11 years ago
|
)
|
||
|
|
||
11 years ago
|
const (
|
||
8 years ago
|
MEMBERS = "org/member/members"
|
||
|
MEMBER_INVITE = "org/member/invite"
|
||
11 years ago
|
)
|
||
|
|
||
8 years ago
|
func Members(c *context.Context) {
|
||
|
org := c.Org.Organization
|
||
|
c.Data["Title"] = org.FullName
|
||
|
c.Data["PageIsOrgMembers"] = true
|
||
11 years ago
|
|
||
|
if err := org.GetMembers(); err != nil {
|
||
8 years ago
|
c.Handle(500, "GetMembers", err)
|
||
11 years ago
|
return
|
||
|
}
|
||
8 years ago
|
c.Data["Members"] = org.Members
|
||
11 years ago
|
|
||
8 years ago
|
c.HTML(200, MEMBERS)
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
func MembersAction(c *context.Context) {
|
||
|
uid := com.StrTo(c.Query("uid")).MustInt64()
|
||
11 years ago
|
if uid == 0 {
|
||
8 years ago
|
c.Redirect(c.Org.OrgLink + "/members")
|
||
11 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
org := c.Org.Organization
|
||
11 years ago
|
var err error
|
||
8 years ago
|
switch c.Params(":action") {
|
||
11 years ago
|
case "private":
|
||
8 years ago
|
if c.User.ID != uid && !c.Org.IsOwner {
|
||
|
c.Error(404)
|
||
11 years ago
|
return
|
||
|
}
|
||
9 years ago
|
err = models.ChangeOrgUserStatus(org.ID, uid, false)
|
||
11 years ago
|
case "public":
|
||
8 years ago
|
if c.User.ID != uid && !c.Org.IsOwner {
|
||
|
c.Error(404)
|
||
11 years ago
|
return
|
||
|
}
|
||
9 years ago
|
err = models.ChangeOrgUserStatus(org.ID, uid, true)
|
||
11 years ago
|
case "remove":
|
||
8 years ago
|
if !c.Org.IsOwner {
|
||
|
c.Error(404)
|
||
11 years ago
|
return
|
||
|
}
|
||
|
err = org.RemoveMember(uid)
|
||
10 years ago
|
if models.IsErrLastOrgOwner(err) {
|
||
8 years ago
|
c.Flash.Error(c.Tr("form.last_org_owner"))
|
||
|
c.Redirect(c.Org.OrgLink + "/members")
|
||
11 years ago
|
return
|
||
|
}
|
||
|
case "leave":
|
||
8 years ago
|
err = org.RemoveMember(c.User.ID)
|
||
10 years ago
|
if models.IsErrLastOrgOwner(err) {
|
||
8 years ago
|
c.Flash.Error(c.Tr("form.last_org_owner"))
|
||
|
c.Redirect(c.Org.OrgLink + "/members")
|
||
11 years ago
|
return
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|
||
|
if err != nil {
|
||
8 years ago
|
log.Error(4, "Action(%s): %v", c.Params(":action"), err)
|
||
|
c.JSON(200, map[string]interface{}{
|
||
11 years ago
|
"ok": false,
|
||
|
"err": err.Error(),
|
||
|
})
|
||
|
return
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
if c.Params(":action") != "leave" {
|
||
|
c.Redirect(c.Org.OrgLink + "/members")
|
||
10 years ago
|
} else {
|
||
8 years ago
|
c.Redirect(setting.AppSubURL + "/")
|
||
10 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
func Invitation(c *context.Context) {
|
||
|
org := c.Org.Organization
|
||
|
c.Data["Title"] = org.FullName
|
||
|
c.Data["PageIsOrgMembers"] = true
|
||
11 years ago
|
|
||
8 years ago
|
if c.Req.Method == "POST" {
|
||
|
uname := c.Query("uname")
|
||
11 years ago
|
u, err := models.GetUserByName(uname)
|
||
|
if err != nil {
|
||
8 years ago
|
if errors.IsUserNotExist(err) {
|
||
8 years ago
|
c.Flash.Error(c.Tr("form.user_not_exist"))
|
||
|
c.Redirect(c.Org.OrgLink + "/invitations/new")
|
||
11 years ago
|
} else {
|
||
8 years ago
|
c.Handle(500, " GetUserByName", err)
|
||
11 years ago
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
9 years ago
|
if err = org.AddMember(u.ID); err != nil {
|
||
8 years ago
|
c.Handle(500, " AddMember", err)
|
||
11 years ago
|
return
|
||
|
}
|
||
|
|
||
|
log.Trace("New member added(%s): %s", org.Name, u.Name)
|
||
8 years ago
|
c.Redirect(c.Org.OrgLink + "/members")
|
||
11 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
c.HTML(200, MEMBER_INVITE)
|
||
11 years ago
|
}
|