|
|
@@ -13,12 +13,20 @@ import (
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
- TEAMS = "org/team/teams"
|
|
|
- TEAM_NEW = "org/team/new"
|
|
|
- TEAM_MEMBERS = "org/team/members"
|
|
|
+ // TEAMS page template
|
|
|
+ TEAMS = "org/team/teams"
|
|
|
+
|
|
|
+ // TEAM_NEW page template
|
|
|
+ TEAM_NEW = "org/team/new"
|
|
|
+
|
|
|
+ // TEAM_MEMBERS page template
|
|
|
+ TEAM_MEMBERS = "org/team/members"
|
|
|
+
|
|
|
+ // TEAM_REPOSITORIES page template
|
|
|
TEAM_REPOSITORIES = "org/team/repositories"
|
|
|
)
|
|
|
|
|
|
+// Teams shows team page
|
|
|
func Teams(c *context.Context) {
|
|
|
org := c.Org.Organization
|
|
|
c.Data["Title"] = org.FullName
|
|
|
@@ -35,6 +43,8 @@ func Teams(c *context.Context) {
|
|
|
c.HTML(200, TEAMS)
|
|
|
}
|
|
|
|
|
|
+// TeamsAction handle the user action
|
|
|
+// Like : join, leave, add or remove a team
|
|
|
func TeamsAction(c *context.Context) {
|
|
|
uid := com.StrTo(c.Query("uid")).MustInt64()
|
|
|
if uid == 0 {
|
|
|
@@ -45,14 +55,17 @@ func TeamsAction(c *context.Context) {
|
|
|
page := c.Query("page")
|
|
|
var err error
|
|
|
switch c.Params(":action") {
|
|
|
+ // Join a team
|
|
|
case "join":
|
|
|
if !c.Org.IsOwner {
|
|
|
c.Error(404)
|
|
|
return
|
|
|
}
|
|
|
err = c.Org.Team.AddMember(c.User.ID)
|
|
|
+ // Leave a team
|
|
|
case "leave":
|
|
|
err = c.Org.Team.RemoveMember(c.User.ID)
|
|
|
+ // Remove a team
|
|
|
case "remove":
|
|
|
if !c.Org.IsOwner {
|
|
|
c.Error(404)
|
|
|
@@ -60,6 +73,7 @@ func TeamsAction(c *context.Context) {
|
|
|
}
|
|
|
err = c.Org.Team.RemoveMember(uid)
|
|
|
page = "team"
|
|
|
+ // Add a team
|
|
|
case "add":
|
|
|
if !c.Org.IsOwner {
|
|
|
c.Error(404)
|
|
|
@@ -104,6 +118,8 @@ func TeamsAction(c *context.Context) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// TeamsRepoAction handle user actions
|
|
|
+// Like: add, remove a repository
|
|
|
func TeamsRepoAction(c *context.Context) {
|
|
|
if !c.Org.IsOwner {
|
|
|
c.Error(404)
|
|
|
@@ -139,6 +155,7 @@ func TeamsRepoAction(c *context.Context) {
|
|
|
c.Redirect(c.Org.OrgLink + "/teams/" + c.Org.Team.LowerName + "/repositories")
|
|
|
}
|
|
|
|
|
|
+// NewTeam shows the team creation page
|
|
|
func NewTeam(c *context.Context) {
|
|
|
c.Data["Title"] = c.Org.Organization.FullName
|
|
|
c.Data["PageIsOrgTeams"] = true
|
|
|
@@ -147,6 +164,7 @@ func NewTeam(c *context.Context) {
|
|
|
c.HTML(200, TEAM_NEW)
|
|
|
}
|
|
|
|
|
|
+// NewTeamPost creates an organization with the body fields
|
|
|
func NewTeamPost(c *context.Context, f form.CreateTeam) {
|
|
|
c.Data["Title"] = c.Org.Organization.FullName
|
|
|
c.Data["PageIsOrgTeams"] = true
|
|
|
@@ -165,6 +183,7 @@ func NewTeamPost(c *context.Context, f form.CreateTeam) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ // Create a new team
|
|
|
if err := models.NewTeam(t); err != nil {
|
|
|
c.Data["Err_TeamName"] = true
|
|
|
switch {
|
|
|
@@ -181,6 +200,7 @@ func NewTeamPost(c *context.Context, f form.CreateTeam) {
|
|
|
c.Redirect(c.Org.OrgLink + "/teams/" + t.LowerName)
|
|
|
}
|
|
|
|
|
|
+// TeamMembers shows team members page
|
|
|
func TeamMembers(c *context.Context) {
|
|
|
c.Data["Title"] = c.Org.Team.Name
|
|
|
c.Data["PageIsOrgTeams"] = true
|
|
|
@@ -191,6 +211,7 @@ func TeamMembers(c *context.Context) {
|
|
|
c.HTML(200, TEAM_MEMBERS)
|
|
|
}
|
|
|
|
|
|
+// TeamRepositories shows team repositoies page
|
|
|
func TeamRepositories(c *context.Context) {
|
|
|
c.Data["Title"] = c.Org.Team.Name
|
|
|
c.Data["PageIsOrgTeams"] = true
|
|
|
@@ -201,6 +222,7 @@ func TeamRepositories(c *context.Context) {
|
|
|
c.HTML(200, TEAM_REPOSITORIES)
|
|
|
}
|
|
|
|
|
|
+// EditTeam shows edit team page
|
|
|
func EditTeam(c *context.Context) {
|
|
|
c.Data["Title"] = c.Org.Organization.FullName
|
|
|
c.Data["PageIsOrgTeams"] = true
|
|
|
@@ -209,6 +231,7 @@ func EditTeam(c *context.Context) {
|
|
|
c.HTML(200, TEAM_NEW)
|
|
|
}
|
|
|
|
|
|
+// EditTeamPost edit team with the body fields
|
|
|
func EditTeamPost(c *context.Context, f form.CreateTeam) {
|
|
|
t := c.Org.Team
|
|
|
c.Data["Title"] = c.Org.Organization.FullName
|
|
|
@@ -243,6 +266,7 @@ func EditTeamPost(c *context.Context, f form.CreateTeam) {
|
|
|
}
|
|
|
}
|
|
|
t.Description = f.Description
|
|
|
+ // Edit team
|
|
|
if err := models.UpdateTeam(t, isAuthChanged); err != nil {
|
|
|
c.Data["Err_TeamName"] = true
|
|
|
switch {
|
|
|
@@ -256,7 +280,9 @@ func EditTeamPost(c *context.Context, f form.CreateTeam) {
|
|
|
c.Redirect(c.Org.OrgLink + "/teams/" + t.LowerName)
|
|
|
}
|
|
|
|
|
|
+// DeleteTeam deletes a team
|
|
|
func DeleteTeam(c *context.Context) {
|
|
|
+ // Delete team
|
|
|
if err := models.DeleteTeam(c.Org.Team); err != nil {
|
|
|
c.Flash.Error("DeleteTeam: " + err.Error())
|
|
|
} else {
|