quick notifier fix

pull/273/head
Hunter Long 2019-11-05 19:35:01 -08:00
parent c4d1cdcf0e
commit 6d78fceffc
3 changed files with 16 additions and 18 deletions

View File

@ -102,7 +102,7 @@ func (n *Notification) AfterFind() (err error) {
func (n *Notification) AddQueue(uid string, msg interface{}) { func (n *Notification) AddQueue(uid string, msg interface{}) {
data := &QueueData{uid, msg} data := &QueueData{uid, msg}
n.Queue = append(n.Queue, data) n.Queue = append(n.Queue, data)
utils.Log(0, fmt.Sprintf("Notifier '%v' added new item (%v) to the queue. (%v queued)", n.Method, uid, len(n.Queue))) utils.Log(1, fmt.Sprintf("Notifier '%v' added new item (%v) to the queue. (%v queued)", n.Method, uid, len(n.Queue)))
} }
// CanTest returns true if the notifier implements the OnTest interface // CanTest returns true if the notifier implements the OnTest interface
@ -189,8 +189,8 @@ func reverseLogs(input []*NotificationLog) []*NotificationLog {
} }
// isInDatabase returns true if the notifier has already been installed // isInDatabase returns true if the notifier has already been installed
func isInDatabase(n *Notification) bool { func isInDatabase(n Notifier) bool {
inDb := modelDb(n).RecordNotFound() inDb := modelDb(n.Select()).RecordNotFound()
return !inDb return !inDb
} }
@ -216,13 +216,14 @@ func Update(n Notifier, notif *Notification) (*Notification, error) {
} }
// insertDatabase will create a new record into the database for the notifier // insertDatabase will create a new record into the database for the notifier
func insertDatabase(n *Notification) (int64, error) { func insertDatabase(n Notifier) (int64, error) {
n.Limits = 3 noti := n.Select()
query := db.Create(n) noti.Limits = 3
query := db.Create(noti)
if query.Error != nil { if query.Error != nil {
return 0, query.Error return 0, query.Error
} }
return n.Id, query.Error return noti.Id, query.Error
} }
// SelectNotifier returns the Notification struct from the database // SelectNotifier returns the Notification struct from the database
@ -237,7 +238,7 @@ func SelectNotifier(method string) (*Notification, Notifier, error) {
return notifier, comm.(Notifier), nil return notifier, comm.(Notifier), nil
} }
} }
return nil, nil, nil return nil, nil, errors.New("cannot find notifier")
} }
// Init accepts the Notifier interface to initialize the notifier // Init accepts the Notifier interface to initialize the notifier
@ -309,9 +310,9 @@ CheckNotifier:
// install will check the database for the notification, if its not inserted it will insert a new record for it // install will check the database for the notification, if its not inserted it will insert a new record for it
func install(n Notifier) error { func install(n Notifier) error {
inDb := isInDatabase(n.Select()) inDb := isInDatabase(n)
if !inDb { if !inDb {
_, err := insertDatabase(n.Select()) _, err := insertDatabase(n)
if err != nil { if err != nil {
utils.Log(3, err) utils.Log(3, err)
return err return err

View File

@ -140,7 +140,7 @@
<h3 class="mt-4">Bulk Import Services</h3> <h3 class="mt-4">Bulk Import Services</h3>
You can import multiple services based on a CSV file with the format shown on the <a href="https://github.com/hunterlong/statping/wiki/Bulk-Import-Services" target="_blank">Bulk Import Wiki</a>. You can import multiple services based on a CSV file with the format shown on the <a href="https://github.com/hunterlong/statping/wiki/Bulk-Import-Services" target="_blank">Bulk Import Wiki</a>.
<div class="card"> <div class="card mt-2">
<div class="card-body"> <div class="card-body">
<form action="/settings/bulk_import" method="POST" enctype="multipart/form-data" class="form-inline"> <form action="/settings/bulk_import" method="POST" enctype="multipart/form-data" class="form-inline">
<div class="form-group col-10"> <div class="form-group col-10">
@ -158,16 +158,13 @@
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<a href="/settings/export" class="btn btn-sm btn-secondary float-right">Export Settings</a>
{{if .Domain}}
<a href="#" class="btn btn-sm btn-secondary float-right ml-1">Authentication QR Code</a>
{{end}}
{{if .Domain}} {{if .Domain}}
<div class="row align-content-center"> <div class="row align-content-center">
<img class="rounded text-center" width="300" height="300" src="https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl={{ QrAuth }}"> <img class="rounded text-center" width="300" height="300" src="https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl={{ QrAuth }}">
</div> </div>
<a class="btn btn-sm btn-primary" href={{safeURL QrAuth}}>Open in Statping App</a> <a class="btn btn-sm btn-primary" href={{safeURL QrAuth}}>Open in Statping App</a>
<a href="/settings/export" class="btn btn-sm btn-secondary">Export Settings</a>
{{end}} {{end}}
</div> </div>

File diff suppressed because one or more lines are too long