This commit is contained in:
@@ -391,6 +391,18 @@ public class ApiController {
|
|||||||
|
|
||||||
Long userId = authService.useUserAuthToken(tokenHeader);
|
Long userId = authService.useUserAuthToken(tokenHeader);
|
||||||
FileEntityResponse entityResponse = fileEntityService.getById(fileId, version);
|
FileEntityResponse entityResponse = fileEntityService.getById(fileId, version);
|
||||||
|
FileStatus status = entityResponse.getStatus();
|
||||||
|
|
||||||
|
if (status.equals(FileStatus.BLOCKED) || status.equals(FileStatus.DELETED) ||
|
||||||
|
status.equals(FileStatus.REMOVED)) {
|
||||||
|
Map<String, Object> errorData = new HashMap<>();
|
||||||
|
errorData.put("fileId", entityResponse.getId());
|
||||||
|
|
||||||
|
return ResponseEntity.ok().body(new BaseResponse(20004,
|
||||||
|
MessageCode.FILE_IS_BLOCKED.getCode(),
|
||||||
|
MessageCode.FILE_IS_BLOCKED.getDescription(),
|
||||||
|
errorData));
|
||||||
|
}
|
||||||
|
|
||||||
User fileUser = userRepository.findById(entityResponse.getUserId()).orElseThrow();
|
User fileUser = userRepository.findById(entityResponse.getUserId()).orElseThrow();
|
||||||
User user = userRepository.findById(userId).orElseThrow();
|
User user = userRepository.findById(userId).orElseThrow();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ public enum MessageCode {
|
|||||||
REG_EMAIL_EXISTS(1, "Email already registered"),
|
REG_EMAIL_EXISTS(1, "Email already registered"),
|
||||||
REG_EMAIL_OR_PHONE_EXISTS(1, "Email or phone already registered"),
|
REG_EMAIL_OR_PHONE_EXISTS(1, "Email or phone already registered"),
|
||||||
REFERRAL_LINK_IS_NOT_EXIST(1, "Refferal link is not exist"),
|
REFERRAL_LINK_IS_NOT_EXIST(1, "Refferal link is not exist"),
|
||||||
|
FILE_IS_BLOCKED(1, "File is blocked,deleted or removed"),
|
||||||
INVALID_FIELD(2, "Invalid field"),
|
INVALID_FIELD(2, "Invalid field"),
|
||||||
MAIL_VERIFIED_NULL(2, "Mail verified null"),
|
MAIL_VERIFIED_NULL(2, "Mail verified null"),
|
||||||
INVALID_TOKEN(2, "Token not found or time expired"),
|
INVALID_TOKEN(2, "Token not found or time expired"),
|
||||||
|
|||||||
@@ -33,4 +33,7 @@ public class ComplaintResponse {
|
|||||||
|
|
||||||
@JsonProperty("updated_at")
|
@JsonProperty("updated_at")
|
||||||
private String updatedAt;
|
private String updatedAt;
|
||||||
|
|
||||||
|
@JsonProperty("not_moderated")
|
||||||
|
private Boolean notModerated;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,4 +20,5 @@ public class SimilarFileDTO {
|
|||||||
LocalDateTime uploadDate;
|
LocalDateTime uploadDate;
|
||||||
String url;
|
String url;
|
||||||
Boolean owner;
|
Boolean owner;
|
||||||
|
String fileStatus;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,4 +52,7 @@ public class ComplaintEntity {
|
|||||||
@Column(name = "updated_at")
|
@Column(name = "updated_at")
|
||||||
@LastModifiedDate
|
@LastModifiedDate
|
||||||
private LocalDateTime updatedAt;
|
private LocalDateTime updatedAt;
|
||||||
|
|
||||||
|
@Column(name = "not_moderated_file")
|
||||||
|
private Boolean not_moderated_file;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,6 +87,9 @@ public class FileEntity {
|
|||||||
@Column(name = "medium_path")
|
@Column(name = "medium_path")
|
||||||
private String mediumPath;
|
private String mediumPath;
|
||||||
|
|
||||||
|
@Column(name = "moderation_reason_id")
|
||||||
|
private Long moderationReasonId;
|
||||||
|
|
||||||
@OneToOne(mappedBy = "file", cascade = CascadeType.ALL, orphanRemoval = true)
|
@OneToOne(mappedBy = "file", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private ImageHashEntity imageHash;
|
private ImageHashEntity imageHash;
|
||||||
|
|||||||
@@ -7,5 +7,8 @@ public enum FileStatus {
|
|||||||
VIOLATION,
|
VIOLATION,
|
||||||
CHECKED,
|
CHECKED,
|
||||||
ERROR,
|
ERROR,
|
||||||
TEMP
|
TEMP,
|
||||||
|
REMOVED,
|
||||||
|
MODERATION,
|
||||||
|
BLOCKED
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package ru.soune.nocopy.entity.file.moderation;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
import org.springframework.data.annotation.CreatedDate;
|
||||||
|
import org.springframework.data.annotation.LastModifiedDate;
|
||||||
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "moderation_reasons")
|
||||||
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
|
public class ModerationReason {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "reason_text", nullable = false, columnDefinition = "TEXT")
|
||||||
|
private String reasonText;
|
||||||
|
|
||||||
|
@CreatedDate
|
||||||
|
@Column(name = "created_at", updatable = false)
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
@LastModifiedDate
|
||||||
|
@Column(name = "updated_at")
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
}
|
||||||
@@ -63,6 +63,7 @@ public class ComplaintEntityHandler implements RequestHandler {
|
|||||||
"text is required");
|
"text is required");
|
||||||
|
|
||||||
ComplaintResponse response = complaintService.createComplaint(req);
|
ComplaintResponse response = complaintService.createComplaint(req);
|
||||||
|
|
||||||
return successResponse(msgId, "Complaint created successfully", response);
|
return successResponse(msgId, "Complaint created successfully", response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +118,7 @@ public class ComplaintEntityHandler implements RequestHandler {
|
|||||||
if (req.getId() == null) return errorResponse(msgId, MessageCode.NOT_FOUND.getCode(), "id is required");
|
if (req.getId() == null) return errorResponse(msgId, MessageCode.NOT_FOUND.getCode(), "id is required");
|
||||||
|
|
||||||
ComplaintResponse response = complaintService.updateComplaint(req.getId(), req);
|
ComplaintResponse response = complaintService.updateComplaint(req.getId(), req);
|
||||||
|
|
||||||
return successResponse(msgId, "Complaint updated successfully", response);
|
return successResponse(msgId, "Complaint updated successfully", response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public interface ImageSimilarityRepository
|
|||||||
f.created_at AS uploadDate,
|
f.created_at AS uploadDate,
|
||||||
f.protection_status AS protectionStatus,
|
f.protection_status AS protectionStatus,
|
||||||
f.file_extension AS extension,
|
f.file_extension AS extension,
|
||||||
|
f.status AS status,
|
||||||
h.hash64_hi AS hash64Hi,
|
h.hash64_hi AS hash64Hi,
|
||||||
h.hash64_lo AS hash64Lo
|
h.hash64_lo AS hash64Lo
|
||||||
FROM image_hashes ref
|
FROM image_hashes ref
|
||||||
|
|||||||
@@ -15,4 +15,5 @@ public interface SimilarImageProjection {
|
|||||||
LocalDateTime getUploadDate();
|
LocalDateTime getUploadDate();
|
||||||
ProtectionStatus getProtectionStatus();
|
ProtectionStatus getProtectionStatus();
|
||||||
String getExtension();
|
String getExtension();
|
||||||
|
String getFileStatus();
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import ru.soune.nocopy.dto.file.SimilarFileDTO;
|
import ru.soune.nocopy.dto.file.SimilarFileDTO;
|
||||||
import ru.soune.nocopy.entity.company.Company;
|
import ru.soune.nocopy.entity.company.Company;
|
||||||
import ru.soune.nocopy.entity.file.FileEntity;
|
import ru.soune.nocopy.entity.file.FileEntity;
|
||||||
|
import ru.soune.nocopy.entity.file.FileStatus;
|
||||||
import ru.soune.nocopy.entity.file.ImageHashEntity;
|
import ru.soune.nocopy.entity.file.ImageHashEntity;
|
||||||
import ru.soune.nocopy.entity.user.User;
|
import ru.soune.nocopy.entity.user.User;
|
||||||
import ru.soune.nocopy.exception.DuplicateImageException;
|
import ru.soune.nocopy.exception.DuplicateImageException;
|
||||||
@@ -154,22 +155,19 @@ public class FileSimilarityService {
|
|||||||
var imageHashEntity = hashRepository.findById(fileId)
|
var imageHashEntity = hashRepository.findById(fileId)
|
||||||
.orElseThrow(() -> new RuntimeException("Hash not found for file: " + fileId));
|
.orElseThrow(() -> new RuntimeException("Hash not found for file: " + fileId));
|
||||||
|
|
||||||
List<SimilarImageProjection> candidates;
|
|
||||||
List<Long> userIds;
|
List<Long> userIds;
|
||||||
// if (authToken == null || "all".equals(authToken)) {
|
List<SimilarImageProjection> candidates = repository.findCandidates(fileId);
|
||||||
candidates = repository.findCandidates(fileId);
|
|
||||||
// } else {
|
Long userId = authTokenRepository.findUserIdByToken(authToken);
|
||||||
Long userId = authTokenRepository.findUserIdByToken(authToken);
|
User user = userRepository.findById(userId).orElseThrow(() -> new RuntimeException("User not found"));
|
||||||
User user = userRepository.findById(userId).orElseThrow(() -> new RuntimeException("User not found"));
|
Company company = user.getCompany();
|
||||||
Company company = user.getCompany();
|
|
||||||
if (company != null) {
|
if (company != null) {
|
||||||
userIds = company.getUsers().stream().map(User::getId).collect(Collectors.toList());
|
userIds = company.getUsers().stream().map(User::getId).collect(Collectors.toList());
|
||||||
// candidates = repository.findCandidatesFromUserFiles(fileId, userIds);
|
} else {
|
||||||
} else {
|
userIds = List.of(userId);
|
||||||
userIds = List.of(userId);
|
}
|
||||||
// candidates = repository.findCandidatesFromUserFiles(fileId, userId);
|
|
||||||
}
|
|
||||||
// }
|
|
||||||
|
|
||||||
List<String> levels = (similarityLevels != null && !similarityLevels.isEmpty())
|
List<String> levels = (similarityLevels != null && !similarityLevels.isEmpty())
|
||||||
? similarityLevels
|
? similarityLevels
|
||||||
@@ -180,6 +178,7 @@ public class FileSimilarityService {
|
|||||||
imageHashEntity.getHash64Hi(),
|
imageHashEntity.getHash64Hi(),
|
||||||
imageHashEntity.getHash64Lo(), userIds))
|
imageHashEntity.getHash64Lo(), userIds))
|
||||||
.filter(dto -> levels.contains(dto.getSimilarityLevel()))
|
.filter(dto -> levels.contains(dto.getSimilarityLevel()))
|
||||||
|
.filter(dto -> dto.getFileStatus().equals(FileStatus.ACTIVE.name()))
|
||||||
.sorted(Comparator.comparingInt(SimilarFileDTO::getHammingDistance))
|
.sorted(Comparator.comparingInt(SimilarFileDTO::getHammingDistance))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
@@ -243,6 +242,7 @@ public class FileSimilarityService {
|
|||||||
.owner(userIds.contains(similarImageProjection.getUserId()))
|
.owner(userIds.contains(similarImageProjection.getUserId()))
|
||||||
// .url(baseUrl + "/api/files/protected/" + similarImageProjection.getId())
|
// .url(baseUrl + "/api/files/protected/" + similarImageProjection.getId())
|
||||||
.url(baseUrl + "/api/files/protected/" + similarImageProjection.getId() + "/thumbnail")
|
.url(baseUrl + "/api/files/protected/" + similarImageProjection.getId() + "/thumbnail")
|
||||||
|
.fileStatus(similarImageProjection.getFileStatus())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import ru.soune.nocopy.dto.complaint.ComplaintRequest;
|
|||||||
import ru.soune.nocopy.dto.complaint.ComplaintResponse;
|
import ru.soune.nocopy.dto.complaint.ComplaintResponse;
|
||||||
import ru.soune.nocopy.entity.complaint.ComplaintEntity;
|
import ru.soune.nocopy.entity.complaint.ComplaintEntity;
|
||||||
import ru.soune.nocopy.entity.complaint.ComplaintStatus;
|
import ru.soune.nocopy.entity.complaint.ComplaintStatus;
|
||||||
|
import ru.soune.nocopy.entity.file.FileStatus;
|
||||||
import ru.soune.nocopy.entity.violation.Violation;
|
import ru.soune.nocopy.entity.violation.Violation;
|
||||||
import ru.soune.nocopy.exception.ComplaintNotFoundException;
|
import ru.soune.nocopy.exception.ComplaintNotFoundException;
|
||||||
import ru.soune.nocopy.exception.DuplicateComplaintException;
|
import ru.soune.nocopy.exception.DuplicateComplaintException;
|
||||||
@@ -32,8 +33,6 @@ public class ComplaintEntityService {
|
|||||||
|
|
||||||
private final ViolationRepository violationRepository;
|
private final ViolationRepository violationRepository;
|
||||||
|
|
||||||
private final ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
public ComplaintResponse createComplaint(ComplaintRequest request) {
|
public ComplaintResponse createComplaint(ComplaintRequest request) {
|
||||||
@@ -49,6 +48,7 @@ public class ComplaintEntityService {
|
|||||||
.complaintText(request.getComplaintText())
|
.complaintText(request.getComplaintText())
|
||||||
.email(request.getEmail())
|
.email(request.getEmail())
|
||||||
.violation(violation)
|
.violation(violation)
|
||||||
|
.not_moderated_file(violation.getFileEntity().getStatus().equals(FileStatus.MODERATION))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return mapToResponse(complaintRepository.save(complaint));
|
return mapToResponse(complaintRepository.save(complaint));
|
||||||
@@ -116,6 +116,7 @@ public class ComplaintEntityService {
|
|||||||
.violationId(entity.getViolation() != null ? entity.getViolation().getId() : null)
|
.violationId(entity.getViolation() != null ? entity.getViolation().getId() : null)
|
||||||
.createdAt(entity.getCreatedAt() != null ? entity.getCreatedAt().format(DATE_FORMATTER) : null)
|
.createdAt(entity.getCreatedAt() != null ? entity.getCreatedAt().format(DATE_FORMATTER) : null)
|
||||||
.updatedAt(entity.getUpdatedAt() != null ? entity.getUpdatedAt().format(DATE_FORMATTER) : null)
|
.updatedAt(entity.getUpdatedAt() != null ? entity.getUpdatedAt().format(DATE_FORMATTER) : null)
|
||||||
|
.notModerated(entity.getNot_moderated_file() != null ? entity.getNot_moderated_file() : null)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user