added jsvm .* binds
This commit is contained in:
parent
b2ac538580
commit
e87ef431c5
|
@ -14,6 +14,8 @@
|
||||||
"@hourly": "0 * * * *"
|
"@hourly": "0 * * * *"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- Added JSVM `$mails.*` binds for sending.
|
||||||
|
|
||||||
- Fill the `LastVerificationSentAt` and `LastResetSentAt` fields only after a successfull email send.
|
- Fill the `LastVerificationSentAt` and `LastResetSentAt` fields only after a successfull email send.
|
||||||
|
|
||||||
- Reflected the latest JS SDK changes in the Admin UI.
|
- Reflected the latest JS SDK changes in the Admin UI.
|
||||||
|
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"github.com/pocketbase/pocketbase/core"
|
"github.com/pocketbase/pocketbase/core"
|
||||||
"github.com/pocketbase/pocketbase/daos"
|
"github.com/pocketbase/pocketbase/daos"
|
||||||
"github.com/pocketbase/pocketbase/forms"
|
"github.com/pocketbase/pocketbase/forms"
|
||||||
|
"github.com/pocketbase/pocketbase/mails"
|
||||||
"github.com/pocketbase/pocketbase/models"
|
"github.com/pocketbase/pocketbase/models"
|
||||||
"github.com/pocketbase/pocketbase/models/schema"
|
"github.com/pocketbase/pocketbase/models/schema"
|
||||||
"github.com/pocketbase/pocketbase/tokens"
|
"github.com/pocketbase/pocketbase/tokens"
|
||||||
|
@ -415,6 +416,19 @@ func dbxBinds(vm *goja.Runtime) {
|
||||||
obj.Set("notBetween", dbx.NotBetween)
|
obj.Set("notBetween", dbx.NotBetween)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mailsBinds(vm *goja.Runtime) {
|
||||||
|
obj := vm.NewObject()
|
||||||
|
vm.Set("$mails", obj)
|
||||||
|
|
||||||
|
// admin
|
||||||
|
obj.Set("sendAdminPasswordReset", mails.SendAdminPasswordReset)
|
||||||
|
|
||||||
|
// record
|
||||||
|
obj.Set("sendRecordPasswordReset", mails.SendRecordPasswordReset)
|
||||||
|
obj.Set("sendRecordVerification", mails.SendRecordVerification)
|
||||||
|
obj.Set("sendRecordChangeEmail", mails.SendRecordChangeEmail)
|
||||||
|
}
|
||||||
|
|
||||||
func tokensBinds(vm *goja.Runtime) {
|
func tokensBinds(vm *goja.Runtime) {
|
||||||
obj := vm.NewObject()
|
obj := vm.NewObject()
|
||||||
vm.Set("$tokens", obj)
|
vm.Set("$tokens", obj)
|
||||||
|
|
|
@ -484,6 +484,60 @@ func TestDbxBinds(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMailsBindsCount(t *testing.T) {
|
||||||
|
vm := goja.New()
|
||||||
|
mailsBinds(vm)
|
||||||
|
|
||||||
|
testBindsCount(vm, "$mails", 4, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMailsBinds(t *testing.T) {
|
||||||
|
app, _ := tests.NewTestApp()
|
||||||
|
defer app.Cleanup()
|
||||||
|
|
||||||
|
admin, err := app.Dao().FindAdminByEmail("test@example.com")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
record, err := app.Dao().FindAuthRecordByEmail("users", "test@example.com")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
vm := goja.New()
|
||||||
|
baseBinds(vm)
|
||||||
|
mailsBinds(vm)
|
||||||
|
vm.Set("$app", app)
|
||||||
|
vm.Set("admin", admin)
|
||||||
|
vm.Set("record", record)
|
||||||
|
|
||||||
|
_, vmErr := vm.RunString(`
|
||||||
|
$mails.sendAdminPasswordReset($app, admin);
|
||||||
|
if (!$app.testMailer.lastMessage.html.includes("/_/#/confirm-password-reset/")) {
|
||||||
|
throw new Error("Expected admin password reset email")
|
||||||
|
}
|
||||||
|
|
||||||
|
$mails.sendRecordPasswordReset($app, record);
|
||||||
|
if (!$app.testMailer.lastMessage.html.includes("/_/#/auth/confirm-password-reset/")) {
|
||||||
|
throw new Error("Expected record password reset email")
|
||||||
|
}
|
||||||
|
|
||||||
|
$mails.sendRecordVerification($app, record);
|
||||||
|
if (!$app.testMailer.lastMessage.html.includes("/_/#/auth/confirm-verification/")) {
|
||||||
|
throw new Error("Expected record verification email")
|
||||||
|
}
|
||||||
|
|
||||||
|
$mails.sendRecordChangeEmail($app, record, "new@example.com");
|
||||||
|
if (!$app.testMailer.lastMessage.html.includes("/_/#/auth/confirm-email-change/")) {
|
||||||
|
throw new Error("Expected record email change email")
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
if vmErr != nil {
|
||||||
|
t.Fatal(vmErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestTokensBindsCount(t *testing.T) {
|
func TestTokensBindsCount(t *testing.T) {
|
||||||
vm := goja.New()
|
vm := goja.New()
|
||||||
tokensBinds(vm)
|
tokensBinds(vm)
|
||||||
|
@ -506,11 +560,11 @@ func TestTokensBinds(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
vm := goja.New()
|
vm := goja.New()
|
||||||
|
baseBinds(vm)
|
||||||
|
tokensBinds(vm)
|
||||||
vm.Set("$app", app)
|
vm.Set("$app", app)
|
||||||
vm.Set("admin", admin)
|
vm.Set("admin", admin)
|
||||||
vm.Set("record", record)
|
vm.Set("record", record)
|
||||||
baseBinds(vm)
|
|
||||||
tokensBinds(vm)
|
|
||||||
|
|
||||||
sceneraios := []struct {
|
sceneraios := []struct {
|
||||||
js string
|
js string
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -161,12 +161,9 @@ func (p *plugin) registerMigrations() error {
|
||||||
dbxBinds(vm)
|
dbxBinds(vm)
|
||||||
tokensBinds(vm)
|
tokensBinds(vm)
|
||||||
securityBinds(vm)
|
securityBinds(vm)
|
||||||
// note: disallow for now and give the authors of custom SaaS offerings
|
osBinds(vm)
|
||||||
// some time to adjust their code to avoid eventual security issues
|
filepathBinds(vm)
|
||||||
//
|
httpClientBinds(vm)
|
||||||
// osBinds(vm)
|
|
||||||
// filepathBinds(vm)
|
|
||||||
// httpClientBinds(vm)
|
|
||||||
|
|
||||||
vm.Set("migrate", func(up, down func(db dbx.Builder) error) {
|
vm.Set("migrate", func(up, down func(db dbx.Builder) error) {
|
||||||
m.AppMigrations.Register(up, down, file)
|
m.AppMigrations.Register(up, down, file)
|
||||||
|
@ -236,6 +233,7 @@ func (p *plugin) registerHooks() error {
|
||||||
requireRegistry.Enable(vm)
|
requireRegistry.Enable(vm)
|
||||||
console.Enable(vm)
|
console.Enable(vm)
|
||||||
process.Enable(vm)
|
process.Enable(vm)
|
||||||
|
|
||||||
baseBinds(vm)
|
baseBinds(vm)
|
||||||
dbxBinds(vm)
|
dbxBinds(vm)
|
||||||
filesystemBinds(vm)
|
filesystemBinds(vm)
|
||||||
|
@ -246,6 +244,8 @@ func (p *plugin) registerHooks() error {
|
||||||
httpClientBinds(vm)
|
httpClientBinds(vm)
|
||||||
formsBinds(vm)
|
formsBinds(vm)
|
||||||
apisBinds(vm)
|
apisBinds(vm)
|
||||||
|
mailsBinds(vm)
|
||||||
|
|
||||||
vm.Set("$app", p.app)
|
vm.Set("$app", p.app)
|
||||||
vm.Set("$template", templateRegistry)
|
vm.Set("$template", templateRegistry)
|
||||||
vm.Set("__hooks", absHooksDir)
|
vm.Set("__hooks", absHooksDir)
|
||||||
|
|
Loading…
Reference in New Issue