summaryrefslogtreecommitdiffstats
path: root/api/team.go
diff options
context:
space:
mode:
authorCarlos Tadeu Panato Junior <ctadeu@gmail.com>2016-12-08 16:21:43 +0100
committerHarrison Healey <harrisonmhealey@gmail.com>2016-12-08 10:21:43 -0500
commitd402b1d010a56256f15bb482684c18b10ed4bcc5 (patch)
tree0f94813e07ced23c05b22dd302048698e88a7466 /api/team.go
parentb57c9fec89f736de8622218d6dc779012a266a91 (diff)
downloadchat-d402b1d010a56256f15bb482684c18b10ed4bcc5.tar.gz
chat-d402b1d010a56256f15bb482684c18b10ed4bcc5.tar.bz2
chat-d402b1d010a56256f15bb482684c18b10ed4bcc5.zip
Add API call to get a team by its name (#4690)
* Add API call to get a team by its name * add tests for client side and update route regex * remove action * add check for permissions and create tests
Diffstat (limited to 'api/team.go')
-rw-r--r--api/team.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/api/team.go b/api/team.go
index 3fc367ac0..1d4de6b9e 100644
--- a/api/team.go
+++ b/api/team.go
@@ -31,6 +31,7 @@ func InitTeam() {
BaseRoutes.Teams.Handle("/all_team_listings", ApiUserRequired(GetAllTeamListings)).Methods("GET")
BaseRoutes.Teams.Handle("/get_invite_info", ApiAppHandler(getInviteInfo)).Methods("POST")
BaseRoutes.Teams.Handle("/find_team_by_name", ApiAppHandler(findTeamByName)).Methods("POST")
+ BaseRoutes.Teams.Handle("/name/{team_name:[A-Za-z0-9\\-]+}", ApiAppHandler(getTeamByName)).Methods("GET")
BaseRoutes.NeedTeam.Handle("/me", ApiUserRequired(getMyTeam)).Methods("GET")
BaseRoutes.NeedTeam.Handle("/stats", ApiUserRequired(getTeamStats)).Methods("GET")
@@ -701,6 +702,27 @@ func findTeamByName(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
+func getTeamByName(c *Context, w http.ResponseWriter, r *http.Request) {
+ params := mux.Vars(r)
+ teamname := params["team_name"]
+
+ if result := <-Srv.Store.Team().GetByName(teamname); result.Err != nil {
+ c.Err = result.Err
+ return
+ } else {
+ team := result.Data.(*model.Team)
+
+ if team.Type != model.TEAM_OPEN && c.Session.GetTeamByTeamId(team.Id) == nil {
+ if !HasPermissionToContext(c, model.PERMISSION_MANAGE_SYSTEM) {
+ return
+ }
+ }
+
+ w.Write([]byte(team.ToJson()))
+ return
+ }
+}
+
func InviteMembers(team *model.Team, senderName string, invites []string) {
for _, invite := range invites {
if len(invite) > 0 {