|
|
|
@ -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 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|