Skip to content

Commit

Permalink
profile: show warning and option to reactivate when contact method is…
Browse files Browse the repository at this point in the history
… disabled (#28)

* update gql schema

* add verification form and dialog components

* adjust warning tooltip prop name

* call new verification dialog from relevant components

* delete old verification dialog/form

* add graphql2 mutations for verifying and testing contact method phone numbers

* remove old graphql mutations

* update verify and send mutations on ui to reference new code

* use formcontainer and add field error checks to verification code field

- using a string as input as this allows us to expand past digits in the future if we want to, as well as the fact that in a browser a user can still type "e" in as a valid number in a type="number" textfield

* use else

* update verification smoketest

* update other smoketests

* update schema from pr comments

* move field error to graphql layer and remove references to the resend bool

* rename verification form and dialog with User prefixed to match other components

* rename warning "tooltip" text prop to "message" and add a proptype for it

* reword a CM's disabled warning message to be type agnostic

* modify db statement to only reactivate that single contact method, and use within the opened transaction

* create migration to update verification table

update mutation variable on UI and update relevant store functions

* fix smoketests using incorrect variable name for the verification code

* give each action menu it's own state via a new component

* set verification text field to type number

* disable submit button until code has been sent at least once

* delete dupe function and fix india phone number formatting

* render subtitle properly in verification form

* add a caption for UNSTOP use cases

* add apollo hooks library

* add apollo hooks provider

- uses graphql2 client only

* update FlatList avatar/icon padding

* add reactivate button directly to CM list item if disabled

* send code immediately as dialog opens to reactivate

* only call the useEffect hook once, after render

* don't show reactivate button on enabled CMs

* address no-op setState warning

* fix deleting a contact method if a verification code is in flight

* fix for closing delete contact method dialog manually

* don't show UNSTOP message for voice calls

* add avatar and icon support to PaginatedList

* remove tx from graphql funcs

* lock apollo hooks version in package.json

* remove sendAttempted and default the button to say "resend"

* send verification code from form

* pr comment: remove references to using an avatar

* pr comment: adjust FlatList action prop names

* remove unused state vars

* remove submitDisabled from FormDialog

* fix spacing

* better error message

* Show disabled attributes on unowned profiles

* remove unused proptype

* pr comment: remove tertiary action

* pr comment: move open verify dialog logic

* use @apollo/react-hooks instead of react-apollo-hooks

* refactor contact method list to use hooks

* use hook mutation for sending the verification code on button

* add no type submit option to loading button

* use hook mutation to submit verification form

* update too many messages error message

* fix phone number formatting in test

* don't show spacing if no icon specified on paginated lists

* fix avatar

* fix code types on smoketests

* spacing

* remove code expiration function

* don't recalculate when verification code expires

* update stmt call to use stmtContext function

* remove duplicate permissions check

* adjust func definition

* remove redundant console.error

* cleanup getIcon func

* consolidate duplicate lines into function

* fix status reference when sending a verification code

* rename migration such that it's the most recent one

* only use international formats for all supported phone numbers

* refactor how a test message is sent

* re-add user id lookup

* sending a test should fail if the CM is disabled

* update enable voice sms test

* update enable by sms test

* update sms verification smoketest

* update voice verification smoketest

* update variable names for better readabilitiy

* gofmt

* clear send error when attempting to verify
  • Loading branch information
Forfold committed Jul 16, 2019
1 parent 96a372c commit 32d6132
Show file tree
Hide file tree
Showing 41 changed files with 1,158 additions and 822 deletions.
9 changes: 5 additions & 4 deletions engine/verifymanager/db.go
Expand Up @@ -22,7 +22,7 @@ func (db *DB) Name() string { return "Engine.VerificationManager" }
func NewDB(ctx context.Context, db *sql.DB) (*DB, error) {
lock, err := processinglock.NewLock(ctx, db, processinglock.Config{
Type: processinglock.TypeVerify,
Version: 1,
Version: 2,
})
if err != nil {
return nil, err
Expand All @@ -34,15 +34,16 @@ func NewDB(ctx context.Context, db *sql.DB) (*DB, error) {
insertMessages: p.P(`
with rows as (
insert into outgoing_messages (message_type, contact_method_id, user_id, user_verification_code_id)
select 'verification_message', send_to, user_id, code.id
select 'verification_message', contact_method_id, cm.user_id, code.id
from user_verification_codes code
where send_to notnull and now() < expires_at
join user_contact_methods cm on cm.id = contact_method_id
where not sent and now() < expires_at
limit 100
for update skip locked
returning user_verification_code_id id
)
update user_verification_codes code
set send_to = null
set sent = true
from rows
where code.id = rows.id
`),
Expand Down
74 changes: 0 additions & 74 deletions graphql/contactmethod.go
Expand Up @@ -170,77 +170,3 @@ func (h *Handler) sendContactMethodTest() *g.Field {
},
}
}

func (h *Handler) sendContactMethodVerification() *g.Field {
return &g.Field{
Type: g.NewObject(g.ObjectConfig{
Name: "SendContactMethodVerification",
Fields: g.Fields{"id": &g.Field{Type: g.String}},
}),
Args: g.FieldConfigArgument{
"input": &g.ArgumentConfig{
Type: g.NewInputObject(g.InputObjectConfig{
Name: "SendContactMethodVerificationInput",
Fields: g.InputObjectConfigFieldMap{
"contact_method_id": &g.InputObjectFieldConfig{Type: g.NewNonNull(g.String)},
"resend": &g.InputObjectFieldConfig{Type: g.Boolean},
},
}),
},
},
Resolve: func(p g.ResolveParams) (interface{}, error) {
m, ok := p.Args["input"].(map[string]interface{})
if !ok {
return nil, errors.New("invalid input type")
}

resend, _ := m["resend"].(bool)
var result struct {
CMID string `json:"id"`
}
result.CMID, _ = m["contact_method_id"].(string)

err := h.c.NotificationStore.SendContactMethodVerification(p.Context, result.CMID, resend)
return newScrubber(p.Context).scrub(result, err)
},
}
}

func (h *Handler) verifyContactMethod() *g.Field {
return &g.Field{
Type: g.NewObject(g.ObjectConfig{
Name: "VerifyContactMethodOutput",
Fields: g.Fields{
"contact_method_ids": &g.Field{Type: g.NewList(g.String), Description: "IDs of contact methods that have been enabled by this operation."}},
}),
Args: g.FieldConfigArgument{
"input": &g.ArgumentConfig{
Type: g.NewInputObject(g.InputObjectConfig{
Name: "VerifyContactMethodInput",
Fields: g.InputObjectConfigFieldMap{
"verification_code": &g.InputObjectFieldConfig{Type: g.NewNonNull(g.Int)},
"contact_method_id": &g.InputObjectFieldConfig{Type: g.NewNonNull(g.String)},
},
}),
},
},
Resolve: func(p g.ResolveParams) (interface{}, error) {
m, ok := p.Args["input"].(map[string]interface{})
if !ok {
return nil, errors.New("invalid input type")
}

id, _ := m["contact_method_id"].(string)
var code int
code, _ = m["verification_code"].(int)

changed, err := h.c.NotificationStore.VerifyContactMethod(p.Context, id, code)
var result struct {
IDs []string `json:"contact_method_ids"`
}
result.IDs = changed
return newScrubber(p.Context).scrub(result, err)

},
}
}
2 changes: 0 additions & 2 deletions graphql/schema.go
Expand Up @@ -91,8 +91,6 @@ func (h *Handler) buildSchema() error {
"createAll": h.createAllField(),
"updateConfigLimit": h.updateConfigLimitField(),
"sendContactMethodTest": h.sendContactMethodTest(),
"sendContactMethodVerification": h.sendContactMethodVerification(),
"verifyContactMethod": h.verifyContactMethod(),
"deleteHeartbeatMonitor": h.deleteHeartbeatMonitorField(),
"updateUserOverride": h.updateUserOverrideField(),
"deleteAll": h.deleteAllField(),
Expand Down

0 comments on commit 32d6132

Please sign in to comment.