Skip to content

Commit 18fe639

Browse files
authored
fix(SIte Users): 502 errors for member of lots of organisations (LLC-34) (#1513)
1 parent 6a8e084 commit 18fe639

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

Diff for: lib/models/plugins/addCRUDFunctions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ async function getConnection({
181181
query.where(cursorFilter);
182182
} else if (before) {
183183
const cursorFilter = paginationToFilter({
184-
cursor: after,
184+
cursor: before,
185185
sort,
186186
paginationDirection: direction
187187
});

Diff for: ui/src/pages/SiteUsersPage/SiteUserOrgItems.js

+35-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { Map } from 'immutable';
4-
import { compose, withProps, setPropTypes } from 'recompose';
4+
import { compose, setPropTypes, withProps } from 'recompose';
55
import { withModels } from 'ui/utils/hocs';
66
import SiteUserOrgItem from './SiteUserOrgItem';
77

@@ -11,12 +11,12 @@ const enhance = compose(
1111
}),
1212
withProps(({ user }) => {
1313
const schema = 'organisation';
14-
const organisations = user
15-
.get('organisations')
16-
.map(org => new Map({ $oid: org }));
14+
const organisations = user.get('organisations').map(org => new Map({ $oid: org }));
15+
// Decision made via (https://github.com/LearningLocker/learninglocker/pull/1513#issuecomment-587064642)
16+
// Need to change when we will have OrganisationUser model.
1717
const filter = new Map({
1818
_id: new Map({
19-
$in: organisations
19+
$in: organisations.slice(0, 10)
2020
})
2121
});
2222

@@ -25,11 +25,37 @@ const enhance = compose(
2525
withModels
2626
);
2727

28-
const SiteUserOrgItems = ({ models, user }) => {
29-
const orgsItems = models
30-
.map(org => <SiteUserOrgItem key={org.get('_id').toString()} org={org} user={user} />)
28+
const SiteUserOrgItems = ({ models, user, filter }) => {
29+
// Decision made via (https://github.com/LearningLocker/learninglocker/pull/1513#issuecomment-587064642)
30+
// Need to change when we will have OrganisationUser model.
31+
const orgItems = filter
32+
.get('_id')
33+
.get('$in')
34+
.map((org) => {
35+
const orgModel = models.find(model =>
36+
model.get('_id').toString() === org.get('$oid').toString()
37+
);
38+
39+
if (orgModel === undefined) {
40+
return (
41+
<li key={org.get('$oid').toString()}>
42+
Sorry organisation with id {org.get('$oid')} was deleted!
43+
</li>
44+
);
45+
}
46+
47+
return <SiteUserOrgItem key={orgModel.get('_id').toString()} org={orgModel} user={user} />;
48+
})
3149
.valueSeq();
32-
return <ul>{orgsItems}</ul>;
50+
51+
const countOfRemainingOrganisations = user.get('organisations').count() - orgItems.count();
52+
53+
return (
54+
<div>
55+
<ul>{orgItems}</ul>
56+
{countOfRemainingOrganisations > 0 && <p>Plus { countOfRemainingOrganisations } more not displayed</p>}
57+
</div>
58+
);
3359
};
3460

3561
export default enhance(SiteUserOrgItems);

0 commit comments

Comments
 (0)