Skip to content

Commit

Permalink
MAX_TEXTERS_PER_CAMPAIGN env/org var
Browse files Browse the repository at this point in the history
  • Loading branch information
schuyler1d committed Jun 15, 2020
1 parent cbb44db commit 704e705
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/REFERENCE-environment_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
| MAX_CONTACTS | If set each campaign can only have a maximum of the value (an integer). This is good for staging/QA/evaluation instances. _Default_: false (i.e. there is no maximum) |
| MAX_CONTACTS_PER_TEXTER | Maximum contacts that a texter can send to, per campaign. This is particularly useful for dynamic assignment. This must not be blank/empty and must be a number greater than 0. |
| MAX_MESSAGE_LENGTH | The maximum size for a message that a texter can send. When you send a SMS message over 160 characters the message will be split, so you might want to set this as 160 or less if you have a high SMS-only target demographic. _Default_: 99999 |
| MAX_TEXTERS_PER_CAMPAIGN | Maximum texters that can join a campaign before joining with a dynamic assignment campaign link will block the texter from joining with a message that the campaign is full. |
| NEXMO_API_KEY | Nexmo API key. Required if using Nexmo. |
| NEXMO_API_SECRET | Nexmo API secret. Required if using Nexmo. |
| NGP_VAN_API_KEY | API key. Request an API key on the API Integrations section of VAN. Select `Hustle` API key in VAN. _Required_ for VAN integration_. |
Expand Down
12 changes: 9 additions & 3 deletions src/containers/JoinTeam.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ class JoinTeam extends React.Component {
organization = await this.props.mutations.joinOrganization(
this.props.location.search
);
} catch (ex) {
} catch (err) {
console.log("error joining", err);
const texterMessage = (err &&
err.message &&
err.message.match(/(Sorry,.+)$/)) || [
0,
"Something went wrong trying to join this organization. Please contact your administrator."
];
this.setState({
errors:
"Something went wrong trying to join this organization. Please contact your administrator."
errors: texterMessage[1]
});
}

Expand Down
14 changes: 14 additions & 0 deletions src/server/api/mutations/joinOrganization.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ export const joinOrganization = async (
organization = await cacheableData.organization.load(
campaign.organization_id
);
const maxTextersPerCampaign = getConfig(
"MAX_TEXTERS_PER_CAMPAIGN",
organization
);
if (maxTextersPerCampaign) {
const campaignTexterCount = await r.getCount(
r.knex("assignment").where("campaign_id", campaignId)
);
if (campaignTexterCount >= maxTextersPerCampaign) {
throw new GraphQLError(
"Sorry, this campaign has too many texters already"
);
}
}
} else {
throw new GraphQLError("Invalid join request");
}
Expand Down

0 comments on commit 704e705

Please sign in to comment.