Skip to content

Commit e17e2a2

Browse files
committed
Rip out anything left that deals in anything other than ids
1 parent b6d5374 commit e17e2a2

38 files changed

Lines changed: 241 additions & 244 deletions

backend/src/main/java/net/modtale/controller/admin/ProjectManagementController.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ public ResponseEntity<?> getProjectReviewDetails(@PathVariable String id) {
7878
Project project = projectService.getRawProjectById(id);
7979
if (project == null) return ResponseEntity.notFound().build();
8080

81-
User author = userRepository.findByUsernameIgnoreCase(project.getAuthor()).orElse(null);
82-
if (author == null) {
83-
author = userRepository.findById(project.getAuthor()).orElse(null);
84-
}
81+
User author = userRepository.findById(project.getAuthorId()).orElse(null);
8582

8683
AdminAuthorStatsDTO authorStats = new AdminAuthorStatsDTO(
8784
author != null ? author.getCreatedAt() : "Unknown",
@@ -262,7 +259,7 @@ public ResponseEntity<?> unlistProject(@PathVariable String id, @RequestBody(req
262259
List.of(targetProject.getAuthorId()),
263260
"Project Unlisted",
264261
"Your project '" + targetProject.getTitle() + "' was unlisted from the public directory by an administrator. Reason: " + reason,
265-
URI.create("/mod/" + targetProject.getSlug()),
262+
URI.create(projectService.getProjectLink(targetProject)),
266263
null
267264
);
268265

backend/src/main/java/net/modtale/controller/admin/UserManagementController.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,24 @@ public ResponseEntity<?> unbanEmail(@RequestParam String email) {
9999
return ResponseEntity.ok().build();
100100
}
101101

102-
@GetMapping("/users/{username}")
103-
public ResponseEntity<?> getUserDetails(@PathVariable String username) {
102+
@GetMapping("/users/{userId}")
103+
public ResponseEntity<?> getUserDetails(@PathVariable String userId) {
104104
User currentUser = getSafeUser();
105105
if (!accessControlService.isAdmin(currentUser)) {
106106
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
107107
}
108-
Optional<User> target = userRepository.findByUsernameIgnoreCase(username);
108+
Optional<User> target = userRepository.findById(userId);
109109
if (target.isEmpty()) return ResponseEntity.notFound().build();
110110

111111
return ResponseEntity.ok(UserMapper.toDTO(target.get(), true));
112112
}
113113

114-
@GetMapping("/users/{username}/raw")
115-
public ResponseEntity<?> getRawUser(@PathVariable String username) {
114+
@GetMapping("/users/{userId}/raw")
115+
public ResponseEntity<?> getRawUser(@PathVariable String userId) {
116116
User currentUser = getSafeUser();
117117
if (!accessControlService.isSuperAdmin(currentUser)) return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
118118

119-
User target = userRepository.findByUsernameIgnoreCase(username).orElse(null);
119+
User target = userRepository.findById(userId).orElse(null);
120120
if (target == null) return ResponseEntity.notFound().build();
121121

122122
target.setGithubAccessToken(null);
@@ -127,12 +127,12 @@ public ResponseEntity<?> getRawUser(@PathVariable String username) {
127127
return ResponseEntity.ok(target);
128128
}
129129

130-
@PutMapping("/users/{username}/raw")
131-
public ResponseEntity<?> updateRawUser(@PathVariable String username, @RequestBody User updatedData) {
130+
@PutMapping("/users/{userId}/raw")
131+
public ResponseEntity<?> updateRawUser(@PathVariable String userId, @RequestBody User updatedData) {
132132
User currentUser = getSafeUser();
133133
if (!accessControlService.isSuperAdmin(currentUser)) return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
134134

135-
User existing = userRepository.findByUsernameIgnoreCase(username).orElse(null);
135+
User existing = userRepository.findById(userId).orElse(null);
136136
if (existing == null) return ResponseEntity.notFound().build();
137137

138138
updatedData.setId(existing.getId());
@@ -152,16 +152,16 @@ public ResponseEntity<?> updateRawUser(@PathVariable String username, @RequestBo
152152
return ResponseEntity.ok().build();
153153
}
154154

155-
@DeleteMapping("/users/{username}")
155+
@DeleteMapping("/users/{userId}")
156156
public ResponseEntity<?> deleteUser(
157-
@PathVariable String username,
157+
@PathVariable String userId,
158158
@RequestParam(required = false, defaultValue = "Administrative enforcement action.") String reason
159159
) {
160160
User currentUser = getSafeUser();
161161
if (!accessControlService.isAdmin(currentUser)) {
162162
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
163163
}
164-
User target = userRepository.findByUsernameIgnoreCase(username).orElse(null);
164+
User target = userRepository.findById(userId).orElse(null);
165165
if (target == null) return ResponseEntity.notFound().build();
166166

167167
if (!canManageUser(currentUser, target)) {
@@ -182,15 +182,15 @@ public ResponseEntity<?> deleteUser(
182182
}
183183
}
184184

185-
@PostMapping("/users/{username}/tier")
186-
public ResponseEntity<?> setUserTier(@PathVariable String username, @RequestParam String tier) {
185+
@PostMapping("/users/{userId}/tier")
186+
public ResponseEntity<?> setUserTier(@PathVariable String userId, @RequestParam String tier) {
187187
User currentUser = getSafeUser();
188188
if (!accessControlService.isSuperAdmin(currentUser)) {
189189
return ResponseEntity.status(HttpStatus.FORBIDDEN)
190190
.body(Map.of("error", "Access Denied", "message", "You do not have permission."));
191191
}
192192

193-
User target = userRepository.findByUsernameIgnoreCase(username).orElse(null);
193+
User target = userRepository.findById(userId).orElse(null);
194194
if (target == null) return ResponseEntity.status(HttpStatus.NOT_FOUND)
195195
.body(Map.of("error", "Not Found", "message", "User not found."));
196196

@@ -214,14 +214,14 @@ public ResponseEntity<?> setUserTier(@PathVariable String username, @RequestPara
214214
}
215215
}
216216

217-
@PostMapping("/users/{username}/role")
218-
public ResponseEntity<?> addUserRole(@PathVariable String username, @RequestParam String role) {
217+
@PostMapping("/users/{userId}/role")
218+
public ResponseEntity<?> addUserRole(@PathVariable String userId, @RequestParam String role) {
219219
User currentUser = getSafeUser();
220220
if (!accessControlService.isSuperAdmin(currentUser)) {
221221
return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Only Super Admin can manage roles.");
222222
}
223223

224-
User target = userRepository.findByUsernameIgnoreCase(username).orElse(null);
224+
User target = userRepository.findById(userId).orElse(null);
225225
if (target == null) return ResponseEntity.notFound().build();
226226

227227
if (target.getRoles() == null) target.setRoles(new ArrayList<>());
@@ -233,14 +233,14 @@ public ResponseEntity<?> addUserRole(@PathVariable String username, @RequestPara
233233
return ResponseEntity.ok().build();
234234
}
235235

236-
@DeleteMapping("/users/{username}/role")
237-
public ResponseEntity<?> removeUserRole(@PathVariable String username, @RequestParam String role) {
236+
@DeleteMapping("/users/{userId}/role")
237+
public ResponseEntity<?> removeUserRole(@PathVariable String userId, @RequestParam String role) {
238238
User currentUser = getSafeUser();
239239
if (!accessControlService.isSuperAdmin(currentUser)) {
240240
return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Only Super Admin can manage roles.");
241241
}
242242

243-
User target = userRepository.findByUsernameIgnoreCase(username).orElse(null);
243+
User target = userRepository.findById(userId).orElse(null);
244244
if (target == null) return ResponseEntity.notFound().build();
245245

246246
if (target.getRoles() != null) {

backend/src/main/java/net/modtale/controller/analytics/AnalyticsController.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
import net.modtale.service.security.AccessControlService;
1313
import net.modtale.service.user.AccountService;
1414
import org.springframework.beans.factory.annotation.Autowired;
15-
import org.springframework.data.mongodb.core.MongoTemplate;
16-
import org.springframework.data.mongodb.core.query.Criteria;
17-
import org.springframework.data.mongodb.core.query.Query;
1815
import org.springframework.http.CacheControl;
1916
import org.springframework.http.HttpStatus;
2017
import org.springframework.http.ResponseEntity;
@@ -24,7 +21,6 @@
2421
import java.time.LocalDateTime;
2522
import java.util.List;
2623
import java.util.concurrent.TimeUnit;
27-
import java.util.regex.Pattern;
2824

2925
@RestController
3026
@RequestMapping("/api/v1")
@@ -35,7 +31,6 @@ public class AnalyticsController {
3531
@Autowired private AccountService accountService;
3632
@Autowired private ProjectService projectService;
3733
@Autowired private AccessControlService accessControlService;
38-
@Autowired private MongoTemplate mongoTemplate;
3934

4035
private String getClientIp(HttpServletRequest request) {
4136
String xfHeader = request.getHeader("X-Forwarded-For");
@@ -51,15 +46,15 @@ private long getSecondsUntilMidnight() {
5146
public ResponseEntity<?> getCreatorAnalytics(
5247
@RequestParam(defaultValue = "30d") String range,
5348
@RequestParam(required = false) List<String> include,
54-
@RequestParam(required = false) String username
49+
@RequestParam(required = false) String userId
5550
) {
5651
User currentUser = accountService.getCurrentUser();
5752
if (currentUser == null) return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
5853

5954
String resolvedTargetId = currentUser.getId();
6055

61-
if (username != null && !username.isEmpty() && !username.equalsIgnoreCase(currentUser.getUsername())) {
62-
User target = mongoTemplate.findOne(new Query(Criteria.where("username").regex("^" + Pattern.quote(username) + "$", "i")), User.class);
56+
if (userId != null && !userId.isEmpty() && !userId.equals(currentUser.getId())) {
57+
User target = accountService.getPublicProfile(userId);
6358
if (target == null) return ResponseEntity.notFound().build();
6459

6560
if (target.getAccountType() == User.AccountType.ORGANIZATION) {

backend/src/main/java/net/modtale/controller/project/ProjectController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public ResponseEntity<GameVersionService.GameVersionCatalog> getGameVersionCatal
118118
}
119119

120120
@PostMapping("/projects")
121-
@PreAuthorize("@apiSecurity.hasCreateProjectPerm(#owner, authentication)")
121+
@PreAuthorize("@apiSecurity.hasCreateProjectPerm(#requestPayload.owner, authentication)")
122122
public ResponseEntity<?> createProject(@ModelAttribute CreateProjectRequest requestPayload) {
123123
User user = accountService.getCurrentUser();
124124
if (user == null) return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();

backend/src/main/java/net/modtale/controller/system/SitemapController.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.modtale.model.project.Project;
44
import net.modtale.service.project.SearchService;
5+
import net.modtale.service.project.ProjectService;
56
import org.springframework.beans.factory.annotation.Autowired;
67
import org.springframework.beans.factory.annotation.Value;
78
import org.springframework.http.MediaType;
@@ -18,6 +19,7 @@
1819
public class SitemapController {
1920

2021
@Autowired private SearchService searchService;
22+
@Autowired private ProjectService projectService;
2123

2224
@Value("${app.frontend.url:https://modtale.net}")
2325
private String baseUrl;
@@ -42,15 +44,11 @@ public String generateSitemap() {
4244
List<Project> projects = searchService.getPublishedProjects();
4345

4446
for (Project p : projects) {
45-
String prefix = "/mod/";
46-
if ("MODPACK".equals(p.getClassification())) prefix = "/modpack/";
47-
else if ("SAVE".equals(p.getClassification())) prefix = "/world/";
48-
49-
String slug = (p.getSlug() != null && !p.getSlug().isBlank()) ? p.getSlug() : createSlug(p.getTitle(), p.getId());
50-
5147
if (p.getUpdatedAt() != null) {
52-
addUrl(xml, baseUrl + prefix + slug, "0.8", parseDate(p.getUpdatedAt()));
53-
activeAuthors.add(p.getAuthor());
48+
addUrl(xml, baseUrl + projectService.getProjectLink(p), "0.8", parseDate(p.getUpdatedAt()));
49+
if (p.getAuthorId() != null && !p.getAuthorId().isBlank()) {
50+
activeAuthors.add(p.getAuthorId());
51+
}
5452
}
5553
}
5654

@@ -80,13 +78,4 @@ private LocalDate parseDate(String dateStr) {
8078
return LocalDate.now();
8179
}
8280
}
83-
84-
private String createSlug(String title, String id) {
85-
if (title == null) return id;
86-
String slug = title.toLowerCase()
87-
.replaceAll("[^a-z0-9]+", "-")
88-
.replaceAll("(^-|-$)", "");
89-
if (slug.length() > 30) slug = slug.substring(0, 30);
90-
return slug.isEmpty() ? id : slug + "-" + id;
91-
}
92-
}
81+
}

backend/src/main/java/net/modtale/controller/user/UserController.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
import org.springframework.web.multipart.MultipartFile;
3636

3737
import java.util.List;
38-
import java.util.Map;
39-
import java.util.Optional;
4038
import java.util.stream.Collectors;
4139

4240
@RestController
@@ -73,13 +71,6 @@ public ResponseEntity<List<UserSummaryDTO>> getUsersBatch(@RequestBody UsersBatc
7371
.collect(Collectors.toList()));
7472
}
7573

76-
@GetMapping("/users/lookup/{username}")
77-
public ResponseEntity<Map<String, String>> lookupUserId(@PathVariable String username) {
78-
Optional<User> target = userRepository.findByUsernameIgnoreCase(username);
79-
if (target.isEmpty()) return ResponseEntity.notFound().build();
80-
return ResponseEntity.ok(Map.of("id", target.get().getId()));
81-
}
82-
8374
@GetMapping("/user/me")
8475
@PreAuthorize("@apiSecurity.hasPersonalPerm('PROFILE_READ', authentication)")
8576
public ResponseEntity<UserDTO> getCurrentUser() {

backend/src/main/java/net/modtale/mapper/ProjectMapper.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public static AdminProjectDTO toAdminDTO(Project project) {
9191
project.getExpiresAt(),
9292
project.getDeletedAt(),
9393
project.getApprovedBy(),
94-
project.getContributors(),
9594
project.getGalleryImages(),
9695
project.getProjectRoles(),
9796
project.getTeamMembers(),
@@ -148,8 +147,6 @@ public static ProjectDTO toDTO(Project project, boolean isSummary, String curren
148147
dto.setProjectRoles(project.getProjectRoles());
149148
dto.setTeamMembers(project.getTeamMembers());
150149
dto.setTeamInvites(project.getTeamInvites());
151-
152-
dto.setContributors(project.getContributors());
153150
dto.setGalleryImages(project.getGalleryImages());
154151
dto.setComments(project.getComments() != null
155152
? project.getComments().stream()

backend/src/main/java/net/modtale/model/dto/admin/AdminProjectDTO.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public record AdminProjectDTO(
3939
String expiresAt,
4040
LocalDateTime deletedAt,
4141
String approvedBy,
42-
List<String> contributors,
4342
List<String> galleryImages,
4443
List<Project.ProjectRole> projectRoles,
4544
List<Project.ProjectMember> teamMembers,

backend/src/main/java/net/modtale/model/dto/project/ProjectDTO.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ public class ProjectDTO {
4747
private List<Project.ProjectMember> teamMembers;
4848
private List<Project.ProjectMember> teamInvites;
4949

50-
private List<String> contributors;
51-
5250
private List<String> galleryImages;
5351
private List<ProjectCommentDTO> comments;
5452
private List<ProjectVersionDTO> versions;
@@ -127,8 +125,6 @@ public class ProjectDTO {
127125
public List<Project.ProjectMember> getTeamInvites() { return teamInvites; }
128126
public void setTeamInvites(List<Project.ProjectMember> teamInvites) { this.teamInvites = teamInvites; }
129127

130-
public List<String> getContributors() { return contributors; }
131-
public void setContributors(List<String> contributors) { this.contributors = contributors; }
132128
public List<String> getGalleryImages() { return galleryImages; }
133129
public void setGalleryImages(List<String> galleryImages) { this.galleryImages = galleryImages; }
134130
public List<ProjectCommentDTO> getComments() { return comments; }

backend/src/main/java/net/modtale/model/project/Project.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ public ProjectMember(String userId, String roleId) {
139139

140140
private String approvedBy;
141141

142-
private List<String> contributors = new ArrayList<>();
143-
private List<String> pendingInvites = new ArrayList<>();
144-
145142
private List<ProjectRole> projectRoles = new ArrayList<>();
146143
private List<ProjectMember> teamMembers = new ArrayList<>();
147144
private List<ProjectMember> teamInvites = new ArrayList<>();
@@ -233,11 +230,6 @@ public Project() {}
233230
public String getApprovedBy() { return approvedBy; }
234231
public void setApprovedBy(String approvedBy) { this.approvedBy = approvedBy; }
235232

236-
public List<String> getContributors() { return contributors; }
237-
public void setContributors(List<String> contributors) { this.contributors = contributors; }
238-
public List<String> getPendingInvites() { return pendingInvites; }
239-
public void setPendingInvites(List<String> pendingInvites) { this.pendingInvites = pendingInvites; }
240-
241233
public List<ProjectRole> getProjectRoles() { return projectRoles; }
242234
public void setProjectRoles(List<ProjectRole> projectRoles) { this.projectRoles = projectRoles; }
243235
public List<ProjectMember> getTeamMembers() { return teamMembers; }
@@ -259,4 +251,4 @@ public Project() {}
259251
public void setCanEdit(boolean canEdit) { this.canEdit = canEdit; }
260252
public boolean isOwner() { return isOwner; }
261253
public void setIsOwner(boolean isOwner) { this.isOwner = isOwner; }
262-
}
254+
}

0 commit comments

Comments
 (0)