Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
siewer committed Jan 31, 2025
1 parent f33f116 commit 85d1675
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import io.mixeway.mixewayflowapi.api.threatintel.dto.ItemListResponse;
import io.mixeway.mixewayflowapi.api.threatintel.dto.RemovedVulnerabilityDTO;
import io.mixeway.mixewayflowapi.api.threatintel.dto.ReviewedVulnerabilityDTO;
import io.mixeway.mixewayflowapi.db.entity.CodeRepo;
import io.mixeway.mixewayflowapi.db.entity.Team;
import io.mixeway.mixewayflowapi.domain.coderepo.FindCodeRepoService;
import io.mixeway.mixewayflowapi.domain.finding.FindFindingService;
import io.mixeway.mixewayflowapi.domain.team.FindTeamService;
Expand Down Expand Up @@ -38,9 +40,11 @@ public ResponseEntity<List<ReviewedVulnerabilityDTO>> getSupressedThreats(Princi

public ResponseEntity<ItemListResponse> getThreatsForTeam(Principal principal, String remoteId) {
ItemListResponse itemListResponse = findFindingService.getThreatIntelFindingsForTeam(principal,remoteId);
itemListResponse.setNumberOfTeams(findTeamService.findAllTeams(principal).size());
itemListResponse.setNumberOfAllProjects(findCodeRepoService.findCodeRepoForUser(principal).size());
itemListResponse.setOpenedVulnerabilities(findFindingService.countOpenedVulnerabilities(principal));
List<Team> team = findTeamService.findByRemoteId(remoteId);
List<CodeRepo> codeRepos = findCodeRepoService.findbyTeamIn(team);
itemListResponse.setNumberOfTeams(team.size());
itemListResponse.setNumberOfAllProjects(codeRepos.size());
itemListResponse.setOpenedVulnerabilities(findFindingService.countOpenedVulnerabilitiesForRepos(codeRepos));
return new ResponseEntity<>(itemListResponse,HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,7 @@ public Optional<CodeRepo> findAllByUrl(String url) {
}


public List<CodeRepo> findbyTeamIn(List<Team> team) {
return codeRepoRepository.findByTeamIn(team);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ private ItemListResponse mapProjectionsToItems(List<ItemProjection> projections)
public Long countOpenedVulnerabilities(Principal principal){
return findingRepository.countAllByCodeRepoInAndStatusIn(findCodeRepoService.findCodeRepoForUser(principal), Arrays.asList("NEW", "EXISTING"));
}
public Long countOpenedVulnerabilitiesForRepos(List<CodeRepo> codeRepos){
return findingRepository.countAllByCodeRepoInAndStatusIn(codeRepos, Arrays.asList("NEW", "EXISTING"));
}

public List<RemovedVulnerabilityDTO> getTopRemovedVulns(Principal principal){

Expand Down
4 changes: 4 additions & 0 deletions backend/src/main/resources/db/changelog/data_dump_test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -792,4 +792,8 @@ SELECT pg_catalog.setval('public.vulnerability_id_seq', 20, true);
--
-- PostgreSQL database dump complete
--
INSERT INTO users (username, password, active, reset_password)
VALUES
('team_user', '$2a$10$test', true, false),
('unauthorized_user', '$2a$10$test', true, false);

16 changes: 16 additions & 0 deletions backend/src/main/resources/db/changelog/db.changelog-master.sql
Original file line number Diff line number Diff line change
Expand Up @@ -583,3 +583,19 @@ HAVING
THEN 'notable'
ELSE NULL
END IS NOT NULL;

-- changeset siewer:add-comment
CREATE TABLE comment (
id BIGSERIAL PRIMARY KEY,
message TEXT NOT NULL,
finding_id BIGINT NOT NULL,
user_id BIGINT NOT NULL,
created_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (finding_id) REFERENCES finding(id),
FOREIGN KEY (user_id) REFERENCES users(id)
);

-- Index for faster lookups
CREATE INDEX idx_comment_finding ON comment(finding_id);
CREATE INDEX idx_comment_user ON comment(user_id);
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void createCommentAsAdmin() throws FindingNotFoundException {
String message = "Test comment";

// When
Comment comment = createCommentService.createComment(1L,1L, message, principal);
Comment comment = createCommentService.createComment(2L,1L, message, principal);

// Then
assertNotNull(comment);
Expand All @@ -68,7 +68,7 @@ void createCommentAsTeamMember() throws FindingNotFoundException {
String message = "Test comment from team member";

// When
Comment comment = createCommentService.createComment(1L,1L, message, principal);
Comment comment = createCommentService.createComment(2L,1L, message, principal);

// Then
assertNotNull(comment);
Expand All @@ -88,7 +88,7 @@ void createCommentUnauthorizedUser() {

// Then
assertThrows(UnauthorizedAccessException.class, () ->
createCommentService.createComment(1L, 1L,message, principal)
createCommentService.createComment(2L, 1L,message, principal)
);
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/views/show-repo/show-repo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ <h5 cModalTitle>Vulnerability Details</h5>
cButton
color="primary"
type="submit"
[disabled]="!newComment?.trim() || isAddingComment">
[disabled]="!newComment.trim() || isAddingComment">
<c-spinner *ngIf="isAddingComment" size="sm" class="me-1"></c-spinner>
Send
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type ChartOptions = {
labels: string[];
};


@Component({
selector: 'app-threat-score',
standalone: true,
Expand All @@ -33,11 +34,11 @@ export type ChartOptions = {
export class ThreatScoreComponent implements OnChanges {
@Input()
threatScore: string = '';
public chartOptions: Partial<ChartOptions>;
public chartOptions: ChartOptions;

constructor() {
// Initialize chartOptions without threatScore
this.chartOptions = {
series: [0], // Initialize with 0
chart: {
type: 'radialBar',
offsetY: -20,
Expand Down Expand Up @@ -75,7 +76,6 @@ export class ThreatScoreComponent implements OnChanges {
},
fill: {
type: 'gradient',

gradient: {
shade: 'light',
shadeIntensity: 0.4,
Expand All @@ -102,23 +102,28 @@ export class ThreatScoreComponent implements OnChanges {

updateChartOptions() {
// Convert threatScore to a number and update series
const score = Number(this.threatScore) || 0; // Default to 0 if invalid
let color: string ='';
if (score > 80){
const score = Number(this.threatScore) || 0;
let color: string = '';
if (score > 80) {
color = '#e60303';
} else if (score > 60){
} else if (score > 60) {
color = '#e34848';
} else if (score > 40){
} else if (score > 40) {
color = '#e47a3a';
} else if (score > 20){
} else if (score > 20) {
color = '#bedf76';
} else {
color = '#55ec32';
}

// Update only the necessary properties
this.chartOptions = {
...this.chartOptions,
series: [score],
fill: {colors: [color]},
fill: {
...this.chartOptions.fill,
colors: [color]
}
};
}
}

0 comments on commit 85d1675

Please sign in to comment.