Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
schuyler1d committed Aug 18, 2017
2 parents f2b2258 + 02f0f5d commit bb9174b
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 28 deletions.
4 changes: 3 additions & 1 deletion src/components/AssignmentTexterSurveys.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ const styles = {
root: {
},
card: {
marginTop: 10,
marginBottom: 10,
backgroundColor: grey50,
padding: 20
padding: 10
},
cardHeader: {
padding: 0
Expand Down
2 changes: 1 addition & 1 deletion src/components/CannedResponseMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ScriptList from './ScriptList'

const styles = {
popover: {
width: 500
width: '75%'
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/components/ContactToolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ import { grey100 } from 'material-ui/styles/colors'

const inlineStyles = {
toolbar: {
backgroundColor: grey100
backgroundColor: grey100,
},
cellToolbarTitle: {
fontSize: 14
fontSize: '1em'
},
locationToolbarTitle: {
fontSize: 14
fontSize: '1em'
},
timeToolbarTitle: {
fontSize: 14
fontSize: '1em'
}
}


const ContactToolbar = function ContactToolbar(props) {
const { campaignContact, rightToolbarIcon } = props

Expand Down
27 changes: 15 additions & 12 deletions src/containers/AssignmentTexterContact.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react'
import { StyleSheet, css } from 'aphrodite'
import ContactToolbar from '../components/ContactToolbar'
import MessageList from '../components/MessageList'
import ProhibitedIcon from 'material-ui/svg-icons/av/not-interested'
import CannedResponseMenu from '../components/CannedResponseMenu'
import AssignmentTexterSurveys from '../components/AssignmentTexterSurveys'
import RaisedButton from 'material-ui/RaisedButton'
Expand Down Expand Up @@ -52,12 +51,15 @@ const styles = StyleSheet.create({
color: 'white',
zIndex: 1000000
},
messageForm: {
backgroundColor: 'red'
},
loadingIndicator: {
maxWidth: '50%'
},
navigationToolbarTitle: {
fontSize: '12px',
position: 'absolute',
position: 'relative',
top: 5

},
Expand All @@ -73,7 +75,7 @@ const styles = StyleSheet.create({
flex: '0 0 auto'
},
messageField: {
padding: 20
padding: 10
},
dialogActions: {
marginTop: 20,
Expand All @@ -89,11 +91,15 @@ const inlineStyles = {
},
exitTexterIconButton: {
float: 'right',
height: '56px'
height: '50px',
zIndex: 100,
position: 'absolute',
top: 0,
right: '-30'
},
toolbarIconButton: {
position: 'absolute',
top: 4
top: 0
// without this the toolbar icons are not centered vertically
},
actionToolbar: {
Expand Down Expand Up @@ -492,22 +498,19 @@ class AssignmentTexterContact extends React.Component {
disabled={this.state.disabled}
/>
{this.renderNeedsResponseToggleButton(contact)}
<ToolbarSeparator />
<RaisedButton
label='Canned responses'
onTouchTap={this.handleOpenPopover}
/>
<ToolbarSeparator />
<IconButton
<RaisedButton
secondary
style={inlineStyles.toolbarIconButton}
label='Opt out'
onTouchTap={this.handleOpenDialog}
tooltip='Opt out this contact'
tooltipPosition='top-center'
>
<ProhibitedIcon />
</IconButton>

</RaisedButton>
<div
style={{ float: 'right', marginLeft: 20 }}
>
Expand Down Expand Up @@ -591,7 +594,7 @@ class AssignmentTexterContact extends React.Component {
type='submit'
style={inlineStyles.dialogButton}
component={GSSubmitButton}
label='Send message and opt out user'
label='Send'
/>
</div>
</GSForm>
Expand Down
21 changes: 21 additions & 0 deletions src/server/api/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ export async function accessRequired(user, orgId, role, allowSuperadmin = false)
}
}

export async function assignmentRequired(user, assignmentId) {
authRequired(user)

if (user.is_superadmin) {
return
}

const [assignment] = await r.knex('assignment')
.where({
user_id: user.id,
id: assignmentId
}).limit(1)

if (typeof assignment === 'undefined') {
throw new GraphQLError({
status: 403,
message: 'You are not authorized to access that resource.'
})
}
}

export function superAdminRequired(user) {
authRequired(user)

Expand Down
28 changes: 19 additions & 9 deletions src/server/api/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import {
GraphQLError,
authRequired,
accessRequired,
assignmentRequired,
superAdminRequired
} from './errors'
import nexmo from './lib/nexmo'
Expand Down Expand Up @@ -152,7 +153,6 @@ const rootSchema = `
currentUser: User
organization(id:String!): Organization
campaign(id:String!): Campaign
invite(id:String!): Invite
inviteByHash(hash:String!): [Invite]
contact(id:String!): CampaignContact
assignment(id:String!): Assignment
Expand Down Expand Up @@ -478,14 +478,27 @@ const rootMutations = {
}
return editCampaign(id, campaign, loaders)
},
createCannedResponse: async (_, { cannedResponse }) => {
createCannedResponse: async (_, { cannedResponse }, { user, loaders }) => {
authRequired(user)

const cannedResponseInstance = new CannedResponse({
campaign_id: cannedResponse.campaignId,
user_id: cannedResponse.userId,
title: cannedResponse.title,
text: cannedResponse.text
})
return await cannedResponseInstance.save()
}).save()
//deletes duplicate created canned_responses
let query = r.knex('canned_response')
.where('text', 'in',
r.knex('canned_response')
.where({
text: cannedResponse.text,
campaign_id: cannedResponse.campaignId
})
.select('text')
).andWhere({ user_id: cannedResponse.userId })
.del()
await query
},
createOrganization: async (_, { name, userId, inviteId }, { loaders, user }) => {
authRequired(user)
Expand Down Expand Up @@ -514,8 +527,9 @@ const rootMutations = {

return newOrganization
},
editCampaignContactMessageStatus: async(_, { messageStatus, campaignContactId }, { loaders }) => {
editCampaignContactMessageStatus: async(_, { messageStatus, campaignContactId }, { loaders, user }) => {
const contact = await loaders.campaignContact.load(campaignContactId)
await assignmentRequired(user, contact.assignment_id)
contact.message_status = messageStatus
return await contact.save()
},
Expand Down Expand Up @@ -656,10 +670,6 @@ const rootResolvers = {
},
organization: async(_, { id }, { loaders }) =>
loaders.organization.load(id),
invite: async (_, { id }, { loaders, user }) => {
authRequired(user)
return loaders.invite.load(id)
},
inviteByHash: async (_, { hash }, { loaders, user }) => {
authRequired(user)
return r.table('invite').filter({"hash": hash})
Expand Down

0 comments on commit bb9174b

Please sign in to comment.