Skip to content

Commit 0841c55

Browse files
authored
Merge pull request #1983 from hackforla/ts.project-manager-list
Ts.project manager list
2 parents ad308aa + 4f3bd8f commit 0841c55

File tree

3 files changed

+234
-200
lines changed

3 files changed

+234
-200
lines changed

backend/controllers/user.controller.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ UserController.user_list = async function (req, res) {
2222
const user = await User.find(query);
2323
return res.status(200).send(user);
2424
} catch (err) {
25-
console.log(err);
25+
console.error(err);
2626
return res.sendStatus(400);
2727
}
2828
};
@@ -39,7 +39,7 @@ UserController.admin_list = async function (req, res) {
3939
const admins = await User.find({ accessLevel: { $in: ['admin', 'superadmin'] } });
4040
return res.status(200).send(admins);
4141
} catch (err) {
42-
console.log(err);
42+
console.error(err);
4343
return res.sendStatus(400);
4444
}
4545
};
@@ -53,17 +53,24 @@ UserController.projectManager_list = async function (req, res) {
5353

5454
try {
5555
const projectManagers = await User.find({
56-
$and: [
57-
{ accessLevel: { $in: ['admin', 'superadmin'] } },
58-
{ managedProjects: { $exists: true, $type: 'array', $ne: [] } },
59-
],
56+
managedProjects: { $exists: true, $type: 'array', $ne: [] },
6057
});
6158

6259
// Collect all unique project IDs
63-
const allProjectIds = [...new Set(projectManagers.flatMap((pm) => pm.managedProjects))];
60+
const allProjectIds = [
61+
...new Set(
62+
projectManagers
63+
.flatMap((pm) => pm.managedProjects)
64+
.filter((id) => typeof id === 'string' && id.match(/^[a-f\d]{24}$/i)),
65+
),
66+
];
6467

6568
// Fetch all projects in one query
66-
const projects = await Project.find({ _id: { $in: allProjectIds } });
69+
const projects = await Project.find(
70+
{ _id: { $in: allProjectIds } },
71+
{ _id: 1, name: 1 }, // projection
72+
);
73+
6774
const projectIdToName = {};
6875
for (const project of projects) {
6976
projectIdToName[project._id.toString()] = project.name;
@@ -80,7 +87,8 @@ UserController.projectManager_list = async function (req, res) {
8087

8188
return res.status(200).send(updatedProjectManagers);
8289
} catch (err) {
83-
console.log(err);
90+
console.error(err);
91+
console.log('Projectlead error', err);
8492
return res.sendStatus(400);
8593
}
8694
};
@@ -100,7 +108,7 @@ UserController.user_by_id = async function (req, res) {
100108
// and look downstream to see whether 404 would break anything
101109
return res.status(200).send(user);
102110
} catch (err) {
103-
console.log(err);
111+
console.error(err);
104112
return res.sendStatus(400);
105113
}
106114
};
@@ -144,7 +152,7 @@ UserController.update = async function (req, res) {
144152
const user = await User.findOneAndUpdate({ _id: UserId }, req.body, { new: true });
145153
return res.status(200).send(user);
146154
} catch (err) {
147-
console.log(err);
155+
console.error(err);
148156
return res.sendStatus(400);
149157
}
150158
};
@@ -162,7 +170,7 @@ UserController.delete = async function (req, res) {
162170
const user = await User.findByIdAndDelete(UserId);
163171
return res.status(200).send(user);
164172
} catch (err) {
165-
console.log(err);
173+
console.error(err);
166174
return res.sendStatus(400);
167175
}
168176
};
@@ -232,7 +240,6 @@ UserController.signin = function (req, res) {
232240
};
233241

234242
UserController.verifySignIn = async function (req, res) {
235-
236243
let token = req.headers['x-access-token'] || req.headers['authorization'];
237244
if (token.startsWith('Bearer ')) {
238245
// Remove Bearer from string
@@ -245,7 +252,7 @@ UserController.verifySignIn = async function (req, res) {
245252
res.cookie('token', token, { httpOnly: true });
246253
return res.send(user);
247254
} catch (err) {
248-
console.log(err);
255+
console.error(err);
249256
return res.status(403);
250257
}
251258
};

client/src/components/user-admin/UserPermissionSearch.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ const UserPermissionSearch = ({ admins, projectLeads, setUserToEdit }) => {
246246
variant={isProjectLead ? 'contained' : 'secondary'}
247247
onClick={buttonSwap}
248248
>
249-
Project Leads
249+
Project Members
250250
</Button>
251251
</ButtonGroup>
252252
</Box>

0 commit comments

Comments
 (0)