Skip to content

Commit

Permalink
Merge d37fcb2 into ad0ed00
Browse files Browse the repository at this point in the history
  • Loading branch information
cpanato committed Mar 14, 2017
2 parents ad0ed00 + d37fcb2 commit 50a0e50
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
17 changes: 17 additions & 0 deletions api4/system.go
Expand Up @@ -20,6 +20,7 @@ func InitSystem() {
BaseRoutes.ApiRoot.Handle("/config/reload", ApiSessionRequired(configReload)).Methods("POST")
BaseRoutes.ApiRoot.Handle("/email/test", ApiSessionRequired(testEmail)).Methods("POST")
BaseRoutes.ApiRoot.Handle("/database/recycle", ApiSessionRequired(databaseRecycle)).Methods("POST")
BaseRoutes.ApiRoot.Handle("/caches/invalidate", ApiSessionRequired(invalidateCaches)).Methods("POST")
}

func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -77,3 +78,19 @@ func databaseRecycle(c *Context, w http.ResponseWriter, r *http.Request) {

ReturnStatusOK(w)
}

func invalidateCaches(c *Context, w http.ResponseWriter, r *http.Request) {
if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
return
}

err := app.InvalidateAllCaches()
if err != nil {
c.Err = err
return
}

w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
ReturnStatusOK(w)
}
17 changes: 17 additions & 0 deletions api4/system_test.go
Expand Up @@ -126,5 +126,22 @@ func TestDatabaseRecycle(t *testing.T) {

_, resp = th.SystemAdminClient.DatabaseRecycle()
CheckNoError(t, resp)
}

func TestInvalidateCaches(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()
Client := th.Client

flag, resp := Client.InvalidateCaches()
CheckForbiddenStatus(t, resp)
if flag == true {
t.Fatal("should not clean the cache due no permission.")
}

flag, resp = th.SystemAdminClient.InvalidateCaches()
CheckNoError(t, resp)
if flag == false {
t.Fatal("should clean the cache")
}
}
13 changes: 13 additions & 0 deletions model/client4.go
Expand Up @@ -154,6 +154,10 @@ func (c *Client4) GetDatabaseRoute() string {
return fmt.Sprintf("/database")
}

func (c *Client4) GetCacheRoute() string {
return fmt.Sprintf("/caches")
}

func (c *Client4) GetClusterRoute() string {
return fmt.Sprintf("/cluster")
}
Expand Down Expand Up @@ -1154,6 +1158,15 @@ func (c *Client4) DatabaseRecycle() (bool, *Response) {
}
}

func (c *Client4) InvalidateCaches() (bool, *Response) {
if r, err := c.DoApiPost(c.GetCacheRoute()+"/invalidate", ""); err != nil {
return false, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
return CheckStatusOK(r), BuildResponse(r)
}
}

// Webhooks Section

// CreateIncomingWebhook creates an incoming webhook for a channel.
Expand Down

0 comments on commit 50a0e50

Please sign in to comment.