PLT-6019: Add APIv4 Endpoint for restoring Channels (#6263)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
34728f748b
Коммит
0a20e8d326
@@ -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)
|
||||
|
||||
@@ -1067,6 +1067,32 @@ func TestDeleteChannel(t *testing.T) {
|
||||
CheckNoError(t, resp)
|
||||
}
|
||||
|
||||
func TestRestoreChannel(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer TearDown()
|
||||
Client := th.Client
|
||||
|
||||
publicChannel1 := th.CreatePublicChannel()
|
||||
Client.DeleteChannel(publicChannel1.Id)
|
||||
|
||||
privateChannel1 := th.CreatePrivateChannel()
|
||||
Client.DeleteChannel(privateChannel1.Id)
|
||||
|
||||
_, resp := Client.RestoreChannel(publicChannel1.Id)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, resp = Client.RestoreChannel(privateChannel1.Id)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
th.LoginTeamAdmin()
|
||||
|
||||
_, resp = Client.RestoreChannel(publicChannel1.Id)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
_, resp = Client.RestoreChannel(privateChannel1.Id)
|
||||
CheckOKStatus(t, resp)
|
||||
}
|
||||
|
||||
func TestGetChannelByName(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user