Workflow tweaks

* Allow Reader for email subject,
* Remove valid ID constraint check.
This commit is contained in:
Tomaž Jerman
2021-03-24 16:00:19 +01:00
parent bb2ad03193
commit 7e81c6bd17
4 changed files with 68 additions and 19 deletions
+40 -6
View File
@@ -42,8 +42,10 @@ func (h emailHandler) register() {
type (
emailSendArgs struct {
hasSubject bool
Subject string
hasSubject bool
Subject interface{}
subjectString string
subjectStream io.Reader
hasReplyTo bool
ReplyTo interface{}
@@ -79,6 +81,10 @@ type (
}
)
func (a emailSendArgs) GetSubject() (bool, string, io.Reader) {
return a.hasSubject, a.subjectString, a.subjectStream
}
func (a emailSendArgs) GetReplyTo() (bool, string, *sysTypes.User) {
return a.hasReplyTo, a.replyToString, a.replyToUser
}
@@ -122,7 +128,7 @@ func (h emailHandler) Send() *atypes.Function {
Parameters: []*atypes.Param{
{
Name: "subject",
Types: []string{"String"},
Types: []string{"String", "Reader"},
Meta: &atypes.ParamMeta{
Label: "Subject",
},
@@ -188,6 +194,17 @@ func (h emailHandler) Send() *atypes.Function {
return
}
// Converting Subject argument
if args.hasSubject {
aux := expr.Must(expr.Select(in, "subject"))
switch aux.Type() {
case h.reg.Type("String").Type():
args.subjectString = aux.Get().(string)
case h.reg.Type("Reader").Type():
args.subjectStream = aux.Get().(io.Reader)
}
}
// Converting ReplyTo argument
if args.hasReplyTo {
aux := expr.Must(expr.Select(in, "replyTo"))
@@ -265,8 +282,10 @@ func (h emailHandler) Send() *atypes.Function {
type (
emailMessageArgs struct {
hasSubject bool
Subject string
hasSubject bool
Subject interface{}
subjectString string
subjectStream io.Reader
hasReplyTo bool
ReplyTo interface{}
@@ -306,6 +325,10 @@ type (
}
)
func (a emailMessageArgs) GetSubject() (bool, string, io.Reader) {
return a.hasSubject, a.subjectString, a.subjectStream
}
func (a emailMessageArgs) GetReplyTo() (bool, string, *sysTypes.User) {
return a.hasReplyTo, a.replyToString, a.replyToUser
}
@@ -349,7 +372,7 @@ func (h emailHandler) Message() *atypes.Function {
Parameters: []*atypes.Param{
{
Name: "subject",
Types: []string{"String"},
Types: []string{"String", "Reader"},
Meta: &atypes.ParamMeta{
Label: "Subject",
},
@@ -423,6 +446,17 @@ func (h emailHandler) Message() *atypes.Function {
return
}
// Converting Subject argument
if args.hasSubject {
aux := expr.Must(expr.Select(in, "subject"))
switch aux.Type() {
case h.reg.Type("String").Type():
args.subjectString = aux.Get().(string)
case h.reg.Type("Reader").Type():
args.subjectStream = aux.Get().(io.Reader)
}
}
// Converting ReplyTo argument
if args.hasReplyTo {
aux := expr.Must(expr.Select(in, "replyTo"))
+23 -7
View File
@@ -3,12 +3,13 @@ package automation
import (
"context"
"fmt"
"github.com/cortezaproject/corteza-server/pkg/mail"
sysTypes "github.com/cortezaproject/corteza-server/system/types"
gomail "gopkg.in/mail.v2"
"io"
"io/ioutil"
"strings"
"github.com/cortezaproject/corteza-server/pkg/mail"
sysTypes "github.com/cortezaproject/corteza-server/system/types"
gomail "gopkg.in/mail.v2"
)
type (
@@ -37,17 +38,32 @@ func EmailHandler(reg emailHandlerRegistry) *emailHandler {
func (h emailHandler) send(_ context.Context, args *emailSendArgs) (err error) {
msg := mail.New()
if err = h.procArgs(msg, args.Subject, args); err != nil {
_, s, r := args.GetSubject()
if r != nil {
aux, _ := ioutil.ReadAll(r)
s = string(aux)
}
if err = h.procArgs(msg, s, args); err != nil {
return
}
return mail.Send(msg)
}
func (h emailHandler) message(_ context.Context, args *emailMessageArgs) (r *emailMessageResults, err error) {
func (h emailHandler) message(_ context.Context, args *emailMessageArgs) (*emailMessageResults, error) {
var err error
msg := mail.New()
if err = h.procArgs(msg, args.Subject, args); err != nil {
return
_, s, r := args.GetSubject()
if r != nil {
aux, _ := ioutil.ReadAll(r)
s = string(aux)
}
if err = h.procArgs(msg, s, args); err != nil {
return nil, err
}
return &emailMessageResults{Message: &emailMessage{msg: msg}}, nil
+1
View File
@@ -11,6 +11,7 @@ messageParams: &messageParams
label: Subject
types:
- { wf: String }
- { wf: Reader, suffix: Stream }
replyTo:
meta:
+4 -6
View File
@@ -5,15 +5,16 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/cortezaproject/corteza-server/pkg/errors"
"github.com/cortezaproject/corteza-server/pkg/handle"
"github.com/spf13/cast"
"io"
"net/http"
"net/url"
"reflect"
"strings"
"time"
"github.com/cortezaproject/corteza-server/pkg/errors"
"github.com/cortezaproject/corteza-server/pkg/handle"
"github.com/spf13/cast"
)
type (
@@ -196,9 +197,6 @@ func CastToFloat(val interface{}) (out float64, err error) {
func CastToID(val interface{}) (out uint64, err error) {
out, err = cast.ToUint64E(UntypedValue(val))
if out == 0 {
err = fmt.Errorf("invalid ID")
}
return
}