Skip to content

Commit

Permalink
PHONE_INVENTORY and TWILIO_MULTI_ORG as defaults, fix user_id bug in …
Browse files Browse the repository at this point in the history
…Campaign texters list and filter on null not =null
  • Loading branch information
schuyler1d committed Aug 11, 2020
1 parent aff1a80 commit b88eb47
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 30 deletions.
12 changes: 12 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@
"value": "https://<changeme>.herokuapp.com/twilio-message-report"
},

"TWILIO_MULTI_ORG": {
"description": "Allows each organization in the Spoke instance to set Twilio variables within the app",
"required": false,
"value": "1"
},

"PHONE_INVENTORY": {
"description": "Enables organization owners to be able to buy Twilio phone numbers within the app",
"required": false,
"value": "1"
},

"EMAIL_HOST": {
"description": "for email notification integration",
"required": false,
Expand Down
10 changes: 5 additions & 5 deletions docs/REFERENCE-best-practices-conformance-messaging.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Best Practices on Conformance and Messaging

- [Introduction](#Introduction)
- [One click or keypress per-message](#One%20click%20or%20keypress%20per-message)
- [Opting out](#Opting%20out)
- [Modifying the initial text message](#Modifying%20the%20initial%20text%20message)
- [Blocking inappropriate texter content](#Blocking%20inappropriate%20texter%20content)
- [Introduction](#introduction)
- [One click or keypress per-message](#one-click-or-keypress-per-message)
- [Opting out](#opting-out)
- [Modifying the initial text message](#modifying-the-initial-text-message)
- [Blocking inappropriate texter content](#blocking-inappropriate-texter-content)

## Introduction

Expand Down
4 changes: 4 additions & 0 deletions src/containers/AssignmentTexterContact.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ export class AssignmentTexterContact extends React.Component {
messageStatusFilter === "needsMessage" &&
/fast=1/.test(document.location.search)
) {
// FUTURE: this can cause some confusion especially when a texter
// thinks they completed sending, but there are still waiting requests
// This probably needs some interface tweaks to communicate something
// to the texter.
this.props.mutations.sendMessage(message, contact.id).then(() => {
console.log("sentMessage", contact.id);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ export const requestNewBatchCount = async ({
return 0;
}
const availableCount = await r.getCount(
r.knex("campaign_contact").where({
campaign_id: campaign.id,
message_status: "needsMessage",
assignment_id: null
})
r
.knex("campaign_contact")
.where({
campaign_id: campaign.id,
message_status: "needsMessage"
})
.whereNull("assignment_id")
);

// Make sure they don't have any needsResponse(s)
Expand Down
7 changes: 5 additions & 2 deletions src/server/api/campaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ export const resolvers = {
"assignment.id",
"assignment.user_id",
"assignment.campaign_id",
"assignment.max_contacts",
"user.first_name",
"user.last_name",
"user_organization.role"
Expand All @@ -454,8 +455,10 @@ export const resolvers = {
.havingRaw("count(*) > 0");
}
}

return query;
return (await query).map(a => ({
...a,
texter: { ...a, id: a.user_id }
}));
},
interactionSteps: async (campaign, _, { user }) => {
await accessRequired(user, campaign.organization_id, "TEXTER", true);
Expand Down
5 changes: 4 additions & 1 deletion src/server/api/mutations/buyPhoneNumbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export const buyPhoneNumbers = async (
) => {
await accessRequired(user, organizationId, "OWNER");
const org = await cacheableData.organization.load(organizationId);
if (!getConfig("EXPERIMENTAL_PHONE_INVENTORY", org, { truthy: true })) {
if (
!getConfig("EXPERIMENTAL_PHONE_INVENTORY", org, { truthy: true }) &&
!getConfig("PHONE_INVENTORY", org, { truthy: true })
) {
throw new Error("Phone inventory management is not enabled");
}
const serviceName = getConfig("DEFAULT_SERVICE", org);
Expand Down
2 changes: 1 addition & 1 deletion src/server/api/mutations/findNewCampaignContact.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export const findNewCampaignContact = async (
"in",
r
.knex("campaign_contact")
.whereNull("assignment_id")
.where({
assignment_id: null,
// FUTURE: a function in the batch policy could allow convo contacts, too
message_status: "needsMessage",
campaign_id: campaign.id
Expand Down
35 changes: 20 additions & 15 deletions src/server/api/organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ export const getSideboxChoices = organization => {
};

const campaignNumbersEnabled = organization => {
const inventoryEnabled = getConfig(
"EXPERIMENTAL_PHONE_INVENTORY",
organization,
{
const inventoryEnabled =
getConfig("EXPERIMENTAL_PHONE_INVENTORY", organization, {
truthy: true
}
);
}) ||
getConfig("PHONE_INVENTORY", organization, {
truthy: true
});

return (
inventoryEnabled &&
Expand Down Expand Up @@ -269,19 +269,24 @@ export const resolvers = {
},
phoneInventoryEnabled: async (organization, _, { user }) => {
await accessRequired(user, organization.id, "SUPERVOLUNTEER");
return getConfig("EXPERIMENTAL_PHONE_INVENTORY", organization, {
truthy: true
});
return (
getConfig("EXPERIMENTAL_PHONE_INVENTORY", organization, {
truthy: true
}) ||
getConfig("PHONE_INVENTORY", organization, {
truthy: true
})
);
},
campaignPhoneNumbersEnabled: async (organization, _, { user }) => {
await accessRequired(user, organization.id, "SUPERVOLUNTEER");
const inventoryEnabled = getConfig(
"EXPERIMENTAL_PHONE_INVENTORY",
organization,
{
const inventoryEnabled =
getConfig("EXPERIMENTAL_PHONE_INVENTORY", organization, {
truthy: true
}
);
}) ||
getConfig("PHONE_INVENTORY", organization, {
truthy: true
});
const configured =
inventoryEnabled &&
getConfig("EXPERIMENTAL_CAMPAIGN_PHONE_NUMBERS", organization, {
Expand Down
2 changes: 1 addition & 1 deletion src/server/api/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ const rootResolvers = {
},
RootQuery: {
campaign: async (_, { id }, { loaders, user }) => {
const campaign = await Campaign.get(id);
const campaign = await loaders.campaign.load(id);
await accessRequired(user, campaign.organization_id, "SUPERVOLUNTEER");
return campaign;
},
Expand Down

0 comments on commit b88eb47

Please sign in to comment.