Open platform to collect and prioritize feedback
add 403 page (#147)
Guilherme Oenningb699ba0a13b6
diff --git a/app/handlers/idea_test.go b/app/handlers/idea_test.goindex 492440b8f..991ceaa3a 100644--- a/app/handlers/idea_test.go+++ b/app/handlers/idea_test.go@@ -1,6 +1,7 @@package handlers_testimport (+ "net/http""testing""github.com/getfider/fider/app/handlers"@@ -123,7 +124,7 @@ func TestUpdateIdeaHandler_NonAuthorized(t *testing.T) {WithParam("number", idea.Number).ExecutePost(handlers.UpdateIdea(), `{ "title": "the new title", "description": "new description" }`)- Expect(code).To(Equal(401))+ Expect(code).To(Equal(http.StatusForbidden))}func TestPostCommentHandler(t *testing.T) {diff --git a/app/middlewares/auth.go b/app/middlewares/auth.goindex abec399ea..794bcf485 100644--- a/app/middlewares/auth.go+++ b/app/middlewares/auth.go@@ -1,8 +1,6 @@package middlewaresimport (- "net/http"-"github.com/getfider/fider/app/pkg/web")@@ -11,7 +9,7 @@ func IsAuthenticated() web.MiddlewareFunc {return func(next web.HandlerFunc) web.HandlerFunc {return func(c web.Context) error {if c.User() == nil {- return c.NoContent(http.StatusForbidden)+ return c.Unauthorized()}return next(c)}@@ -28,7 +26,7 @@ func IsAuthorized(roles ...int) web.MiddlewareFunc {return next(c)}}- return c.NoContent(http.StatusForbidden)+ return c.Unauthorized()}}}diff --git a/app/pkg/web/context.go b/app/pkg/web/context.goindex 6e5c7a02c..163d93204 100644--- a/app/pkg/web/context.go+++ b/app/pkg/web/context.go@@ -101,6 +101,14 @@ func (ctx *Context) IsAjax() bool {return strings.Contains(ctx.Request.Header.Get("Accept"), "application/json")}+//Unauthorized returns a 403 response+func (ctx *Context) Unauthorized() error {+ if ctx.IsAjax() {+ return ctx.JSON(http.StatusForbidden, Map{})+ }+ return ctx.Render(http.StatusForbidden, "403.html", Map{})+}+//NotFound returns a 404 pagefunc (ctx *Context) NotFound() error {return ctx.Render(http.StatusNotFound, "404.html", Map{})@@ -129,11 +137,6 @@ func (ctx *Context) HandleValidation(result *validate.Result) error {})}-//Unauthorized returns a 401 response-func (ctx *Context) Unauthorized() error {- return ctx.JSON(http.StatusUnauthorized, Map{})-}-//Ok returns 200 OK with JSON resultfunc (ctx *Context) Ok(data interface{}) error {return ctx.JSON(http.StatusOK, data)diff --git a/app/pkg/web/renderer.go b/app/pkg/web/renderer.goindex 6a3cd4f24..5beca3380 100644--- a/app/pkg/web/renderer.go+++ b/app/pkg/web/renderer.go@@ -26,6 +26,7 @@ func NewRenderer(settings *models.AppSettings, logger log.Logger) *Renderer {renderer.templates = make(map[string]*template.Template)renderer.add("index.html")+ renderer.add("403.html")renderer.add("404.html")renderer.add("500.html")diff --git a/views/403.html b/views/403.htmlnew file mode 100644index 000000000..61af32666--- /dev/null+++ b/views/403.html@@ -0,0 +1,21 @@+{{define "title"}}+Not Authorized · Fider+{{end}}++{{define "javascript"}}{{end}}++{{define "content"}}+<div class="ui middle aligned center aligned grid failure-page">+ <div class="column">+ <img src="http://getfider.com/images/logo-100x100.png"/>+ <h1>NOT AUTHORIZED</h1>+ <p>+ You are not authorized to view this page.+ </p>++ {{ if .tenant }}+ <span>Take me back to <a href="{{ .baseUrl }}">{{ .tenant.Subdomain }}.fider.io</a> home page.</span>+ {{ end }}+ </div>+</div>+{{end}}\ No newline at end of file