Skip to content

Commit

Permalink
Modify case where integration bot was authorized but user didn't fini…
Browse files Browse the repository at this point in the history
…sh inputting their PAT -> should result in not sharing keys with bot
  • Loading branch information
dangtony98 committed Jan 22, 2023
1 parent 6969593 commit 6b80cd6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const requireIntegrationAuthorizationAuth = ({
}) => {
return async (req: Request, res: Response, next: NextFunction) => {
const { integrationAuthId } = req[location];

const integrationAuth = await IntegrationAuth.findOne({
_id: integrationAuthId
})
Expand Down
7 changes: 1 addition & 6 deletions frontend/src/components/basic/dialog/ActivateBotDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,23 @@ type Props = {
isOpen: boolean;
closeModal: () => void;
selectedIntegrationOption: IntegrationOption | null;
handleBotActivate: () => Promise<void>;
integrationOptionPress: (integrationOption: IntegrationOption) => void;
};

const ActivateBotDialog = ({
isOpen,
closeModal,
selectedIntegrationOption,
handleBotActivate,
integrationOptionPress
}: Props) => {
const { t } = useTranslation();

const submit = async () => {
try {
// 1. activate bot
await handleBotActivate();

// type check
if (!selectedIntegrationOption) return;

// 2. start integration or probe for PAT
// start integration or probe for PAT
integrationOptionPress(selectedIntegrationOption);

} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const IntegrationAccessTokenDialog = ({
<div>
<Transition appear show={isOpen} as={Fragment}>
<Dialog as="div" className="relative z-10" onClose={() => {
console.log('onClose');
closeModal();
}}>
<Transition.Child
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/integrations/IntegrationSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const ProjectIntegrationSection = ({
setBot,
environments = [],
handleDeleteIntegration
}: Props) =>
integrations.length > 0 ? (
}: Props) => {
return integrations.length > 0 ? (
<div className="mb-12">
<div className="flex flex-col justify-between items-start mx-4 mb-4 mt-6 text-xl max-w-5xl px-2">
<h1 className="font-semibold text-3xl">Current Integrations</h1>
Expand All @@ -40,7 +40,6 @@ const ProjectIntegrationSection = ({
</p>
</div>
{integrations.map((integration: Integration) => {
console.log('IntegrationSection integration: ', integration);
return (
<IntegrationTile
key={`integration-${integration._id.toString()}`}
Expand All @@ -58,5 +57,6 @@ const ProjectIntegrationSection = ({
) : (
<div />
);

}

export default ProjectIntegrationSection;
14 changes: 10 additions & 4 deletions frontend/src/pages/integrations/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ export default function Integrations() {
accessToken?: string;
}) => {
try {
if (!bot.isActive) {
await handleBotActivate();
}

if (integrationOption.type === 'oauth') {
// integration is of type OAuth

Expand Down Expand Up @@ -233,7 +237,7 @@ export default function Integrations() {
return;
}
} catch (err) {
console.log(err);
console.error(err);
}
};

Expand All @@ -247,6 +251,7 @@ export default function Integrations() {
* @returns
*/
const integrationOptionPress = async (integrationOption: IntegrationOption) => {
// consider: don't start integration until at [handleIntegrationOption] step
try {
const integrationAuthX = integrationAuths.find((integrationAuth) => integrationAuth.integration === integrationOption.slug);

Expand All @@ -264,12 +269,15 @@ export default function Integrations() {
return;
}

if (!bot.isActive) {
await handleBotActivate();
}

// case: integration has been authorized before
// -> create new integration
const integration = await createIntegration({
integrationAuthId: integrationAuthX._id
});

setIntegrations([...integrations, integration]);
} catch (err) {
console.error(err);
Expand Down Expand Up @@ -350,15 +358,13 @@ export default function Integrations() {
isOpen={isActivateBotDialogOpen}
closeModal={() => setIsActivateBotDialogOpen(false)}
selectedIntegrationOption={selectedIntegrationOption}
handleBotActivate={handleBotActivate}
integrationOptionPress={integrationOptionPress}
/>
<IntegrationAccessTokenDialog
isOpen={isIntegrationAccessTokenDialogOpen}
closeModal={() => setIntegrationAccessTokenDialogOpen(false)}
selectedIntegrationOption={selectedIntegrationOption}
handleIntegrationOption={handleIntegrationOption}

/>
<IntegrationSection
integrations={integrations}
Expand Down

0 comments on commit 6b80cd6

Please sign in to comment.