Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Temporary workaround for scrape slackrole issue #547

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 10 additions & 9 deletions src/support/slack/commands/run-scrape.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@ function RunScrapeCommand(context) {
* @returns {Promise} A promise that resolves when the operation is complete.
*/
const handleExecution = async (args, slackContext) => {
const { say, user } = slackContext;
const config = await dataAccess.getConfiguration();
const slackRoles = config.getSlackRoles() || {};
const admins = slackRoles?.scrape || [];

if (!admins.includes(user)) {
await say(':error: Only members of role "scrape" can run this command.');
return;
}
// const { say, user } = slackContext;
// const config = await dataAccess.getConfiguration();
// const slackRoles = config.getSlackRoles() || {};
// const admins = slackRoles?.scrape || [];

// if (!admins.includes(user)) {
// await say(':error: Only members of role "scrape" can run this command.');
// return;
// }

const { say } = slackContext;
try {
const [baseURLInput] = args;
const baseURL = extractURLFromSlackInput(baseURLInput);
Expand Down
30 changes: 16 additions & 14 deletions test/support/slack/commands/run-scrape.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,13 @@ describe('RunScrapeCommand', () => {
expect(slackContext.say.calledWith(':error: Only members of role "scrape" can run this command.')).to.be.false;
});

it('handles missing SLACK_IDS_RUN_IMPORT', async () => {
dataAccessStub.getConfiguration.resolves({ getSlackRoles: () => null });
const command = RunScrapeCommand(context);
await command.handleExecution(['https://example.com'], { ...slackContext, user: 'ANYUSER' });
expect(slackContext.say.calledWith(':error: Only members of role "scrape" can run this command.')).to.be.true;
});
// it('handles missing SLACK_IDS_RUN_IMPORT', async () => {
// dataAccessStub.getConfiguration.resolves({ getSlackRoles: () => null });
// const command = RunScrapeCommand(context);
// await command.handleExecution(['https://example.com'], { ...slackContext, user: 'ANYUSER' });
// eslint-disable-next-line max-len
// expect(slackContext.say.calledWith(':error: Only members of role "scrape" can run this command.')).to.be.true;
// });
it('triggers a scrape for a valid site with top pages', async () => {
dataAccessStub.getSiteByBaseURL.resolves({
getId: () => '123',
Expand All @@ -113,14 +114,15 @@ describe('RunScrapeCommand', () => {
expect(slackContext.say.thirdCall.args[0]).to.include('white_check_mark: Completed triggering scrape runs for site `https://example.com` — Total URLs: 2');
});

it('does not trigger a scrape when user is not authorized', async () => {
slackContext.user = 'UNAUTHORIZED_USER';
const command = RunScrapeCommand(context);

await command.handleExecution(['https://example.com'], slackContext);

expect(slackContext.say.calledWith(':error: Only members of role "scrape" can run this command.')).to.be.true;
});
// it('does not trigger a scrape when user is not authorized', async () => {
// slackContext.user = 'UNAUTHORIZED_USER';
// const command = RunScrapeCommand(context);
//
// await command.handleExecution(['https://example.com'], slackContext);
//
// eslint-disable-next-line max-len
// expect(slackContext.say.calledWith(':error: Only members of role "scrape" can run this command.')).to.be.true;
// });

it('responds with a warning for an invalid site url', async () => {
const command = RunScrapeCommand(context);
Expand Down
Loading