summaryrefslogtreecommitdiffstats
path: root/api4/channel.go
diff options
context:
space:
mode:
authorRobin Naundorf <r.naundorf@fh-muenster.de>2017-05-15 22:12:30 +0200
committerJoram Wilander <jwawilander@gmail.com>2017-05-15 16:12:30 -0400
commit0a20e8d3269515e2d44a0bcad0a2408f62245814 (patch)
tree533767c6a60939504f8f70c60bd4ff77ef0e8fe7 /api4/channel.go
parent34728f748bfd7976c085f1be77e53f70d6e55a06 (diff)
downloadchat-0a20e8d3269515e2d44a0bcad0a2408f62245814.tar.gz
chat-0a20e8d3269515e2d44a0bcad0a2408f62245814.tar.bz2
chat-0a20e8d3269515e2d44a0bcad0a2408f62245814.zip
PLT-6019: Add APIv4 Endpoint for restoring Channels (#6263)
Diffstat (limited to 'api4/channel.go')
-rw-r--r--api4/channel.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/api4/channel.go b/api4/channel.go
index e02b2677c..26892bf2f 100644
--- a/api4/channel.go
+++ b/api4/channel.go
@@ -29,6 +29,7 @@ func InitChannel() {
BaseRoutes.Channel.Handle("", ApiSessionRequired(getChannel)).Methods("GET")
BaseRoutes.Channel.Handle("", ApiSessionRequired(updateChannel)).Methods("PUT")
BaseRoutes.Channel.Handle("/patch", ApiSessionRequired(patchChannel)).Methods("PUT")
+ BaseRoutes.Channel.Handle("/restore", ApiSessionRequired(restoreChannel)).Methods("POST")
BaseRoutes.Channel.Handle("", ApiSessionRequired(deleteChannel)).Methods("DELETE")
BaseRoutes.Channel.Handle("/stats", ApiSessionRequired(getChannelStats)).Methods("GET")
BaseRoutes.Channel.Handle("/pinned", ApiSessionRequired(getPinnedPosts)).Methods("GET")
@@ -180,6 +181,36 @@ func patchChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
+func restoreChannel(c *Context, w http.ResponseWriter, r *http.Request) {
+ c.RequireChannelId()
+ if c.Err != nil {
+ return
+ }
+
+ var channel *model.Channel
+ var err *model.AppError
+ if channel, err = app.GetChannel(c.Params.ChannelId); err != nil {
+ c.Err = err
+ return
+ }
+ teamId := channel.TeamId
+
+ if !app.SessionHasPermissionToTeam(c.Session, teamId, model.PERMISSION_MANAGE_TEAM) {
+ c.SetPermissionError(model.PERMISSION_MANAGE_TEAM)
+ return
+ }
+
+ channel, err = app.RestoreChannel(channel)
+ if err != nil {
+ c.Err = err
+ return
+ }
+
+ c.LogAudit("name=" + channel.Name)
+ w.Write([]byte(channel.ToJson()))
+
+}
+
func CanManageChannel(c *Context, channel *model.Channel) bool {
if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES)