summaryrefslogtreecommitdiffstats
path: root/api/team.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-08-26 12:49:07 -0400
committerChristopher Speller <crspeller@gmail.com>2015-09-04 11:11:38 -0400
commitf0fd9a9e8b85544089246bde71b6d61ba90eeb0e (patch)
tree256896117078ef1396a52fcecf3116863b3bb716 /api/team.go
parent1b923528448eace438a1f498116a19361a8b0fb2 (diff)
downloadchat-f0fd9a9e8b85544089246bde71b6d61ba90eeb0e.tar.gz
chat-f0fd9a9e8b85544089246bde71b6d61ba90eeb0e.tar.bz2
chat-f0fd9a9e8b85544089246bde71b6d61ba90eeb0e.zip
Adding ability to export data from mattermost
Diffstat (limited to 'api/team.go')
-rw-r--r--api/team.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/api/team.go b/api/team.go
index 8cce384c3..e1b3b274a 100644
--- a/api/team.go
+++ b/api/team.go
@@ -32,7 +32,9 @@ func InitTeam(r *mux.Router) {
sr.Handle("/update_name", ApiUserRequired(updateTeamDisplayName)).Methods("POST")
sr.Handle("/update_valet_feature", ApiUserRequired(updateValetFeature)).Methods("POST")
sr.Handle("/me", ApiUserRequired(getMyTeam)).Methods("GET")
+ // These should be moved to the global admain console
sr.Handle("/import_team", ApiUserRequired(importTeam)).Methods("POST")
+ sr.Handle("/export_team", ApiUserRequired(exportTeam)).Methods("GET")
}
func signupTeam(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -675,3 +677,22 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/octet-stream")
http.ServeContent(w, r, "MattermostImportLog.txt", time.Now(), bytes.NewReader(log.Bytes()))
}
+
+func exportTeam(c *Context, w http.ResponseWriter, r *http.Request) {
+ if !c.HasPermissionsToTeam(c.Session.TeamId, "export") || !c.IsTeamAdmin(c.Session.UserId) {
+ c.Err = model.NewAppError("exportTeam", "Only a team admin can export data.", "userId="+c.Session.UserId)
+ c.Err.StatusCode = http.StatusForbidden
+ return
+ }
+
+ options := ExportOptionsFromJson(r.Body)
+
+ if link, err := ExportToFile(options); err != nil {
+ c.Err = err
+ return
+ } else {
+ result := map[string]string{}
+ result["link"] = link
+ w.Write([]byte(model.MapToJson(result)))
+ }
+}