mirror of
https://github.com/safing/portbase
synced 2025-09-02 10:40:39 +00:00
Merge pull request #47 from safing/feature/make-notifications-ack-by-default
Make default ack action if notification has none
This commit is contained in:
commit
80332fbfc7
2 changed files with 13 additions and 18 deletions
|
@ -54,7 +54,7 @@ func (lrw *LoggingResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
|
||||||
return nil, nil, errors.New("response does not implement http.Hijacker")
|
return nil, nil, errors.New("response does not implement http.Hijacker")
|
||||||
}
|
}
|
||||||
|
|
||||||
// RequestLogger is a logging middleware
|
// RequestLogger is a logging middleware.
|
||||||
func RequestLogger(next http.Handler) http.Handler {
|
func RequestLogger(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Tracef("api request: %s ___ %s", r.RemoteAddr, r.RequestURI)
|
log.Tracef("api request: %s ___ %s", r.RemoteAddr, r.RequestURI)
|
||||||
|
|
|
@ -123,6 +123,18 @@ func (n *Notification) Save() *Notification {
|
||||||
if n.GUID == "" {
|
if n.GUID == "" {
|
||||||
n.GUID = uuid.NewV4().String()
|
n.GUID = uuid.NewV4().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make ack notification if there are no defined actions
|
||||||
|
if len(n.AvailableActions) == 0 {
|
||||||
|
n.AvailableActions = []*Action{
|
||||||
|
{
|
||||||
|
ID: "ack",
|
||||||
|
Text: "OK",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
n.actionFunction = noOpAction
|
||||||
|
}
|
||||||
|
|
||||||
// check key
|
// check key
|
||||||
if n.DatabaseKey() == "" {
|
if n.DatabaseKey() == "" {
|
||||||
n.SetKey(fmt.Sprintf("notifications:all/%s", n.ID))
|
n.SetKey(fmt.Sprintf("notifications:all/%s", n.ID))
|
||||||
|
@ -175,23 +187,6 @@ func (n *Notification) SetActionFunction(fn func(*Notification)) *Notification {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeAck sets a default "OK" action and a no-op action function.
|
|
||||||
func (n *Notification) MakeAck() *Notification {
|
|
||||||
n.lock.Lock()
|
|
||||||
defer n.lock.Unlock()
|
|
||||||
|
|
||||||
n.AvailableActions = []*Action{
|
|
||||||
{
|
|
||||||
ID: "ack",
|
|
||||||
Text: "OK",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
n.Type = Info
|
|
||||||
n.actionFunction = noOpAction
|
|
||||||
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
// Response waits for the user to respond to the notification and returns the selected action.
|
// Response waits for the user to respond to the notification and returns the selected action.
|
||||||
func (n *Notification) Response() <-chan string {
|
func (n *Notification) Response() <-chan string {
|
||||||
n.lock.Lock()
|
n.lock.Lock()
|
||||||
|
|
Loading…
Add table
Reference in a new issue