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

added vulnerable api request response download raw button #1504

Merged
merged 1 commit into from
Dec 18, 2024
Merged
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
9 changes: 5 additions & 4 deletions app/components/ak-divider/index.hbs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{{! @glint-nocheck : or}}
{{#let (element (or @tag 'hr')) as |Tag|}}
{{#let (element (or @tag (if this.isVertical 'div' 'hr'))) as |Tag|}}
<Tag
data-test-ak-divider
...attributes
local-class='
ak-divider-root
ak-divider-variant-{{or @variant "fullWidth"}}
ak-divider-color-{{or @color "light"}}'
ak-divider-root
ak-divider-variant-{{or @variant "fullWidth"}}
ak-divider-color-{{or @color "light"}}
ak-divider-direction-{{or @direction "horizontal"}}'
/>
{{/let}}
30 changes: 27 additions & 3 deletions app/components/ak-divider/index.scss
future-pirate-king marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
.ak-divider-root {
flex-shrink: 0;
border-width: 0px 0px thin;
border-style: solid;

&.ak-divider-direction-horizontal {
border-width: 0px 0px thin;
}

&.ak-divider-direction-vertical {
flex-shrink: unset;
border-width: 0px thin 0px 0px;
}
}

.ak-divider-variant-fullWidth {
width: 100%;
margin: 0px;

&.ak-divider-direction-horizontal {
width: 100%;
}

&.ak-divider-direction-vertical {
height: 100%;
}
}

.ak-divider-variant-middle {
margin: 0 1em;

&.ak-divider-direction-horizontal {
width: 100%;
}

&.ak-divider-direction-vertical {
margin: 1em 0;
height: 80%;
}
}

.ak-divider-color-light {
Expand All @@ -19,4 +43,4 @@

.ak-divider-color-dark {
border-color: var(--ak-divider-color-dark);
}
}
21 changes: 21 additions & 0 deletions app/components/ak-divider/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,24 @@ Default.args = {
variant: 'fullWidth',
color: 'light',
};

const VerticalTemplate = (args) => ({
template: hbs`
<AkTypography @color="textSecondary" @gutterBottom={{true}}>Experiment with me</AkTypography>

<div {{style height="200px"}} class="flex-row flex-align-center flex-justify-space-around p-3 w-full m-3">
<AkTypography @color="textSecondary" @gutterBottom={{true}}>A</AkTypography>
<AkDivider @color={{this.color}} @direction={{this.direction}} @variant={{this.variant}} />
<AkTypography @color="textSecondary" @gutterBottom={{true}}>B</AkTypography>
</div>
`,
context: { ...args },
});

export const Vertical = VerticalTemplate.bind({});

Vertical.args = {
color: 'dark',
direction: 'vertical',
variant: 'fullWidth',
};
7 changes: 6 additions & 1 deletion app/components/ak-divider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ export interface AkDividerSignature {
tag?: string;
variant?: 'fullWidth' | 'middle';
color?: 'light' | 'dark';
direction?: 'horizontal' | 'vertical';
};
Blocks: { default: [] };
}

export default class AkDividerComponent extends Component<AkDividerSignature> {}
export default class AkDividerComponent extends Component<AkDividerSignature> {
get isVertical() {
return this.args.direction === 'vertical';
}
}

declare module '@glint/environment-ember-loose/registry' {
export default interface Registry {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{#if this.me.org.is_admin}}
{{#if (or @analysis.isRisky @analysis.isOverriddenAsPassed)}}
<AkStack @spacing='1.5'>
<div local-class='divider' />
<AkStack @spacing='1.5' {{style height='100%'}}>
<AkDivider @direction='vertical' @color='dark' />

<AkTooltip
@arrow={{true}}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

.analysis-content-title {
position: sticky;
top: calc(172px + 1.5em);
top: calc(132px + 1.5em);
z-index: 1;
padding: 1em;
border: 1px solid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,65 +31,64 @@
{{t 'vulnerableApis'}}
</AkTypography>

<AkStack @spacing='1' @alignItems='center'>
<AkStack @spacing='1.5' @alignItems='center' {{style height='30px'}}>
<AkStack
local-class='counter-container'
@spacing='0.5'
@alignItems='flex-end'
@spacing='3'
@alignItems='center'
>
<AkTypography @variant='subtitle1'>
{{pgc.startItemIdx}}
</AkTypography>
<AkTypography @variant='body2'>
out of
</AkTypography>
<AkTypography @variant='subtitle1'>
{{pgc.totalItems}}
APIs'
</AkTypography>
</AkStack>

<AkButton
data-test-analysisDetails-vulFinding-pagination-prevBtn
@disabled={{pgc.disablePrev}}
@leftIconClass={{this.classes.prevButtonIconClass}}
@color='neutral'
@variant='outlined'
local-class='ak-pagination-prev-button'
{{on 'click' pgc.prevAction}}
>
<:leftIcon>
<AkIconButton
data-test-analysisDetails-vulFinding-pagination-prevBtn
disabled={{pgc.disablePrev}}
local-class='ak-pagination-prev-button'
{{on 'click' pgc.prevAction}}
>
<AkIcon
@iconName='arrow-left'
{{style fontSize='1.28rem !important'}}
/>
</:leftIcon>
</AkIconButton>

<:default>
{{t 'previous'}}
</:default>
</AkButton>

<AkButton
data-test-analysisDetails-vulFinding-pagination-nextBtn
@disabled={{pgc.disableNext}}
@color='neutral'
@variant='outlined'
@rightIconClass={{this.classes.nextButtonIconClass}}
local-class='ak-pagination-next-button'
{{on 'click' pgc.nextAction}}
>
<:default>
{{t 'next'}}
</:default>
<AkStack @spacing='0.5' @alignItems='center'>
<AkTypography @variant='subtitle1'>
{{pgc.startItemIdx}}
</AkTypography>
<AkTypography @variant='body2'>
{{t 'outOf'}}
</AkTypography>
<AkTypography @variant='subtitle1'>
{{pgc.totalItems}}
{{t 'apis'}}
</AkTypography>
</AkStack>

<:rightIcon>
<AkIconButton
data-test-analysisDetails-vulFinding-pagination-nextBtn
disabled={{pgc.disableNext}}
local-class='ak-pagination-next-button'
{{on 'click' pgc.nextAction}}
>
<AkIcon
@iconName='arrow-right'
{{style fontSize='1.28rem !important'}}
/>
</:rightIcon>
</AkButton>
</AkIconButton>
</AkStack>

<AkDivider @direction='vertical' @color='dark' />

<AkTooltip
@arrow={{true}}
@placement='bottom'
@title={{t 'downloadRawApiFindings'}}
>
<AkIconButton
{{on 'click' (perform this.downloadApiFindingsPayload)}}
@variant='outlined'
>
<AkIcon @variant='outlined' @iconName='file-download' />
</AkIconButton>
</AkTooltip>
</AkStack>
</AkStack>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

.analysis-content-title {
position: sticky;
top: calc(172px + 1.5em);
top: calc(132px + 1.5em);
z-index: 1;
padding: 1em;
background-color: var(
Expand All @@ -54,14 +54,6 @@
}
}

.ak-pagination-button-prev-icon {
margin-right: 0.214em;
}

.ak-pagination-button-next-icon {
margin-left: 0.214em;
}

.ak-pagination-select {
height: 30px !important;
}
Expand All @@ -75,20 +67,30 @@
min-width: unset;
padding-left: 0.143em;
padding-right: 0.857em;

&:hover,
&:disabled {
avzz-19 marked this conversation as resolved.
Show resolved Hide resolved
background-color: var(
--file-details-vulnerability-analysis-details-pagination-button-background-color
) !important;
}
}

.ak-pagination-prev-button,
.ak-pagination-next-button {
padding-left: 0.357em;
padding-right: 0.357em;
border-left: 1px solid var(--file-details-vulnerability-analysis-details-border-color-2);
border-radius: 0px !important;
}

.ak-pagination-prev-button {
border-right: 1px solid var(--file-details-vulnerability-analysis-details-border-color-2);
border-radius: 0px !important;
}

.counter-container {
padding: 0.3em 0.75em;
border: 1px solid
var(--file-details-vulnerability-analysis-details-border-color);
var(--file-details-vulnerability-analysis-details-border-color-2);
border-radius: var(--file-details-vulnerability-analysis-details-border-radius);
background-color: var(
--file-details-vulnerability-analysis-details-code-background-color
);
margin-right: 1em;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import {
type VulnerableApiFinding,
} from 'irene/utils/parse-vulnerable-api-finding';

import styles from './index.scss';

export interface FileDetailsVulnerabilityAnalysisDetailsFindingsSignature {
Args: {
analysis: AnalysisModel;
Expand All @@ -30,6 +28,7 @@ export default class FileDetailsVulnerabilityAnalysisDetailsFindingsComponent ex

@service('notifications') declare notify: NotificationService;
@service declare intl: IntlService;
@service('browser/window') declare window: Window;

noop() {}

Expand All @@ -42,14 +41,6 @@ export default class FileDetailsVulnerabilityAnalysisDetailsFindingsComponent ex
this.parseCustomAndApiVulnerableFindings.perform();
}

get classes() {
return {
selectClass: styles['ak-pagination-select'],
prevButtonIconClass: styles['ak-pagination-button-prev-icon'],
nextButtonIconClass: styles['ak-pagination-button-next-icon'],
};
}

get analysis() {
return this.args.analysis;
}
Expand All @@ -73,6 +64,13 @@ export default class FileDetailsVulnerabilityAnalysisDetailsFindingsComponent ex
);
}

get apiFindingsRawPayload() {
return this.analysis.findings
.map((finding) => finding.description)
.filter(Boolean)
.join('\n');
}

@action
handlePrevNextClick({ limit, offset }: { limit: number; offset: number }) {
this.limit = limit;
Expand All @@ -98,6 +96,29 @@ export default class FileDetailsVulnerabilityAnalysisDetailsFindingsComponent ex
this.customVulnerableFindings = customVulnerableFindings;
this.vulnerableApiFindings = vulnerableApiFindings;
});

downloadApiFindingsPayload = task(async () => {
// Create a Blob with the raw text
const blob = new Blob([this.apiFindingsRawPayload], { type: 'text/plain' });

// Create a download link
const link = this.window.document.createElement('a');
link.href = URL.createObjectURL(blob);

const analysisId = this.analysis.id;

// Generate a filename
const timestamp = new Date().getTime();
link.download = `analysis_api_findings_${analysisId}_${timestamp}.txt`;

// Append to body, click, and remove
this.window.document.body.appendChild(link);
link.click();
this.window.document.body.removeChild(link);

// Clean up the URL object
URL.revokeObjectURL(link.href);
});
}

declare module '@glint/environment-ember-loose/registry' {
Expand Down
Loading
Loading