Skip to content

Commit 85d1675

Browse files
committed
fix
1 parent f33f116 commit 85d1675

File tree

8 files changed

+52
-17
lines changed

8 files changed

+52
-17
lines changed

backend/src/main/java/io/mixeway/mixewayflowapi/api/threatintel/service/ThreatIntelService.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import io.mixeway.mixewayflowapi.api.threatintel.dto.ItemListResponse;
44
import io.mixeway.mixewayflowapi.api.threatintel.dto.RemovedVulnerabilityDTO;
55
import io.mixeway.mixewayflowapi.api.threatintel.dto.ReviewedVulnerabilityDTO;
6+
import io.mixeway.mixewayflowapi.db.entity.CodeRepo;
7+
import io.mixeway.mixewayflowapi.db.entity.Team;
68
import io.mixeway.mixewayflowapi.domain.coderepo.FindCodeRepoService;
79
import io.mixeway.mixewayflowapi.domain.finding.FindFindingService;
810
import io.mixeway.mixewayflowapi.domain.team.FindTeamService;
@@ -38,9 +40,11 @@ public ResponseEntity<List<ReviewedVulnerabilityDTO>> getSupressedThreats(Princi
3840

3941
public ResponseEntity<ItemListResponse> getThreatsForTeam(Principal principal, String remoteId) {
4042
ItemListResponse itemListResponse = findFindingService.getThreatIntelFindingsForTeam(principal,remoteId);
41-
itemListResponse.setNumberOfTeams(findTeamService.findAllTeams(principal).size());
42-
itemListResponse.setNumberOfAllProjects(findCodeRepoService.findCodeRepoForUser(principal).size());
43-
itemListResponse.setOpenedVulnerabilities(findFindingService.countOpenedVulnerabilities(principal));
43+
List<Team> team = findTeamService.findByRemoteId(remoteId);
44+
List<CodeRepo> codeRepos = findCodeRepoService.findbyTeamIn(team);
45+
itemListResponse.setNumberOfTeams(team.size());
46+
itemListResponse.setNumberOfAllProjects(codeRepos.size());
47+
itemListResponse.setOpenedVulnerabilities(findFindingService.countOpenedVulnerabilitiesForRepos(codeRepos));
4448
return new ResponseEntity<>(itemListResponse,HttpStatus.OK);
4549
}
4650
}

backend/src/main/java/io/mixeway/mixewayflowapi/domain/coderepo/FindCodeRepoService.java

+3
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,7 @@ public Optional<CodeRepo> findAllByUrl(String url) {
7777
}
7878

7979

80+
public List<CodeRepo> findbyTeamIn(List<Team> team) {
81+
return codeRepoRepository.findByTeamIn(team);
82+
}
8083
}

backend/src/main/java/io/mixeway/mixewayflowapi/domain/finding/FindFindingService.java

+3
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ private ItemListResponse mapProjectionsToItems(List<ItemProjection> projections)
154154
public Long countOpenedVulnerabilities(Principal principal){
155155
return findingRepository.countAllByCodeRepoInAndStatusIn(findCodeRepoService.findCodeRepoForUser(principal), Arrays.asList("NEW", "EXISTING"));
156156
}
157+
public Long countOpenedVulnerabilitiesForRepos(List<CodeRepo> codeRepos){
158+
return findingRepository.countAllByCodeRepoInAndStatusIn(codeRepos, Arrays.asList("NEW", "EXISTING"));
159+
}
157160

158161
public List<RemovedVulnerabilityDTO> getTopRemovedVulns(Principal principal){
159162

backend/src/main/resources/db/changelog/data_dump_test.sql

+4
Original file line numberDiff line numberDiff line change
@@ -792,4 +792,8 @@ SELECT pg_catalog.setval('public.vulnerability_id_seq', 20, true);
792792
--
793793
-- PostgreSQL database dump complete
794794
--
795+
INSERT INTO users (username, password, active, reset_password)
796+
VALUES
797+
('team_user', '$2a$10$test', true, false),
798+
('unauthorized_user', '$2a$10$test', true, false);
795799

backend/src/main/resources/db/changelog/db.changelog-master.sql

+16
Original file line numberDiff line numberDiff line change
@@ -583,3 +583,19 @@ HAVING
583583
THEN 'notable'
584584
ELSE NULL
585585
END IS NOT NULL;
586+
587+
-- changeset siewer:add-comment
588+
CREATE TABLE comment (
589+
id BIGSERIAL PRIMARY KEY,
590+
message TEXT NOT NULL,
591+
finding_id BIGINT NOT NULL,
592+
user_id BIGINT NOT NULL,
593+
created_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
594+
updated_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
595+
FOREIGN KEY (finding_id) REFERENCES finding(id),
596+
FOREIGN KEY (user_id) REFERENCES users(id)
597+
);
598+
599+
-- Index for faster lookups
600+
CREATE INDEX idx_comment_finding ON comment(finding_id);
601+
CREATE INDEX idx_comment_user ON comment(user_id);

backend/src/test/java/io/mixeway/mixewayflowapi/domain/comment/CreateCommentServiceTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void createCommentAsAdmin() throws FindingNotFoundException {
4848
String message = "Test comment";
4949

5050
// When
51-
Comment comment = createCommentService.createComment(1L,1L, message, principal);
51+
Comment comment = createCommentService.createComment(2L,1L, message, principal);
5252

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

7070
// When
71-
Comment comment = createCommentService.createComment(1L,1L, message, principal);
71+
Comment comment = createCommentService.createComment(2L,1L, message, principal);
7272

7373
// Then
7474
assertNotNull(comment);
@@ -88,7 +88,7 @@ void createCommentUnauthorizedUser() {
8888

8989
// Then
9090
assertThrows(UnauthorizedAccessException.class, () ->
91-
createCommentService.createComment(1L, 1L,message, principal)
91+
createCommentService.createComment(2L, 1L,message, principal)
9292
);
9393
}
9494

frontend/src/app/views/show-repo/show-repo.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ <h5 cModalTitle>Vulnerability Details</h5>
11251125
cButton
11261126
color="primary"
11271127
type="submit"
1128-
[disabled]="!newComment?.trim() || isAddingComment">
1128+
[disabled]="!newComment.trim() || isAddingComment">
11291129
<c-spinner *ngIf="isAddingComment" size="sm" class="me-1"></c-spinner>
11301130
Send
11311131
</button>

frontend/src/app/views/threat-intel/threat-score/threat-score.component.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type ChartOptions = {
1818
labels: string[];
1919
};
2020

21+
2122
@Component({
2223
selector: 'app-threat-score',
2324
standalone: true,
@@ -33,11 +34,11 @@ export type ChartOptions = {
3334
export class ThreatScoreComponent implements OnChanges {
3435
@Input()
3536
threatScore: string = '';
36-
public chartOptions: Partial<ChartOptions>;
37+
public chartOptions: ChartOptions;
3738

3839
constructor() {
39-
// Initialize chartOptions without threatScore
4040
this.chartOptions = {
41+
series: [0], // Initialize with 0
4142
chart: {
4243
type: 'radialBar',
4344
offsetY: -20,
@@ -75,7 +76,6 @@ export class ThreatScoreComponent implements OnChanges {
7576
},
7677
fill: {
7778
type: 'gradient',
78-
7979
gradient: {
8080
shade: 'light',
8181
shadeIntensity: 0.4,
@@ -102,23 +102,28 @@ export class ThreatScoreComponent implements OnChanges {
102102

103103
updateChartOptions() {
104104
// Convert threatScore to a number and update series
105-
const score = Number(this.threatScore) || 0; // Default to 0 if invalid
106-
let color: string ='';
107-
if (score > 80){
105+
const score = Number(this.threatScore) || 0;
106+
let color: string = '';
107+
if (score > 80) {
108108
color = '#e60303';
109-
} else if (score > 60){
109+
} else if (score > 60) {
110110
color = '#e34848';
111-
} else if (score > 40){
111+
} else if (score > 40) {
112112
color = '#e47a3a';
113-
} else if (score > 20){
113+
} else if (score > 20) {
114114
color = '#bedf76';
115115
} else {
116116
color = '#55ec32';
117117
}
118+
119+
// Update only the necessary properties
118120
this.chartOptions = {
119121
...this.chartOptions,
120122
series: [score],
121-
fill: {colors: [color]},
123+
fill: {
124+
...this.chartOptions.fill,
125+
colors: [color]
126+
}
122127
};
123128
}
124129
}

0 commit comments

Comments
 (0)