Skip to content

Commit 5d9f461

Browse files
authored
Reordered depedencies for tests (#883)
* feat: upgraded puppeteer package to latest * feat: refactored dependencies from bi-directional to uni-directional * fix: removed individual installation of package as workaround * fix: trying something out of shear desperation * fix: reverted line in package-lock.json * fix: trying to do without the extra "npm install" for consistency * fix: removed the "--production" option
1 parent 3c9d8b2 commit 5d9f461

File tree

7 files changed

+198
-190
lines changed

7 files changed

+198
-190
lines changed

Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ USER node:node
99
WORKDIR /src
1010
COPY --chown=node:node . .
1111

12-
# Workaround https://github.com/CyCoreSystems/go-meteor/issues/6
13-
RUN meteor npm install --save postcss-easy-import
14-
15-
RUN meteor npm install --production
12+
RUN meteor npm install
1613
RUN meteor build --architecture os.linux.x86_64 --directory /bundle
1714
RUN cd /bundle/bundle/programs/server && npm install
1815

imports/api/rest/put-pending-invitations.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import { invite } from '../../util/email-invite'
33
import { Meteor } from 'meteor/meteor'
44

55
import { reloadCaseFields } from '../cases'
6-
import UnitRolesData from '../unit-roles-data'
6+
import UnitRolesData, { defaultRoleVisibility } from '../unit-roles-data'
77
import { logger } from '../../util/logger'
8-
import { defaultRoleVisibility } from '../units'
98

109
export default (req, res) => {
1110
if (req.query.accessToken !== process.env.API_ACCESS_TOKEN) {

imports/api/unit-roles-data.js

Lines changed: 133 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ import { check } from 'meteor/check'
66
import { HTTP } from 'meteor/http'
77
import { Random } from 'meteor/random'
88
import randToken from 'rand-token'
9-
import { addUserToRole, defaultRoleVisibility } from './units'
109
import { findOrCreateUser } from './custom-users'
1110
import UnitMetaData from './unit-meta-data'
12-
import PendingInvitations, { KEEP_DEFAULT, REMOVE_USER, REPLACE_DEFAULT, collectionName as pendingInvitaitonsCollName } from './pending-invitations'
11+
import PendingInvitations, {
12+
KEEP_DEFAULT,
13+
REMOVE_USER,
14+
REPLACE_DEFAULT,
15+
collectionName as pendingInvitationsCollName
16+
} from './pending-invitations'
1317
import unitUserInvitedTemplate from '../email-templates/unit-user-invited'
1418
import { logger } from '../util/logger'
1519
import { getIncrementFor } from './increment-counters'
@@ -42,6 +46,23 @@ export const possibleRoles = [
4246
}
4347
]
4448

49+
export const defaultRoleVisibility = {
50+
[roleEnum.TENANT]: true,
51+
[roleEnum.OWNER_LANDLORD]: true,
52+
[roleEnum.CONTRACTOR]: true,
53+
[roleEnum.MGT_COMPANY]: true,
54+
[roleEnum.AGENT]: true,
55+
'Occupant': true
56+
}
57+
58+
export const roleSortOrder = [
59+
roleEnum.TENANT,
60+
roleEnum.OWNER_LANDLORD,
61+
roleEnum.AGENT,
62+
roleEnum.MGT_COMPANY,
63+
roleEnum.CONTRACTOR
64+
]
65+
4566
const UnitRolesData = new Mongo.Collection(collectionName)
4667

4768
const roleDocMemberMatcher = memberId => roleDoc => roleDoc.members.find(member => member.id === memberId)
@@ -77,6 +98,115 @@ export function inviteUserToRole (invitorId, unitMongoId, inviteeUser, roleType,
7798
return { accessToken }
7899
}
79100

101+
export const addUserToRole = (
102+
invitingUser, inviteeUser, unitBzId, role, invType, isOccupant, errorLogParams = {}, doLiveUpdate, isVisible = true,
103+
isDefaultInvited = true, roleVisibility = defaultRoleVisibility
104+
) => {
105+
// Filling up role visibility in case some of it is missing
106+
roleVisibility = Object.assign({}, defaultRoleVisibility, roleVisibility)
107+
108+
// Creating matching invitation records
109+
const invitationObj = {
110+
invitedBy: invitingUser.bugzillaCreds.id,
111+
invitee: inviteeUser.bugzillaCreds.id,
112+
mefeInvitationIdIntValue: getIncrementFor(pendingInvitationsCollName),
113+
type: invType,
114+
unitId: unitBzId,
115+
role,
116+
isOccupant
117+
}
118+
119+
// TODO: Once all dependencies of role resolving are moved from invitations to UnitRolesData, remove this
120+
// Creating the invitation as pending first
121+
const invitationId = PendingInvitations.insert(invitationObj)
122+
123+
// Linking invitation to user
124+
Meteor.users.update(inviteeUser._id, {
125+
$push: {
126+
receivedInvites: {
127+
unitId: invitationObj.unitId,
128+
invitedBy: invitingUser._id,
129+
timestamp: Date.now(),
130+
type: invitationObj.type,
131+
invitationId,
132+
role,
133+
isOccupant
134+
}
135+
}
136+
})
137+
138+
// Adding to the user to a role on BZ using lambda
139+
try {
140+
HTTP.call('POST', process.env.INVITE_LAMBDA_URL, {
141+
data: [Object.assign({ _id: invitationId }, invitationObj)],
142+
headers: {
143+
Authorization: `Bearer ${process.env.API_ACCESS_TOKEN}`
144+
}
145+
})
146+
} catch (e) {
147+
logger.error({
148+
...errorLogParams,
149+
step: 'INVITE lambda request, unit cleanup might be necessary',
150+
error: e
151+
})
152+
throw new Meteor.Error('Invite API Lambda error', e, { lambdaStatusCode: e.response.statusCode })
153+
}
154+
155+
// Marking the pending invitation as "done", now that the API responded with success
156+
PendingInvitations.update({ _id: invitationId }, {
157+
$set: {
158+
done: true
159+
}
160+
})
161+
Meteor.users.update({
162+
_id: inviteeUser._id,
163+
'receivedInvites.invitationId': invitationId
164+
}, {
165+
$set: {
166+
'receivedInvites.$.done': true
167+
}
168+
})
169+
170+
// Updating the roles collection to sync with BZ's state
171+
const unitRoleQuery = {
172+
roleType: role,
173+
unitBzId
174+
}
175+
176+
const unitRoleModifier = {
177+
$push: {
178+
members: {
179+
id: inviteeUser._id,
180+
isVisible,
181+
isDefaultInvited,
182+
isOccupant,
183+
roleVisibility
184+
}
185+
}
186+
}
187+
188+
UnitRolesData.update(unitRoleQuery, unitRoleModifier)
189+
190+
// Matching the role if the defaultAssigneeId is not defined and sets it to the current user. Does nothing otherwise
191+
let doForceAssigneeUpdate
192+
switch (invType) {
193+
case REPLACE_DEFAULT:
194+
doForceAssigneeUpdate = true
195+
break
196+
default:
197+
doForceAssigneeUpdate = false
198+
}
199+
const assigneeUpdateQuery = doForceAssigneeUpdate ? unitRoleQuery : {
200+
defaultAssigneeId: -1,
201+
...unitRoleQuery
202+
}
203+
UnitRolesData.update(assigneeUpdateQuery, {
204+
$set: {
205+
defaultAssigneeId: inviteeUser._id
206+
}
207+
})
208+
}
209+
80210
export function removeRoleMember (requestorId, unitBzId, email, errorLogParams) {
81211
const unitMeta = UnitMetaData.findOne({ bzId: unitBzId })
82212
const unitRoles = UnitRolesData.find({ unitBzId }).fetch()
@@ -102,7 +232,7 @@ export function removeRoleMember (requestorId, unitBzId, email, errorLogParams)
102232
const invitationObj = {
103233
invitedBy: requestorUser.bugzillaCreds.id,
104234
invitee: userToRemove.bugzillaCreds.id,
105-
mefeInvitationIdIntValue: getIncrementFor(pendingInvitaitonsCollName),
235+
mefeInvitationIdIntValue: getIncrementFor(pendingInvitationsCollName),
106236
type: REMOVE_USER,
107237
unitId: unitBzId,
108238
role: toRemoveRole.roleType,

imports/api/units.js

Lines changed: 7 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ import _ from 'lodash'
77
import publicationFactory from './base/rest-resource-factory'
88
import { makeAssociationFactory, withUsers, withDocs } from './base/associations-helper'
99
import UnitMetaData, { unitTypes, collectionName as unitMetaCollName } from './unit-meta-data'
10-
import UnitRolesData, { possibleRoles, roleEnum, collectionName as unitRolesCollName } from './unit-roles-data'
11-
import PendingInvitations, { REPLACE_DEFAULT, collectionName as pendingInvitationsCollName } from './pending-invitations'
10+
import UnitRolesData, {
11+
possibleRoles,
12+
roleSortOrder,
13+
addUserToRole,
14+
collectionName as unitRolesCollName
15+
} from './unit-roles-data'
16+
import { REPLACE_DEFAULT } from './pending-invitations'
1217
import { callAPI } from '../util/bugzilla-api'
1318
import { logger } from '../util/logger'
1419
import FailedUnitCreations from './failed-unit-creations'
@@ -25,23 +30,6 @@ export const factoryOptions = {
2530

2631
export let serverHelpers
2732

28-
export const defaultRoleVisibility = {
29-
[roleEnum.TENANT]: true,
30-
[roleEnum.OWNER_LANDLORD]: true,
31-
[roleEnum.CONTRACTOR]: true,
32-
[roleEnum.MGT_COMPANY]: true,
33-
[roleEnum.AGENT]: true,
34-
'Occupant': true
35-
}
36-
37-
const roleSortOrder = [
38-
roleEnum.TENANT,
39-
roleEnum.OWNER_LANDLORD,
40-
roleEnum.AGENT,
41-
roleEnum.MGT_COMPANY,
42-
roleEnum.CONTRACTOR
43-
]
44-
4533
if (Meteor.isServer) {
4634
serverHelpers = {
4735
getAPIUnitByName (unitName, apiKey) {
@@ -192,129 +180,6 @@ export const getUnitRoles = (unit, userId) => {
192180
)
193181
}
194182

195-
export const addUserToRole = (
196-
invitingUser, inviteeUser, unitBzId, role, invType, isOccupant, errorLogParams = {}, doLiveUpdate, isVisible = true,
197-
isDefaultInvited = true, roleVisibility = defaultRoleVisibility
198-
) => {
199-
// Filling up role visibility in case some of it is missing
200-
roleVisibility = Object.assign({}, defaultRoleVisibility, roleVisibility)
201-
202-
// Creating matching invitation records
203-
const invitationObj = {
204-
invitedBy: invitingUser.bugzillaCreds.id,
205-
invitee: inviteeUser.bugzillaCreds.id,
206-
mefeInvitationIdIntValue: getIncrementFor(pendingInvitationsCollName),
207-
type: invType,
208-
unitId: unitBzId,
209-
role,
210-
isOccupant
211-
}
212-
213-
// TODO: Once all dependencies of role resolving are moved from invitations to UnitRolesData, remove this
214-
// Creating the invitation as pending first
215-
const invitationId = PendingInvitations.insert(invitationObj)
216-
217-
// Linking invitation to user
218-
Meteor.users.update(inviteeUser._id, {
219-
$push: {
220-
receivedInvites: {
221-
unitId: invitationObj.unitId,
222-
invitedBy: invitingUser._id,
223-
timestamp: Date.now(),
224-
type: invitationObj.type,
225-
invitationId,
226-
role,
227-
isOccupant
228-
}
229-
}
230-
})
231-
232-
// Adding to the user to a role on BZ using lambda
233-
try {
234-
HTTP.call('POST', process.env.INVITE_LAMBDA_URL, {
235-
data: [Object.assign({ _id: invitationId }, invitationObj)],
236-
headers: {
237-
Authorization: `Bearer ${process.env.API_ACCESS_TOKEN}`
238-
}
239-
})
240-
} catch (e) {
241-
logger.error({
242-
...errorLogParams,
243-
step: 'INVITE lambda request, unit cleanup might be necessary',
244-
error: e
245-
})
246-
throw new Meteor.Error('Invite API Lambda error', e, { lambdaStatusCode: e.response.statusCode })
247-
}
248-
249-
// Marking the pending invitation as "done", now that the API responded with success
250-
PendingInvitations.update({ _id: invitationId }, {
251-
$set: {
252-
done: true
253-
}
254-
})
255-
Meteor.users.update({
256-
_id: inviteeUser._id,
257-
'receivedInvites.invitationId': invitationId
258-
}, {
259-
$set: {
260-
'receivedInvites.$.done': true
261-
}
262-
})
263-
264-
// Updating the roles collection to sync with BZ's state
265-
const unitRoleQuery = {
266-
roleType: role,
267-
unitBzId
268-
}
269-
270-
const unitRoleModifier = {
271-
$push: {
272-
members: {
273-
id: inviteeUser._id,
274-
isVisible,
275-
isDefaultInvited,
276-
isOccupant,
277-
roleVisibility
278-
}
279-
}
280-
}
281-
282-
UnitRolesData.update(unitRoleQuery, unitRoleModifier)
283-
284-
// Matching the role if the defaultAssigneeId is not defined and sets it to the current user. Does nothing otherwise
285-
let doForceAssigneeUpdate
286-
switch (invType) {
287-
case REPLACE_DEFAULT:
288-
doForceAssigneeUpdate = true
289-
break
290-
default:
291-
doForceAssigneeUpdate = false
292-
}
293-
const assigneeUpdateQuery = doForceAssigneeUpdate ? unitRoleQuery : {
294-
defaultAssigneeId: -1,
295-
...unitRoleQuery
296-
}
297-
UnitRolesData.update(assigneeUpdateQuery, {
298-
$set: {
299-
defaultAssigneeId: inviteeUser._id
300-
}
301-
})
302-
303-
if (doLiveUpdate) {
304-
try {
305-
const response = callAPI('get', `/rest/product?ids=${unitBzId}`, {}, true, true)
306-
const unitItem = factoryOptions.dataResolver(response.data)[0]
307-
pubObj.handleChanged(unitItem, ['components'])
308-
} catch (e) {
309-
logger.error({
310-
...errorLogParams,
311-
step: 'Fetching unit info for live update after invite, proceeding with no error',
312-
error: e
313-
})
314-
}
315-
}
316-
}
317-
318183
const rolesProjByOwnership = (userId, unitItem) => {
319184
return {
320185
unitId: 1,

imports/migrations/13_add_role_visibility_to_all_members.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Migrations } from 'meteor/percolate:migrations'
2-
import UnitRolesData from '../api/unit-roles-data'
3-
import { defaultRoleVisibility } from '../api/units'
2+
import UnitRolesData, { defaultRoleVisibility } from '../api/unit-roles-data'
43

54
Migrations.add({
65
version: 13,

0 commit comments

Comments
 (0)