Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ public class SecurityConfig {
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(
auth -> auth.requestMatchers("/", "/index", "/demo", "/error", "/login/**", "/oauth2/**", "/dev/**")
.permitAll().requestMatchers("/dashboard", "/profile").authenticated()
.requestMatchers("/incidents", "/api/incidents/**").hasAnyRole("RESIDENT", "HANDLER", "ADMIN")
.requestMatchers("/admin", "/api/admin/**").hasRole("ADMIN")
.requestMatchers("/swagger-ui.html", "/swagger-ui/**", "/v3/api-docs/**").hasRole("ADMIN")
.anyRequest().authenticated())
.permitAll().requestMatchers("/dashboard.html", "/profile.html", "/viewincident.html")
.authenticated().requestMatchers("/incidents.html/**", "/api/incidents/**")
.hasAnyRole("RESIDENT", "HANDLER", "ADMIN").requestMatchers("/admin.html", "/api/admin/**")
.hasRole("ADMIN").requestMatchers("/swagger-ui.html", "/swagger-ui/**", "/v3/api-docs/**")
.hasRole("ADMIN").anyRequest().authenticated())
.oauth2Login(
oauth2 -> oauth2.userInfoEndpoint(userInfo -> userInfo.userService(customOAuth2UserService))
.defaultSuccessUrl("/dashboard", true))
.defaultSuccessUrl("/dashboard.html", true))
.logout(logout -> logout.logoutSuccessUrl("/").invalidateHttpSession(true).clearAuthentication(true)
.deleteCookies("JSESSIONID"))
.csrf(csrf -> csrf.ignoringRequestMatchers("/api/admin/**", "/api/incidents/**", "/dev/**"));
.csrf(csrf -> csrf.ignoringRequestMatchers("/api/admin/**", "/api/incidents/**", "/api/documents/**",
"/dev/**"));

return http.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ResponseStatusException;

import java.io.InputStream;
import java.util.List;

@Controller
@RequestMapping("/documents")
@RestController
@RequestMapping("/api/documents")
Comment thread
SandraNelj marked this conversation as resolved.
public class DocumentController {

private final DocumentService documentService;
Expand All @@ -38,10 +37,13 @@ public DocumentController(DocumentService documentService, IncidentService incid
}

@GetMapping("/{fileKey}")
@ResponseBody
public ResponseEntity<Resource> getFile(@PathVariable String fileKey,
@AuthenticationPrincipal CustomUserDetails userDetails) {

if (userDetails == null) {
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED);
}

AppUser user = userDetails.getUser();

Document document = documentService.getByFileKey(fileKey)
Expand All @@ -64,8 +66,8 @@ public ResponseEntity<Resource> getFile(@PathVariable String fileKey,
}

@PostMapping("/upload/{incidentId}")
public String uploadFile(@PathVariable Long incidentId, @RequestParam("files") List<MultipartFile> files,
@AuthenticationPrincipal CustomUserDetails userDetails) {
public ResponseEntity<Void> uploadFile(@PathVariable Long incidentId,
@RequestParam("files") List<MultipartFile> files, @AuthenticationPrincipal CustomUserDetails userDetails) {

AppUser user = userDetails.getUser();
Incident incident = incidentService.getById(incidentId, user);
Expand All @@ -75,22 +77,18 @@ public String uploadFile(@PathVariable Long incidentId, @RequestParam("files") L
documentService.uploadFile(file, incident);
}
}
return "redirect:/incidents/" + incidentId;
return ResponseEntity.ok().build();
}

@GetMapping("/download/{incidentId}")
public ResponseEntity<InputStreamResource> downloadFile(@PathVariable Long incidentId,
@GetMapping("/{fileKey}/download")
public ResponseEntity<InputStreamResource> downloadFile(@PathVariable String fileKey,
@AuthenticationPrincipal CustomUserDetails userDetails) {
AppUser user = userDetails.getUser();
Incident incident = incidentService.getById(incidentId, user);

List<Document> documents = documentService.getDocumentsByIncident(incident);
if (documents.isEmpty()) {
return ResponseEntity.notFound().build();
}
Document document = documents.get(0);
Document document = documentService.getByFileKey(fileKey)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));

InputStream stream = documentService.downloadFile(document.getFileKey());
InputStream stream = minioService.getFile(fileKey);

return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + document.getFileName() + "\"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ public InputStream downloadFile(String objectKey) {
/** Delete file */
@Transactional
public void deleteFile(Document document) {
documentRepository.delete(document);

try {
documentRepository.delete(document);
minioService.deleteFile(document.getFileKey());
} catch (Exception e) {
} catch (RuntimeException e) {
log.warn("Could not delete file: {}", document.getFileKey(), e);
}
}
Comment thread
SandraNelj marked this conversation as resolved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void deleteFile(String fileKey) {
try {
minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(fileKey).build());
} catch (Exception e) {
throw new RuntimeException("Failed to delete file " + fileKey, e);
System.err.println("MinIO delete failed for " + fileKey + ": " + e.getMessage());
}
}

Expand Down
148 changes: 0 additions & 148 deletions src/main/java/org/example/team6backend/page/PageController.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -771,10 +771,10 @@
<a href="/">Incident Management System</a>
</div>
<div class="nav-links">
<a href="/dashboard">Dashboard</a>
<a href="/incidents">Incidents</a>
<a href="/profile">Profile</a>
<a href="/admin" class="active">Admin</a>
<a href="/dashboard.html">Dashboard</a>
<a href="/incidents.html">Incidents</a>
<a href="/profile.html">Profile</a>
<a href="/admin.html" class="active">Admin</a>
<div class="user-info">
<span class="user-name" th:text="${user.name != null ? user.name : user.githubLogin}">User</span>
<span class="role-badge admin" th:text="${role}">ADMIN</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<body>
<div class="container">

<a href="/dashboard" class="back-dashboard-btn">Back to dashboard</a>
<a href="/dashboard.html" class="back-dashboard-btn">Back to dashboard</a>

<div class="card">
<h2>Report Incident</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,11 @@
<a href="/">Incident Management System</a>
</div>
<div class="nav-links">
<a href="/dashboard">Home</a>
<a th:if="${role != 'PENDING' && user.active}" href="/incidents">Incidents</a>
<a href="/profile">Profile</a>
<a href="/dashboard.html">Home</a>
<a th:if="${role != 'PENDING' && user.active}" href="/incidents.html">Incidents</a>
<a href="/profile.html">Profile</a>
<div th:if="${role == 'ADMIN' && user.active}">
<a href="/admin">Admin</a>
<a href="/admin.html">Admin</a>
</div>

<div th:if="${@environment.getProperty('dev.mode.enabled') == 'true'}"
Expand Down Expand Up @@ -700,7 +700,7 @@ <h3>Pending Users Approval</h3>
<div class="incidents-card">
<div class="card-header">
<h3>Recent incidents</h3>
<a href="/incidents" class="btn btn-outline">View all →</a>
<a href="/incidents.html" class="btn btn-outline">View all →</a>
</div>
<div id="incidentsList" class="incident-list">
<p style="text-align: center; color: #6b7280;">Loading incidents...</p>
Expand Down Expand Up @@ -765,7 +765,7 @@ <h3>Recent incidents</h3>
fetch(`/dev/switch-user?githubLogin=${githubLogin}`)
.then(response => {
if (response.ok) {
window.location.href = '/dashboard';
window.location.href = '/dashboard.html';
} else {
console.error('Failed to switch role');
}
Expand Down Expand Up @@ -816,7 +816,7 @@ <h3>Recent incidents</h3>
container.innerHTML = '<p style="text-align: center; color: #6b7280;">No incidents yet.</p>';
} else {
container.innerHTML = incidents.map(i => `
<div class="incident-item" onclick="window.location.href='/incidents/${i.id}'" style="cursor:pointer;">
<div class="incident-item" onclick="window.location.href='/incidents.html/${i.id}'" style="cursor:pointer;">
<div>
<div class="incident-title">${escapeHtml(i.subject)}</div>
<div class="incident-date">${formatDate(i.createdAt)}</div>
Expand Down Expand Up @@ -967,7 +967,7 @@ <h3>Recent incidents</h3>
}

if (incidentId) {
window.location.href = `/incidents/${incidentId}`;
window.location.href = `/incidents.html?id=${incidentId}`;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
<body th:attr="data-role=${role}">
<div class="container">

<a href="/dashboard" class="back-dashboard-btn">← Back to dashboard</a>
<a href="/dashboard.html" class="back-dashboard-btn">← Back to dashboard</a>

<h2 id="title">Loading...</h2>
<div id="incidents">
Expand Down Expand Up @@ -343,7 +343,7 @@ <h2 id="title">Loading...</h2>
}

function viewIncident(id) {
window.location.href = `/incidents/${id}`;
window.location.href = `/incidents.html?id=${id}`;
}
Comment thread
SandraNelj marked this conversation as resolved.

function escapeHtml(str) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@
<a href="/">Incident Management System</a>
</div>
<div class="nav-links">
<a href="/dashboard">Home</a>
<a th:if="${role != 'PENDING'}" href="/incidents">Incidents</a>
<a href="/dashboard.html">Home</a>
<a th:if="${role != 'PENDING'}" href="/incidents.html">Incidents</a>
<a href="/profile">Profile</a>
<div th:if="${role == 'ADMIN'}">
<a href="/admin">Admin</a>
Expand Down
Loading
Loading