summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--system/admin/admin.go2
-rw-r--r--system/api/handlers.go24
-rw-r--r--system/item/types.go5
3 files changed, 24 insertions, 7 deletions
diff --git a/system/admin/admin.go b/system/admin/admin.go
index 76f36f6..e3ae2d6 100644
--- a/system/admin/admin.go
+++ b/system/admin/admin.go
@@ -487,7 +487,7 @@ var analyticsHTML = `
<div class="analytics">
<div class="card">
<div class="card-content">
- <p class="right">Data range: {{ .from }} - {{ .to }} (GMT)</p>
+ <p class="right">Data range: {{ .from }} - {{ .to }} (UTC)</p>
<div class="card-title">API Requests</div>
<canvas id="analytics-chart"></canvas>
<script>
diff --git a/system/api/handlers.go b/system/api/handlers.go
index 07201ff..af0808d 100644
--- a/system/api/handlers.go
+++ b/system/api/handlers.go
@@ -16,7 +16,7 @@ import (
func typesHandler(res http.ResponseWriter, req *http.Request) {
var types = []string{}
for t, fn := range item.Types {
- if !hide(fn(), res) {
+ if !hide(fn(), res, req) {
types = append(types, t)
}
}
@@ -44,7 +44,7 @@ func contentsHandler(res http.ResponseWriter, req *http.Request) {
return
}
- if hide(it(), res) {
+ if hide(it(), res, req) {
return
}
@@ -116,7 +116,7 @@ func contentHandler(res http.ResponseWriter, req *http.Request) {
return
}
- if hide(pt(), res) {
+ if hide(pt(), res, req) {
return
}
@@ -159,10 +159,12 @@ func contentHandlerBySlug(res http.ResponseWriter, req *http.Request) {
return
}
- if hide(it(), res) {
+ if hide(it(), res, req) {
return
}
+ defer push(res, req, it, post)
+
j, err := fmtJSON(json.RawMessage(post))
if err != nil {
res.WriteHeader(http.StatusInternalServerError)
@@ -172,9 +174,19 @@ func contentHandlerBySlug(res http.ResponseWriter, req *http.Request) {
sendData(res, j, http.StatusOK)
}
-func hide(it interface{}, res http.ResponseWriter) bool {
+func hide(it interface{}, res http.ResponseWriter, req *http.Request) bool {
// check if should be hidden
- if _, ok := it.(item.Hideable); ok {
+ if h, ok := it.(item.Hideable); ok {
+ err := h.Hide(req)
+ if err.Error() == item.AllowHiddenItem {
+ return false
+ }
+
+ if err != nil {
+ res.WriteHeader(http.StatusInternalServerError)
+ return true
+ }
+
res.WriteHeader(http.StatusNotFound)
return true
}
diff --git a/system/item/types.go b/system/item/types.go
index 33e9ced..b4b361b 100644
--- a/system/item/types.go
+++ b/system/item/types.go
@@ -14,6 +14,11 @@ Add this to the file which defines %[1]s{} in the 'content' package:
`
+
+ // AllowHiddenItem should be used as an error to tell a caller of Hideable#Hide
+ // that this type is hidden, but should be shown in a particular case, i.e.
+ // if requested by a valid admin or user
+ AllowHiddenItem = `Allow hidden item`
)
// Types is a map used to reference a type name to its actual Editable type