Added support for multiperson property in notifications (#4440)
This commit is contained in:
parent
9e0811f31f
commit
9e1aa92b08
2 changed files with 71 additions and 0 deletions
|
@ -98,6 +98,32 @@ func (pd PropDef) GetValue(v interface{}, resolver PropValueResolver) (string, e
|
|||
}
|
||||
return userID, nil
|
||||
|
||||
case "multiPerson":
|
||||
// v is a slice of user IDs
|
||||
userIDs, ok := v.([]interface{})
|
||||
if !ok {
|
||||
return "", fmt.Errorf("multiPerson property type: %w", ErrInvalidPropertyValueType)
|
||||
}
|
||||
if resolver != nil {
|
||||
usernames := make([]string, len(userIDs))
|
||||
|
||||
for i, userIDInterface := range userIDs {
|
||||
userID := userIDInterface.(string)
|
||||
|
||||
user, err := resolver.GetUserByID(userID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if user == nil {
|
||||
usernames[i] = userID
|
||||
} else {
|
||||
usernames[i] = user.Username
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Join(usernames, ", "), nil
|
||||
}
|
||||
|
||||
case "multiSelect":
|
||||
// v is a slice of strings containing option ids
|
||||
ms, ok := v.([]interface{})
|
||||
|
|
|
@ -12,6 +12,24 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type MockResolver struct{}
|
||||
|
||||
func (r MockResolver) GetUserByID(userID string) (*User, error) {
|
||||
if userID == "user_id_1" {
|
||||
return &User{
|
||||
ID: "user_id_1",
|
||||
Username: "username_1",
|
||||
}, nil
|
||||
} else if userID == "user_id_2" {
|
||||
return &User{
|
||||
ID: "user_id_2",
|
||||
Username: "username_2",
|
||||
}, nil
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func Test_parsePropertySchema(t *testing.T) {
|
||||
board := &Board{
|
||||
ID: utils.NewID(utils.IDTypeBoard),
|
||||
|
@ -44,6 +62,33 @@ func Test_parsePropertySchema(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func Test_GetValue(t *testing.T) {
|
||||
resolver := MockResolver{}
|
||||
|
||||
propDef := PropDef{
|
||||
Type: "multiPerson",
|
||||
}
|
||||
|
||||
value, err := propDef.GetValue([]interface{}{"user_id_1", "user_id_2"}, resolver)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "username_1, username_2", value)
|
||||
|
||||
// trying with only user
|
||||
value, err = propDef.GetValue([]interface{}{"user_id_1"}, resolver)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "username_1", value)
|
||||
|
||||
// trying with unknown user
|
||||
value, err = propDef.GetValue([]interface{}{"user_id_1", "user_id_unknown"}, resolver)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "username_1, user_id_unknown", value)
|
||||
|
||||
// trying with multiple unknown users
|
||||
value, err = propDef.GetValue([]interface{}{"michael_scott", "jim_halpert"}, resolver)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "michael_scott, jim_halpert", value)
|
||||
}
|
||||
|
||||
const (
|
||||
cardPropertiesExample = `[
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue