Skip to content

Commit 233deac

Browse files
committed
fix: remove gitAccount and fix authorise push route conflicts
fix: return on /create-user fix: cast res,data to Boolean in ldaHelper
1 parent bd7cb33 commit 233deac

File tree

3 files changed

+35
-34
lines changed

3 files changed

+35
-34
lines changed

src/service/passport/ldaphelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const isUserInAdGroupViaHttp = (id: string, domain: string, name: string): Promi
5757
console.log(`checking if user is in group ${url}`);
5858
return client
5959
.get(url)
60-
.then((res) => res.data)
60+
.then((res) => Boolean(res.data))
6161
.catch(() => {
6262
return false;
6363
});

src/service/routes/auth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ router.post('/create-user', async (req: Request, res: Response) => {
216216
res.status(400).send({
217217
message: 'Missing required fields: username, password, email, and gitAccount are required',
218218
});
219+
return;
219220
}
220221

221222
await db.createUser(username, password, email, gitAccount, isAdmin);

src/service/routes/push.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ router.post('/:id/authorise', async (req: Request, res: Response) => {
9999

100100
const { username } = req.user as { username: string };
101101

102-
const push = await getValidPushOrRespond(id, res);
103-
if (!push) return;
102+
// Get the push request
103+
const push = await db.getPush(id);
104+
console.log({ push });
104105

105106
// Get the committer of the push via their email address
106-
const committerEmail = push.userEmail;
107+
const committerEmail = push?.userEmail;
107108
const list = await db.getUsers({ email: committerEmail });
108109
console.log({ list });
109110

@@ -121,40 +122,39 @@ router.post('/:id/authorise', async (req: Request, res: Response) => {
121122
return;
122123
}
123124

124-
// If we are not the author, now check that we are allowed to authorise on this repo
125+
// If we are not the author, now check that we are allowed to authorise on this
126+
// repo
125127
const isAllowed = await db.canUserApproveRejectPush(id, username);
126-
if (!isAllowed) {
128+
if (isAllowed) {
129+
console.log(`user ${username} approved push request for ${id}`);
130+
131+
const reviewerList = await db.getUsers({ username });
132+
console.log({ reviewerList });
133+
134+
const reviewerGitAccount = reviewerList[0].gitAccount;
135+
console.log({ reviewerGitAccount });
136+
137+
if (!reviewerGitAccount) {
138+
res.status(401).send({
139+
message: 'You must associate a GitHub account with your user before approving...',
140+
});
141+
return;
142+
}
143+
144+
const attestation = {
145+
questions,
146+
timestamp: new Date(),
147+
reviewer: {
148+
username,
149+
},
150+
};
151+
const result = await db.authorise(id, attestation);
152+
res.send(result);
153+
} else {
127154
res.status(401).send({
128-
message: 'User is not authorised to authorise changes',
155+
message: `user ${username} not authorised to approve push's on this project`,
129156
});
130-
return;
131157
}
132-
133-
console.log(`user ${username} approved push request for ${id}`);
134-
135-
const reviewerList = await db.getUsers({ username });
136-
console.log({ reviewerList });
137-
138-
const reviewerGitAccount = reviewerList[0].gitAccount;
139-
console.log({ reviewerGitAccount });
140-
141-
if (!reviewerGitAccount) {
142-
res.status(401).send({
143-
message: 'You must associate a GitHub account with your user before approving...',
144-
});
145-
return;
146-
}
147-
148-
const attestation = {
149-
questions,
150-
timestamp: new Date(),
151-
reviewer: {
152-
username,
153-
gitAccount: reviewerGitAccount,
154-
},
155-
};
156-
const result = await db.authorise(id, attestation);
157-
res.send(result);
158158
} else {
159159
res.status(401).send({
160160
message: 'You are unauthorized to perform this action...',

0 commit comments

Comments
 (0)