mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-22 13:25:36 +03:00
Finish Teams page
This commit is contained in:
parent
99713e1180
commit
e4ea5cf598
11 changed files with 247 additions and 518 deletions
|
@ -13,11 +13,11 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/satori/go.uuid"
|
||||
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
"github.com/gogits/gogs/modules/uuid"
|
||||
)
|
||||
|
||||
var CmdServ = cli.Command{
|
||||
|
|
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
|||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
const APP_VER = "0.4.5.0628 Alpha"
|
||||
const APP_VER = "0.4.5.0629 Alpha"
|
||||
|
||||
func init() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
|
|
@ -10,6 +10,16 @@ import (
|
|||
"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.
|
||||
func (org *User) GetOwnerTeam() (*Team, error) {
|
||||
t := &Team{
|
||||
|
@ -167,6 +177,18 @@ type Team struct {
|
|||
RepoIds string `xorm:"TEXT"`
|
||||
NumMembers 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.
|
||||
|
@ -205,6 +227,18 @@ type OrgUser struct {
|
|||
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.
|
||||
func GetOrgUsersByUserId(uid int64) ([]*OrgUser, error) {
|
||||
ous := make([]*OrgUser, 0, 10)
|
||||
|
@ -219,18 +253,6 @@ func GetOrgUsersByOrgId(orgId int64) ([]*OrgUser, error) {
|
|||
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
|
||||
}
|
||||
|
||||
// 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.
|
||||
func GetTeamMembers(orgId, teamId int64) ([]*User, error) {
|
||||
tus := make([]*TeamUser, 0, 10)
|
||||
|
|
File diff suppressed because it is too large
Load diff
16
routers/org/members.go
Normal file
16
routers/org/members.go
Normal file
|
@ -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["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 {
|
||||
ctx.Handle(500, "org.Home(GetRepositories)", err)
|
||||
return
|
||||
|
@ -57,11 +57,6 @@ func Home(ctx *middleware.Context, params martini.Params) {
|
|||
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) {
|
||||
ctx.Data["Title"] = "Create An Organization"
|
||||
ctx.HTML(200, NEW)
|
||||
|
@ -206,7 +201,7 @@ func DeletePost(ctx *middleware.Context, params martini.Params) {
|
|||
}
|
||||
ctx.Data["Org"] = org
|
||||
|
||||
if !models.IsOrganizationOwner(org.Id, ctx.User.Id) {
|
||||
if !org.IsOrgOwner(ctx.User.Id) {
|
||||
ctx.Error(403)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,21 +1,56 @@
|
|||
// 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/models"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
)
|
||||
|
||||
const (
|
||||
TEAMS base.TplName = "org/teams"
|
||||
)
|
||||
|
||||
func Teams(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.Data["Title"] = "Organization "+params["org"]+" Teams"
|
||||
ctx.HTML(200, "org/teams")
|
||||
ctx.Data["Title"] = "Organization " + params["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) {
|
||||
ctx.Data["Title"] = "Organization "+params["org"]+" New Team"
|
||||
ctx.Data["Title"] = "Organization " + params["org"] + " New Team"
|
||||
ctx.HTML(200, "org/new_team")
|
||||
}
|
||||
|
||||
func EditTeam(ctx *middleware.Context, params martini.Params){
|
||||
ctx.Data["Title"] = "Organization "+params["org"]+" Edit Team"
|
||||
ctx.HTML(200,"org/edit_team")
|
||||
func EditTeam(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.Data["Title"] = "Organization " + params["org"] + " Edit Team"
|
||||
ctx.HTML(200, "org/edit_team")
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) {
|
|||
}
|
||||
|
||||
// Check ownership of organization.
|
||||
if !models.IsOrganizationOwner(u.Id, ctx.User.Id) {
|
||||
if !u.IsOrgOwner(ctx.User.Id) {
|
||||
ctx.Error(403)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ func SettingPost(ctx *middleware.Context, form auth.RepoSettingForm) {
|
|||
}
|
||||
|
||||
if ctx.Repo.Owner.IsOrganization() &&
|
||||
!models.IsOrganizationOwner(ctx.Repo.Owner.Id, ctx.User.Id) {
|
||||
!ctx.Repo.Owner.IsOrgOwner(ctx.User.Id) {
|
||||
ctx.Error(403)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
0.4.5.0628 Alpha
|
||||
0.4.5.0629 Alpha
|
|
@ -4,16 +4,16 @@
|
|||
<div class="container clearfix">
|
||||
<div id="org-nav-wrapper">
|
||||
<ul class="nav nav-pills pull-right">
|
||||
<li><a href="#"><i class="fa fa-users"></i>Members
|
||||
<span class="label label-default">5</span></a>
|
||||
<li><a href="/org/{{.Org.Name}}/members"><i class="fa fa-users"></i>Members
|
||||
<span class="label label-default">{{.Org.NumMembers}}</span></a>
|
||||
</li>
|
||||
<li class="active"><a href="#"><i class="fa fa-tags"></i>Teams
|
||||
<span class="label label-default">2</span></a>
|
||||
<li class="active"><a href="/org/{{.Org.Name}}/teams"><i class="fa fa-tags"></i>Teams
|
||||
<span class="label label-default">{{.Org.NumTeams}}</span></a>
|
||||
</li>
|
||||
</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">
|
||||
<h2 class="org-name">Organization Name</h2>
|
||||
<h2 class="org-name">{{.Org.FullName}}</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -23,48 +23,34 @@
|
|||
<div id="org-teams">
|
||||
<div id="org-teams-action">
|
||||
<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/>
|
||||
</div>
|
||||
</div>
|
||||
{{range .Teams}}
|
||||
<div class="org-team col-md-6">
|
||||
<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">
|
||||
<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">
|
||||
<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=""/>
|
||||
{{range .Members}}
|
||||
<a href="/user/{{.LowerName}}">
|
||||
<img class="img-thumbnail" src="{{.AvatarLink}}?s=60" alt=""/>
|
||||
</a>
|
||||
{{end}}
|
||||
</p>
|
||||
</div>
|
||||
<div class="panel-footer">
|
||||
<button class="pull-right btn btn-default">Join</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="org-team col-md-6">
|
||||
<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>
|
||||
{{if .IsMember $.SignedUserId}}
|
||||
<a class="pull-right btn btn-danger" href="/org/{{$.Org.Name}}/teams/{{.LowerName}}?action=leave">Leave</a>
|
||||
{{else}}
|
||||
<a class="pull-right btn btn-default" href="/org/{{$.Org.Name}}/teams/{{.LowerName}}?action=join">Join</a>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue