forked from Gitlink/gitea-1156
Finish Teams page
This commit is contained in:
parent
99713e1180
commit
e4ea5cf598
|
@ -13,11 +13,11 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
"github.com/satori/go.uuid"
|
|
||||||
|
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
"github.com/gogits/gogs/modules/log"
|
"github.com/gogits/gogs/modules/log"
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
|
"github.com/gogits/gogs/modules/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
var CmdServ = cli.Command{
|
var CmdServ = cli.Command{
|
||||||
|
|
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.4.5.0628 Alpha"
|
const APP_VER = "0.4.5.0629 Alpha"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
|
@ -10,6 +10,16 @@ import (
|
||||||
"github.com/gogits/gogs/modules/base"
|
"github.com/gogits/gogs/modules/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IsOrgOwner returns true if given user is in the owner team.
|
||||||
|
func (org *User) IsOrgOwner(uid int64) bool {
|
||||||
|
return IsOrganizationOwner(org.Id, uid)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsOrgMember returns true if given user is member of organization.
|
||||||
|
func (org *User) IsOrgMember(uid int64) bool {
|
||||||
|
return IsOrganizationMember(org.Id, uid)
|
||||||
|
}
|
||||||
|
|
||||||
// GetOwnerTeam returns owner team of organization.
|
// GetOwnerTeam returns owner team of organization.
|
||||||
func (org *User) GetOwnerTeam() (*Team, error) {
|
func (org *User) GetOwnerTeam() (*Team, error) {
|
||||||
t := &Team{
|
t := &Team{
|
||||||
|
@ -167,6 +177,18 @@ type Team struct {
|
||||||
RepoIds string `xorm:"TEXT"`
|
RepoIds string `xorm:"TEXT"`
|
||||||
NumMembers int
|
NumMembers int
|
||||||
NumRepos int
|
NumRepos int
|
||||||
|
Members []*User `xorm:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsTeamMember returns true if given user is a member of team.
|
||||||
|
func (t *Team) IsMember(uid int64) bool {
|
||||||
|
return IsTeamMember(t.OrgId, t.Id, uid)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMembers returns all members in given team of organization.
|
||||||
|
func (t *Team) GetMembers() (err error) {
|
||||||
|
t.Members, err = GetTeamMembers(t.OrgId, t.Id)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTeam creates a record of new team.
|
// NewTeam creates a record of new team.
|
||||||
|
@ -205,6 +227,18 @@ type OrgUser struct {
|
||||||
NumTeam int
|
NumTeam int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsOrganizationOwner returns true if given user is in the owner team.
|
||||||
|
func IsOrganizationOwner(orgId, uid int64) bool {
|
||||||
|
has, _ := x.Where("is_owner=?", true).And("uid=?", uid).And("org_id=?", orgId).Get(new(OrgUser))
|
||||||
|
return has
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsOrganizationMember returns true if given user is member of organization.
|
||||||
|
func IsOrganizationMember(orgId, uid int64) bool {
|
||||||
|
has, _ := x.Where("uid=?", uid).And("org_id=?", orgId).Get(new(OrgUser))
|
||||||
|
return has
|
||||||
|
}
|
||||||
|
|
||||||
// GetOrgUsersByUserId returns all organization-user relations by user ID.
|
// GetOrgUsersByUserId returns all organization-user relations by user ID.
|
||||||
func GetOrgUsersByUserId(uid int64) ([]*OrgUser, error) {
|
func GetOrgUsersByUserId(uid int64) ([]*OrgUser, error) {
|
||||||
ous := make([]*OrgUser, 0, 10)
|
ous := make([]*OrgUser, 0, 10)
|
||||||
|
@ -219,18 +253,6 @@ func GetOrgUsersByOrgId(orgId int64) ([]*OrgUser, error) {
|
||||||
return ous, err
|
return ous, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsOrganizationOwner returns true if given user is in the owner team.
|
|
||||||
func IsOrganizationOwner(orgId, uid int64) bool {
|
|
||||||
has, _ := x.Where("is_owner=?", true).Get(&OrgUser{Uid: uid, OrgId: orgId})
|
|
||||||
return has
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsOrganizationMember returns true if given user is member of organization.
|
|
||||||
func IsOrganizationMember(orgId, uid int64) bool {
|
|
||||||
has, _ := x.Get(&OrgUser{Uid: uid, OrgId: orgId})
|
|
||||||
return has
|
|
||||||
}
|
|
||||||
|
|
||||||
// ___________ ____ ___
|
// ___________ ____ ___
|
||||||
// \__ ___/___ _____ _____ | | \______ ___________
|
// \__ ___/___ _____ _____ | | \______ ___________
|
||||||
// | |_/ __ \\__ \ / \| | / ___// __ \_ __ \
|
// | |_/ __ \\__ \ / \| | / ___// __ \_ __ \
|
||||||
|
@ -246,6 +268,12 @@ type TeamUser struct {
|
||||||
TeamId int64
|
TeamId int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsTeamMember returns true if given user is a member of team.
|
||||||
|
func IsTeamMember(orgId, teamId, uid int64) bool {
|
||||||
|
has, _ := x.Where("uid=?", uid).And("org_id=?", orgId).And("team_id=?", teamId).Get(new(TeamUser))
|
||||||
|
return has
|
||||||
|
}
|
||||||
|
|
||||||
// GetTeamMembers returns all members in given team of organization.
|
// GetTeamMembers returns all members in given team of organization.
|
||||||
func GetTeamMembers(orgId, teamId int64) ([]*User, error) {
|
func GetTeamMembers(orgId, teamId int64) ([]*User, error) {
|
||||||
tus := make([]*TeamUser, 0, 10)
|
tus := make([]*TeamUser, 0, 10)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,16 @@
|
||||||
|
// 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/go-martini/martini"
|
||||||
|
|
||||||
|
"github.com/gogits/gogs/modules/middleware"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Members(ctx *middleware.Context, params martini.Params) {
|
||||||
|
ctx.Data["Title"] = "Organization " + params["org"] + " Members"
|
||||||
|
ctx.HTML(200, "org/members")
|
||||||
|
}
|
|
@ -36,7 +36,7 @@ func Home(ctx *middleware.Context, params martini.Params) {
|
||||||
ctx.Data["Org"] = org
|
ctx.Data["Org"] = org
|
||||||
|
|
||||||
ctx.Data["Repos"], err = models.GetRepositories(org.Id,
|
ctx.Data["Repos"], err = models.GetRepositories(org.Id,
|
||||||
ctx.IsSigned && models.IsOrganizationMember(org.Id, ctx.User.Id))
|
ctx.IsSigned && org.IsOrgMember(ctx.User.Id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "org.Home(GetRepositories)", err)
|
ctx.Handle(500, "org.Home(GetRepositories)", err)
|
||||||
return
|
return
|
||||||
|
@ -57,11 +57,6 @@ func Home(ctx *middleware.Context, params martini.Params) {
|
||||||
ctx.HTML(200, HOME)
|
ctx.HTML(200, HOME)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Members(ctx *middleware.Context, params martini.Params) {
|
|
||||||
ctx.Data["Title"] = "Organization " + params["org"] + " Members"
|
|
||||||
ctx.HTML(200, "org/members")
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(ctx *middleware.Context) {
|
func New(ctx *middleware.Context) {
|
||||||
ctx.Data["Title"] = "Create An Organization"
|
ctx.Data["Title"] = "Create An Organization"
|
||||||
ctx.HTML(200, NEW)
|
ctx.HTML(200, NEW)
|
||||||
|
@ -206,7 +201,7 @@ func DeletePost(ctx *middleware.Context, params martini.Params) {
|
||||||
}
|
}
|
||||||
ctx.Data["Org"] = org
|
ctx.Data["Org"] = org
|
||||||
|
|
||||||
if !models.IsOrganizationOwner(org.Id, ctx.User.Id) {
|
if !org.IsOrgOwner(ctx.User.Id) {
|
||||||
ctx.Error(403)
|
ctx.Error(403)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,48 @@
|
||||||
|
// 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
|
package org
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-martini/martini"
|
"github.com/go-martini/martini"
|
||||||
|
|
||||||
|
"github.com/gogits/gogs/models"
|
||||||
|
"github.com/gogits/gogs/modules/base"
|
||||||
"github.com/gogits/gogs/modules/middleware"
|
"github.com/gogits/gogs/modules/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
TEAMS base.TplName = "org/teams"
|
||||||
|
)
|
||||||
|
|
||||||
func Teams(ctx *middleware.Context, params martini.Params) {
|
func Teams(ctx *middleware.Context, params martini.Params) {
|
||||||
ctx.Data["Title"] = "Organization " + params["org"] + " Teams"
|
ctx.Data["Title"] = "Organization " + params["org"] + " Teams"
|
||||||
ctx.HTML(200, "org/teams")
|
|
||||||
|
org, err := models.GetUserByName(params["org"])
|
||||||
|
if err != nil {
|
||||||
|
if err == models.ErrUserNotExist {
|
||||||
|
ctx.Handle(404, "org.Teams(GetUserByName)", err)
|
||||||
|
} else {
|
||||||
|
ctx.Handle(500, "org.Teams(GetUserByName)", err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.Data["Org"] = org
|
||||||
|
|
||||||
|
if err = org.GetTeams(); err != nil {
|
||||||
|
ctx.Handle(500, "org.Teams(GetTeams)", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, t := range org.Teams {
|
||||||
|
if err = t.GetMembers(); err != nil {
|
||||||
|
ctx.Handle(500, "org.Home(GetMembers)", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx.Data["Teams"] = org.Teams
|
||||||
|
|
||||||
|
ctx.HTML(200, TEAMS)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTeam(ctx *middleware.Context, params martini.Params) {
|
func NewTeam(ctx *middleware.Context, params martini.Params) {
|
||||||
|
|
|
@ -90,7 +90,7 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check ownership of organization.
|
// Check ownership of organization.
|
||||||
if !models.IsOrganizationOwner(u.Id, ctx.User.Id) {
|
if !u.IsOrgOwner(ctx.User.Id) {
|
||||||
ctx.Error(403)
|
ctx.Error(403)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ func SettingPost(ctx *middleware.Context, form auth.RepoSettingForm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Repo.Owner.IsOrganization() &&
|
if ctx.Repo.Owner.IsOrganization() &&
|
||||||
!models.IsOrganizationOwner(ctx.Repo.Owner.Id, ctx.User.Id) {
|
!ctx.Repo.Owner.IsOrgOwner(ctx.User.Id) {
|
||||||
ctx.Error(403)
|
ctx.Error(403)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.4.5.0628 Alpha
|
0.4.5.0629 Alpha
|
|
@ -4,16 +4,16 @@
|
||||||
<div class="container clearfix">
|
<div class="container clearfix">
|
||||||
<div id="org-nav-wrapper">
|
<div id="org-nav-wrapper">
|
||||||
<ul class="nav nav-pills pull-right">
|
<ul class="nav nav-pills pull-right">
|
||||||
<li><a href="#"><i class="fa fa-users"></i>Members
|
<li><a href="/org/{{.Org.Name}}/members"><i class="fa fa-users"></i>Members
|
||||||
<span class="label label-default">5</span></a>
|
<span class="label label-default">{{.Org.NumMembers}}</span></a>
|
||||||
</li>
|
</li>
|
||||||
<li class="active"><a href="#"><i class="fa fa-tags"></i>Teams
|
<li class="active"><a href="/org/{{.Org.Name}}/teams"><i class="fa fa-tags"></i>Teams
|
||||||
<span class="label label-default">2</span></a>
|
<span class="label label-default">{{.Org.NumTeams}}</span></a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<img class="pull-left org-small-logo" src="https://avatars3.githubusercontent.com/u/6656686?s=140" alt="" width="60"/>
|
<img class="pull-left org-small-logo" src="{{.Org.AvatarLink}}?s=140" alt="" width="60"/>
|
||||||
<div id="org-nav-info">
|
<div id="org-nav-info">
|
||||||
<h2 class="org-name">Organization Name</h2>
|
<h2 class="org-name">{{.Org.FullName}}</h2>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -23,48 +23,34 @@
|
||||||
<div id="org-teams">
|
<div id="org-teams">
|
||||||
<div id="org-teams-action">
|
<div id="org-teams-action">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<a href="#"><button class="btn btn-success"><i class="fa fa-plus-square"></i>New Team</button></a>
|
<a href="/org/{{.Org.Name}}/teams/new"><button class="btn btn-success"><i class="fa fa-plus-square"></i>New Team</button></a>
|
||||||
<hr/>
|
<hr/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{range .Teams}}
|
||||||
<div class="org-team col-md-6">
|
<div class="org-team col-md-6">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<h2 class="panel-heading org-team-name"><a href="#"><strong>Team Name</strong></a></h2>
|
<h2 class="panel-heading org-team-name"><a href="/org/{{$.Org.Name}}/teams/{{.LowerName}}"><strong>{{.Name}}</strong></a></h2>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<p class="org-team-meta">4 members · 10 repositories</p>
|
<p class="org-team-meta">{{.NumMembers}} members · {{.NumRepos}} repositories</p>
|
||||||
<p class="org-team-members">
|
<p class="org-team-members">
|
||||||
<a href="#">
|
{{range .Members}}
|
||||||
<img class="img-thumbnail" src="https://avatars2.githubusercontent.com/u/2946214?s=60" alt=""/>
|
<a href="/user/{{.LowerName}}">
|
||||||
</a>
|
<img class="img-thumbnail" src="{{.AvatarLink}}?s=60" alt=""/>
|
||||||
<a href="#">
|
|
||||||
<img class="img-thumbnail" src="https://avatars2.githubusercontent.com/u/2946214?s=60" alt=""/>
|
|
||||||
</a>
|
</a>
|
||||||
|
{{end}}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-footer">
|
<div class="panel-footer">
|
||||||
<button class="pull-right btn btn-default">Join</button>
|
{{if .IsMember $.SignedUserId}}
|
||||||
</div>
|
<a class="pull-right btn btn-danger" href="/org/{{$.Org.Name}}/teams/{{.LowerName}}?action=leave">Leave</a>
|
||||||
</div>
|
{{else}}
|
||||||
</div>
|
<a class="pull-right btn btn-default" href="/org/{{$.Org.Name}}/teams/{{.LowerName}}?action=join">Join</a>
|
||||||
<div class="org-team col-md-6">
|
{{end}}
|
||||||
<div class="panel panel-default">
|
|
||||||
<h2 class="panel-heading org-team-name"><a href="#"><strong>Team Name</strong></a></h2>
|
|
||||||
<div class="panel-body">
|
|
||||||
<p class="org-team-meta">4 members · 10 repositories</p>
|
|
||||||
<p class="org-team-members">
|
|
||||||
<a href="#">
|
|
||||||
<img class="img-thumbnail" src="https://avatars2.githubusercontent.com/u/2946214?s=60" alt=""/>
|
|
||||||
</a>
|
|
||||||
<a href="#">
|
|
||||||
<img class="img-thumbnail" src="https://avatars2.githubusercontent.com/u/2946214?s=60" alt=""/>
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="panel-footer">
|
|
||||||
<button class="pull-right btn btn-danger">Leave</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue