summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-02-04 12:52:11 -0500
committerUnknwon <u@gogs.io>2016-02-04 12:52:11 -0500
commit739d5aa1d32229769acbdf53bd99222d13441b47 (patch)
tree7ca9e508ade455e660ff29a0995b26cefd8b8816 /modules
parent04be8c0de5295f57e06e152e56c481b29b1076e5 (diff)
parentc3ff476ed67b69431e96fce8e5a16450976701f6 (diff)
downloadgitea-739d5aa1d32229769acbdf53bd99222d13441b47.tar.gz
gitea-739d5aa1d32229769acbdf53bd99222d13441b47.zip
Merge pull request #2530 from fnkr/hide-other-teams-repos-from-org-page
Hide other teams & repos from organization page
Diffstat (limited to 'modules')
-rw-r--r--modules/middleware/context.go3
-rw-r--r--modules/middleware/org.go73
2 files changed, 56 insertions, 20 deletions
diff --git a/modules/middleware/context.go b/modules/middleware/context.go
index d58967b891..cd11c08b15 100644
--- a/modules/middleware/context.go
+++ b/modules/middleware/context.go
@@ -65,7 +65,8 @@ type Context struct {
Org struct {
IsOwner bool
IsMember bool
- IsAdminTeam bool // In owner team or team that has admin permission level.
+ IsTeamMember bool // Is member of team.
+ IsTeamAdmin bool // In owner team or team that has admin permission level.
Organization *models.User
OrgLink string
diff --git a/modules/middleware/org.go b/modules/middleware/org.go
index 37ba4deb1f..eb71020e69 100644
--- a/modules/middleware/org.go
+++ b/modules/middleware/org.go
@@ -5,6 +5,8 @@
package middleware
import (
+ "strings"
+
"gopkg.in/macaron.v1"
"github.com/gogits/gogs/models"
@@ -13,9 +15,10 @@ import (
func HandleOrgAssignment(ctx *Context, args ...bool) {
var (
- requireMember bool
- requireOwner bool
- requireAdminTeam bool
+ requireMember bool
+ requireOwner bool
+ requireTeamMember bool
+ requireTeamAdmin bool
)
if len(args) >= 1 {
requireMember = args[0]
@@ -24,7 +27,10 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
requireOwner = args[1]
}
if len(args) >= 3 {
- requireAdminTeam = args[2]
+ requireTeamMember = args[2]
+ }
+ if len(args) >= 4 {
+ requireTeamAdmin = args[3]
}
orgName := ctx.Params(":org")
@@ -52,12 +58,14 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
if ctx.IsSigned && ctx.User.IsAdmin {
ctx.Org.IsOwner = true
ctx.Org.IsMember = true
- ctx.Org.IsAdminTeam = true
+ ctx.Org.IsTeamMember = true
+ ctx.Org.IsTeamAdmin = true
} else if ctx.IsSigned {
ctx.Org.IsOwner = org.IsOwnedBy(ctx.User.Id)
if ctx.Org.IsOwner {
ctx.Org.IsMember = true
- ctx.Org.IsAdminTeam = true
+ ctx.Org.IsTeamMember = true
+ ctx.Org.IsTeamAdmin = true
} else {
if org.IsOrgMember(ctx.User.Id) {
ctx.Org.IsMember = true
@@ -79,24 +87,51 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
ctx.Data["OrgLink"] = ctx.Org.OrgLink
// Team.
+ if ctx.Org.IsMember {
+ if ctx.Org.IsOwner {
+ if err := org.GetTeams(); err != nil {
+ ctx.Handle(500, "GetUserTeams", err)
+ return
+ }
+ } else {
+ if err := org.GetUserTeams(ctx.User.Id); err != nil {
+ ctx.Handle(500, "GetUserTeams", err)
+ return
+ }
+ }
+ }
+
teamName := ctx.Params(":team")
if len(teamName) > 0 {
- ctx.Org.Team, err = org.GetTeam(teamName)
- if err != nil {
- if err == models.ErrTeamNotExist {
- ctx.Handle(404, "GetTeam", err)
- } else {
- ctx.Handle(500, "GetTeam", err)
+ teamExists := false
+ for _, team := range org.Teams {
+
+ if strings.ToLower(team.Name) == strings.ToLower(teamName) {
+ teamExists = true
+ ctx.Org.Team = team
+ ctx.Org.IsTeamMember = true
+ ctx.Data["Team"] = ctx.Org.Team
+ break
}
+ }
+
+ if !teamExists {
+ ctx.Handle(404, "OrgAssignment", err)
+ return
+ }
+
+ ctx.Data["IsTeamMember"] = ctx.Org.IsTeamMember
+ if requireTeamMember && !ctx.Org.IsTeamMember {
+ ctx.Handle(404, "OrgAssignment", err)
+ return
+ }
+
+ ctx.Org.IsTeamAdmin = ctx.Org.Team.IsOwnerTeam() || ctx.Org.Team.Authorize >= models.ACCESS_MODE_ADMIN
+ ctx.Data["IsTeamAdmin"] = ctx.Org.IsTeamAdmin
+ if requireTeamAdmin && !ctx.Org.IsTeamAdmin {
+ ctx.Handle(404, "OrgAssignment", err)
return
}
- ctx.Data["Team"] = ctx.Org.Team
- ctx.Org.IsAdminTeam = ctx.Org.Team.IsOwnerTeam() || ctx.Org.Team.Authorize >= models.ACCESS_MODE_ADMIN
- }
- ctx.Data["IsAdminTeam"] = ctx.Org.IsAdminTeam
- if requireAdminTeam && !ctx.Org.IsAdminTeam {
- ctx.Handle(404, "OrgAssignment", err)
- return
}
}