Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8d25189
initial commit
ryanslatten Jul 28, 2025
7c638b1
added tests
ryanslatten Jul 29, 2025
3274b50
update tests and rename component
ryanslatten Jul 29, 2025
3c5b375
remove unnecessary reset
ryanslatten Jul 29, 2025
a161f58
fix details routing
ryanslatten Jul 29, 2025
7aa7c50
initial commit
ryanslatten Jul 29, 2025
3836551
Merge branch 'teams-component-upgrade' of https://github.com/ngageoin…
ryanslatten Jul 29, 2025
9a5a118
move navbar component into general component
ryanslatten Jul 31, 2025
b4a6f05
add docstrings
ryanslatten Jul 31, 2025
71ba58d
fix test
ryanslatten Jul 31, 2025
462fb8d
initial commit
ryanslatten Jul 31, 2025
b5acf00
Merge branch 'teams-component-upgrade' of https://github.com/ngageoin…
ryanslatten Jul 31, 2025
91ff66b
store
ryanslatten Aug 5, 2025
83dae53
Merge branch 'develop' of https://github.com/ngageoint/mage-server in…
ryanslatten Aug 5, 2025
cc1b2ef
store
ryanslatten Aug 7, 2025
c79524d
lots of changes
ryanslatten Aug 11, 2025
43911e4
Merge branch 'develop' of https://github.com/ngageoint/mage-server in…
ryanslatten Aug 11, 2025
689f53c
add events service and unit tests
ryanslatten Aug 12, 2025
e8b3497
fix card navbar
ryanslatten Aug 12, 2025
18163fd
fix css
ryanslatten Aug 12, 2025
b1647d4
fix test cases
ryanslatten Aug 12, 2025
ac427b0
Add team access and fix css
ryanslatten Aug 13, 2025
549d9af
initial commit
ryanslatten Aug 23, 2025
80cab20
Merge branch 'develop' of https://github.com/ngageoint/mage-server in…
ryanslatten Aug 23, 2025
ae7199f
add delete user modal and unit tests
ryanslatten Aug 25, 2025
d3743fc
cleanup css and comments
ryanslatten Aug 25, 2025
bfc8b92
allow avatar to be uploaded
ryanslatten Aug 25, 2025
634a70b
clean up ng1
ryanslatten Aug 25, 2025
56f5d5c
fix issues from comments
ryanslatten Sep 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion service/src/models/event.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export type Callback<Result = unknown> = (err: Error | null, result?: Result, to
export declare function count(options: TODO, callback: Callback<number>): void
export declare function getEvents(options: TODO, callback: Callback<MageEventDocument[]>): void
export declare function getById(id: MageEventId, options: TODO, callback: Callback<MageEventDocument | null>): void
export declare function filterEventsByUserId(events: MageEventDocument[], userId: string, callback: Callback<MageEventDocument[]>): void
export declare function create(event: MageEventCreateAttrs, user: Partial<UserDocument> & Pick<UserDocument, '_id'>, callback: Callback<MageEventDocument>): void
export declare function addForm(eventId: MageEventId, form: any, callback: Callback<MageEventDocument>): void
export declare function addLayer(event: MageEventDocument, layer: any, callback: Callback<MageEventDocument>): void
Expand Down
85 changes: 47 additions & 38 deletions service/src/models/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ exports.count = function (options, callback) {
conditions['$or'] = accesses;
}

Event.count(conditions, function (err, count) {
Event.countDocuments(conditions, function (err, count) {
callback(err, count);
});
};
Expand Down Expand Up @@ -354,48 +354,57 @@ exports.getEvents = async function (options, callback) {
projection.teamIds = true;
}

const totalCount = await Event.count(query).exec();
try {
const andClauses = [];

Event.find(query, projection, function (err, events) {
if (err) return callback(err);
const buildAccessClause = async (userId) => {
if (!userId) return null;

const filters = [];
const teamDocs = await Team.TeamModel.find({ userIds: { $in: [userId] } }, { _id: 1 }).lean();
const teamIdsForUser = teamDocs.map(t => t._id);
const readRoles = rolesWithPermission('read');
const aclKey = `acl.${userId.toString()}`;
return {
$or: [
{ teamIds: { $in: teamIdsForUser } },
{ [aclKey]: { $in: readRoles } }
]
};
};

// First filter out events user cannot access
if (options.access && options.access.user) {
filters.push(function (done) {
filterEventsByUserId(events, options.access.user._id, function (err, filteredEvents) {
if (err) return done(err);
const accessUserId = options && options.access && options.access.user ? options.access.user._id : null;
const filterUserId = filter && filter.userId ? filter.userId : null;

events = filteredEvents;
done();
});
});
const [accessClause, filterClause] = await Promise.all([
buildAccessClause(accessUserId),
buildAccessClause(filterUserId)
]);

if (accessClause) andClauses.push(accessClause);
if (filterClause) andClauses.push(filterClause);
if (andClauses.length) {
if (query.$and) {
query.$and = query.$and.concat(andClauses);
} else {
query.$and = andClauses;
}
}
} catch (err) {
return callback(err);
}

// Filter again if filtering based on particular user
if (options.filter && options.filter.userId) {
filters.push(function (done) {
filterEventsByUserId(events, options.filter.userId, function (err, filteredEvents) {
if (err) return done(err);
const totalCount = await Event.countDocuments(query).exec();

events = filteredEvents;
done();
});
Event.find(query, projection, (err, events) => {
if (err) return callback(err);

if (options.populate) {
Event.populate(events, [{ path: 'teamIds' }, { path: 'layerIds' }], function (err, events) {
callback(err, events, totalCount);
});
} else {
callback(null, events, totalCount);
}

async.series(filters, function (err) {
if (err) return callback(err);

if (options.populate) {
Event.populate(events, [{ path: 'teamIds' }, { path: 'layerIds' }], function (err, events) {
callback(err, events, totalCount);
});
} else {
callback(null, events, totalCount);
}
});
})
.sort({ name: 1, _id: 1 })
.limit(options.limit || 1000)
Expand Down Expand Up @@ -625,7 +634,7 @@ exports.getMembers = async function (eventId, options) {

const includeTotalCount = typeof options.includeTotalCount === 'boolean' ? options.includeTotalCount : options.pageIndex === 0
if (includeTotalCount) {
page.totalCount = await User.Model.count(params);
page.totalCount = await User.Model.countDocuments(params);
}

return page;
Expand Down Expand Up @@ -683,7 +692,7 @@ exports.getNonMembers = async function (eventId, options) {

const includeTotalCount = typeof options.includeTotalCount === 'boolean' ? options.includeTotalCount : options.pageIndex === 0
if (includeTotalCount) {
page.totalCount = await User.Model.count(params);
page.totalCount = await User.Model.countDocuments(params);
}

return page;
Expand Down Expand Up @@ -728,7 +737,7 @@ exports.getTeamsInEvent = async function (eventId, options) {
};
const includeTotalCount = typeof options.includeTotalCount === 'boolean' ? options.includeTotalCount : options.pageIndex === 0
if (includeTotalCount) {
page.totalCount = await Team.TeamModel.count(params);
page.totalCount = await Team.TeamModel.countDocuments(params);
}
return page;
};
Expand Down Expand Up @@ -766,7 +775,7 @@ exports.getTeamsNotInEvent = async function (eventId, options) {

const includeTotalCount = typeof options.includeTotalCount === 'boolean' ? options.includeTotalCount : options.pageIndex === 0
if (includeTotalCount) {
page.totalCount = await Team.TeamModel.count(params);
page.totalCount = await Team.TeamModel.countDocuments(params);
}

return page;
Expand Down
5 changes: 3 additions & 2 deletions service/src/routes/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ function EventRoutes(app: express.Application, security: { authentication: authe
complete: req.parameters!.complete,
teamId: req.query.teamId as string | undefined,
excludeTeamId: req.query.excludeTeamId as string | undefined,
searchTerm: req.query.term as string | undefined
} as any
searchTerm: req.query.term as string | undefined,
userId: req.query.userId as string | undefined
};
if (req.parameters!.userId) {
filter.userId = req.parameters!.userId
}
Expand Down
Loading