Skip to content

Commit

Permalink
Merge pull request #763 from ParabolInc/epic2-hotfix-2-28
Browse files Browse the repository at this point in the history
fix #751
fix #753
fix #754
fix #755
fix #757
  • Loading branch information
mattkrick authored Feb 28, 2017
2 parents 0b81eda + fbc6983 commit 84ffbe5
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 21 deletions.
27 changes: 27 additions & 0 deletions src/server/graphql/models/Action/actionQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import getRethink from 'server/database/rethinkDriver';
import {GraphQLNonNull, GraphQLID, GraphQLInt} from 'graphql';
import {requireSUOrSelf} from 'server/utils/authorization';

export default {
actionCount: {
type: GraphQLInt,
args: {
userId: {
type: new GraphQLNonNull(GraphQLID),
description: 'userId that owns all the actions'
}
},
async resolve(source, {userId}, {authToken}) {
const r = getRethink();

// AUTH
requireSUOrSelf(authToken, userId);

// RESOLUTION
return await r.table('Action')
.getAll(userId, {index: 'userId'})
.filter({isComplete: false})
.count();
}
}
};
5 changes: 5 additions & 0 deletions src/server/graphql/models/Action/actionSubscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ export default {
},
async resolve(source, {userId}, {authToken, socket, subbedChannelName}, refs) {
const r = getRethink();

// AUTH
requireSUOrSelf(authToken, userId);


// RESOLUTION
const requestedFields = getRequestedFields(refs);
const changefeedHandler = makeChangefeedHandler(socket, subbedChannelName);
r.table('Action')
Expand Down
4 changes: 3 additions & 1 deletion src/server/graphql/models/Invoice/invoiceQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ export default {
// RESOLUTION

if (after) {
const dbAfter = after === 0 ? r.minval : after;
return r.table('Invoice')
.between([orgId, after], [orgId, r.maxval], {index: 'orgIdStartAt', leftBound: 'open'})
.between([orgId, dbAfter], [orgId, r.maxval], {index: 'orgIdStartAt', leftBound: 'open'})
.orderBy(r.desc('startAt'))
.limit(first)
.merge((doc) => ({
Expand All @@ -97,6 +98,7 @@ export default {
const upcomingInvoice = {
id: `upcoming_${orgId}`,
amountDue: stripeInvoice.amount_due,
cursor: 0,
total: stripeInvoice.total,
endAt: fromEpochSeconds(stripeInvoice.period_end),
invoiceDate: fromEpochSeconds(stripeInvoice.date),
Expand Down
24 changes: 22 additions & 2 deletions src/server/graphql/models/Organization/organizationQuery.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
import getRethink from 'server/database/rethinkDriver';
import {GraphQLNonNull, GraphQLID} from 'graphql';
import {GraphQLNonNull, GraphQLID, GraphQLInt} from 'graphql';
import {Organization} from './organizationSchema';
import {requireSUOrTeamMember} from 'server/utils/authorization';
import {requireSUOrTeamMember, requireSUOrSelf} from 'server/utils/authorization';

export default {
orgCount: {
type: GraphQLInt,
args: {
userId: {
type: new GraphQLNonNull(GraphQLID),
description: 'the user ID that belongs to all the orgs'
}
},
async resolve(source, {userId}, {authToken}) {
const r = getRethink();

// AUTH
requireSUOrSelf(authToken, userId);

// RESOLUTION
return await r.table('Organization')
.getAll(userId, {index: 'orgUsers'})
.count();
}
},
orgDetails: {
type: Organization,
args: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default {
const r = getRethink();

// AUTH
await requireSUOrSelf(authToken, userId);
requireSUOrSelf(authToken, userId);

// RESOLUTION
const requestedFields = getRequestedFields(refs);
Expand Down
2 changes: 2 additions & 0 deletions src/server/graphql/rootQuery.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {GraphQLObjectType} from 'graphql';
import action from './models/Action/actionQuery';
import invoice from './models/Invoice/invoiceQuery';
import meeting from './models/Meeting/meetingQuery';
import organization from './models/Organization/organizationQuery';
Expand All @@ -8,6 +9,7 @@ import team from './models/Team/teamQuery';
import user from './models/User/userQuery';

const rootFields = Object.assign({},
action,
invoice,
meeting,
organization,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import addOrgSchema from 'universal/validation/addOrgSchema';
import {segmentEventTrack} from 'universal/redux/segmentActions';
import {connect} from 'react-redux';
import NewTeamForm from 'universal/modules/newTeam/components/NewTeamForm/NewTeamForm';
import LoadingView from 'universal/components/LoadingView/LoadingView';


const orgDropdownMenuItemsQuery = `
query {
orgCount(userId: $userId)
organizations(userId: $userId) @live {
id
name
Expand All @@ -24,7 +23,7 @@ query {
const mapStateToProps = (state, props) => {
const {newOrgRoute} = props;
const userId = state.auth.obj.sub;
const {organizations} = cashay.query(orgDropdownMenuItemsQuery, {
const {orgCount, organizations} = cashay.query(orgDropdownMenuItemsQuery, {
op: 'newTeamFormContainer',
key: userId,
sort: {
Expand All @@ -37,6 +36,7 @@ const mapStateToProps = (state, props) => {
const defaultOrg = organizations[0];
const orgId = defaultOrg && defaultOrg.id;
return {
initialOrgCount: orgCount,
organizations,
initialValues: {
orgId
Expand Down Expand Up @@ -114,13 +114,15 @@ class NewTeamFormContainer extends Component {
};

render() {
const {isNewOrg, organizations} = this.props;
if (organizations.length === 0) {
// more than looks, this is required because initialValues can only be passed in once
return <LoadingView />;
const {initialOrgCount, initialValues, isNewOrg, organizations, router} = this.props;
if (initialOrgCount === 0) {
router.push('/newteam/1');
} else if (!initialValues.orgId) {
return null;
}
return (
<NewTeamForm
initialValues={initialValues}
isNewOrg={isNewOrg}
last4={this.state.last4}
onSubmit={this.onSubmit}
Expand All @@ -134,6 +136,8 @@ class NewTeamFormContainer extends Component {

NewTeamFormContainer.propTypes = {
dispatch: PropTypes.func.isRequired,
initialOrgCount: PropTypes.func.number,
initialValues: PropTypes.object,
isNewOrg: PropTypes.bool,
organizations: PropTypes.array,
router: PropTypes.object.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import appTheme from 'universal/styles/theme/appTheme';
const OrgBilling = (props) => {
const {
invoices,
invoicesReady,
styles,
org
} = props;
Expand Down Expand Up @@ -48,14 +49,21 @@ const OrgBilling = (props) => {
}
<Panel label="Invoices">
<div className={css(styles.listOfInvoices)}>
{invoices.length === 0 ?
{invoicesReady && invoices.length === 0 &&
<div className={css(styles.noInvoices)}>
No invoices yet! Keep doing good work, and we'll do the accounting.
</div> :
</div>
}
{invoicesReady && invoices.length > 0 &&
invoices.map((invoice, idx) =>
<InvoiceRow key={`invoiceRow${idx}`} invoice={invoice}/>
)
}
{!invoicesReady &&
<div className={css(styles.noInvoices)}>
Loading Invoices...
</div>
}
</div>
</Panel>
</div>
Expand All @@ -64,6 +72,7 @@ const OrgBilling = (props) => {

OrgBilling.propTypes = {
invoices: PropTypes.array,
invoicesReady: PropTypes.bool,
styles: PropTypes.object,
org: PropTypes.object
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const UserActionList = (props) => {
actions={actions}
dispatch={dispatch}
teams={teams}
actionCount={actionCount}
userId={userId}
/> :
<UserActionListHeader onAddNewAction={createNewAction}/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class CreditCardModalContainer extends Component {

checkCardType = (e) => {
const {stripeCard} = this.props;
if (e.currentTarget.value) {
if (stripeCard && e.currentTarget.value) {
const type = stripeCard.cardType(e.currentTarget.value);
const cardTypeIcon = cardTypeLookup[type];
if (cardTypeIcon !== this.state.cardTypeIcon) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,32 @@ query {

const mapStateToProps = (state, props) => {
const {orgId} = props;
const {organization: org, invoiceList} = cashay.query(organizationContainerQuery, {
const res = cashay.query(organizationContainerQuery, {
op: 'orgBillingContainer',
key: orgId,
variables: {
orgId,
first: 5
}
}).data;
});
const {data: {organization: org, invoiceList}, status} = res;
return {
invoiceList,
org
org,
invoicesReady: status === 'complete'
};
};

const OrgBillingContainer = (props) => {
const {dispatch, invoiceList, org} = props;
const {dispatch, invoiceList, invoicesReady, org} = props;
if (!org.id) {
return <LoadingView/>;
}
return (
<OrgBilling
dispatch={dispatch}
invoices={invoiceList}
invoicesReady={invoicesReady}
org={org}
/>
);
Expand All @@ -76,6 +79,7 @@ const OrgBillingContainer = (props) => {
OrgBillingContainer.propTypes = {
dispatch: PropTypes.func,
invoiceList: PropTypes.array,
invoicesReady: PropTypes.bool,
org: PropTypes.object
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import UserActionList from 'universal/modules/userDashboard/components/UserActio

const userActionListQuery = `
query {
actionCount(userId: $id)
actions(userId: $id) @live {
content
id
Expand Down Expand Up @@ -47,7 +48,7 @@ const mapStateToProps = (state) => {
const teamsFilterFn = teamFilterId ? (doc) => doc.id === teamFilterId : () => true;
const userId = state.auth.obj.sub;
const queryKey = teamFilterId || '';
const {actions, teams} = cashay.query(userActionListQuery, {
const {actionCount, actions, teams} = cashay.query(userActionListQuery, {
op: 'userActions',
variables: {id: userId},
key: queryKey,
Expand All @@ -66,6 +67,7 @@ const mapStateToProps = (state) => {
mutationHandlers
}).data;
return {
initialActionCount: actionCount,
actions,
teams,
userId: state.auth.obj.sub,
Expand All @@ -75,7 +77,10 @@ const mapStateToProps = (state) => {
};

const UserActionListContainer = (props) => {
const {actions, dispatch, queryKey, selectingNewActionTeam, teams, userId} = props;
const {initialActionCount, actions, dispatch, queryKey, selectingNewActionTeam, teams, userId} = props;
if (initialActionCount === null) {
return null;
}
return (
<UserActionList
actions={actions}
Expand All @@ -91,6 +96,7 @@ const UserActionListContainer = (props) => {
UserActionListContainer.propTypes = {
actions: PropTypes.array,
dispatch: PropTypes.func,
initialActionCount: PropTypes.number,
queryKey: PropTypes.string,
selectingNewActionTeam: PropTypes.bool,
teams: PropTypes.array,
Expand Down

0 comments on commit 84ffbe5

Please sign in to comment.