@@ -59,6 +59,21 @@ public class FileInfoUserResponse {
|
||||
@JsonProperty("audios_violations")
|
||||
private Integer audiosViolations;
|
||||
|
||||
@JsonProperty("document_size")
|
||||
private Long documentSize;
|
||||
|
||||
@JsonProperty("document_quantity")
|
||||
private Integer documentCount;
|
||||
|
||||
@JsonProperty("document_check")
|
||||
private Integer documentCheck;
|
||||
|
||||
@JsonProperty("document_violations")
|
||||
private Integer documentViolations;
|
||||
|
||||
@JsonProperty("protected_document_files_count")
|
||||
private Long protectedDocumentFilesCount;
|
||||
|
||||
@JsonProperty("protected_files_count")
|
||||
private Long protectedFilesCount;
|
||||
|
||||
|
||||
@@ -7,11 +7,12 @@ import java.util.List;
|
||||
|
||||
@Getter
|
||||
public enum FileType {
|
||||
// IMAGE("image", Arrays.asList("jpg", "jpeg", "png", "gif", "bmp", "webp", "jfif")),
|
||||
IMAGE("image", Arrays.asList("jpg", "jpeg", "png", "gif", "bmp")),
|
||||
VIDEO("video", Arrays.asList("mp4", "avi", "mov", "wmv", "flv", "mkv", "webm", "m4v", "mpg", "mpeg",
|
||||
"3gp", "3g2", "f4v", "m2ts", "mts", "vob", "ogv", "divx")),
|
||||
AUDIO("audio", List.of("wav"));
|
||||
AUDIO("audio", List.of("wav")),
|
||||
DOCUMENT("document", Arrays.asList("pdf", "txt", "doc", "docx"));
|
||||
|
||||
|
||||
private final String displayName;
|
||||
private final List<String> allowedExtensions;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package ru.soune.nocopy.exception;
|
||||
|
||||
public class MaxUserCountIsOver extends RuntimeException {
|
||||
public MaxUserCountIsOver(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,12 @@ public class FileStatsService {
|
||||
.audiosCheck(calculateMediaByStatus(files, FileType.AUDIO, FileStatus.CHECKED))
|
||||
.audiosViolations(calculateMediaByStatus(files, FileType.AUDIO, FileStatus.VIOLATION))
|
||||
.protectedAudioFilesCount(protectedUserFiles(files, FileType.AUDIO))
|
||||
|
||||
.documentSize(calculateMediaSize(files, FileType.DOCUMENT))
|
||||
.documentCount(calculateMediaCount(files, FileType.DOCUMENT))
|
||||
.documentCheck(calculateMediaByStatus(files, FileType.DOCUMENT, FileStatus.CHECKED))
|
||||
.documentViolations(calculateMediaByStatus(files, FileType.DOCUMENT, FileStatus.VIOLATION))
|
||||
.protectedDocumentFilesCount(protectedUserFiles(files, FileType.DOCUMENT))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -382,7 +382,7 @@ public class FileUploadServiceImpl implements FileUploadService {
|
||||
return TariffConstants.IMAGE_TOKEN_VALUE;
|
||||
case "audio":
|
||||
return TariffConstants.AUDIO_TOKEN_VALUE;
|
||||
case "pdf":
|
||||
case "document":
|
||||
return TariffConstants.PDF_TOKEN_VALUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ru.soune.nocopy.service.register;
|
||||
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -10,11 +11,13 @@ import ru.soune.nocopy.dto.register.LoginAnswer;
|
||||
import ru.soune.nocopy.dto.register.LoginRequest;
|
||||
import ru.soune.nocopy.dto.register.RegRequest;
|
||||
import ru.soune.nocopy.entity.company.Company;
|
||||
import ru.soune.nocopy.entity.tarif.Tariff;
|
||||
import ru.soune.nocopy.entity.tarif.TariffInfo;
|
||||
import ru.soune.nocopy.entity.tarif.TariffType;
|
||||
import ru.soune.nocopy.entity.user.AuthToken;
|
||||
import ru.soune.nocopy.entity.user.Permission;
|
||||
import ru.soune.nocopy.entity.user.User;
|
||||
import ru.soune.nocopy.exception.MaxUserCountIsOver;
|
||||
import ru.soune.nocopy.exception.NotFoundAuthToken;
|
||||
import ru.soune.nocopy.exception.NotValidFieldException;
|
||||
import ru.soune.nocopy.repository.AuthTokenRepository;
|
||||
@@ -176,20 +179,29 @@ public class AuthService {
|
||||
private void createIndividualCompanyAccount(RegRequest request, User user) {
|
||||
String authToken = request.getAuthToken();
|
||||
Long userIdByToken = authTokenRepository.findUserIdByToken(authToken);
|
||||
User companyUser = userRepository.findById(userIdByToken).orElseThrow();
|
||||
User companyUser = userRepository.findById(userIdByToken)
|
||||
.orElseThrow(() -> new EntityNotFoundException("Not found token: " + authToken));
|
||||
|
||||
Company company = companyUser.getCompany();
|
||||
TariffInfo tariffInfo = company.getTariffInfo();
|
||||
|
||||
Long maxUsers = tariffInfo.getTariff().getMaxUsers();
|
||||
long currentCountUsers = userRepository.countByCompanyId(company.getId());
|
||||
|
||||
//TODO add exception
|
||||
if (currentCountUsers < maxUsers) {
|
||||
throw new RuntimeException();
|
||||
if (company == null) {
|
||||
throw new IllegalStateException("Not have company");
|
||||
}
|
||||
|
||||
user.setCompany(companyUser.getCompany());
|
||||
TariffInfo tariffInfo = company.getTariffInfo();
|
||||
if (tariffInfo == null) {
|
||||
throw new IllegalStateException("Company not have tariff");
|
||||
}
|
||||
|
||||
Tariff tariff = tariffInfo.getTariff();
|
||||
Long maxUsers = tariff.getMaxUsers();
|
||||
long currentCountUsers = userRepository.countByCompanyId(company.getId());
|
||||
|
||||
if (currentCountUsers >= maxUsers) {
|
||||
throw new MaxUserCountIsOver(
|
||||
String.format("Max user is over. " + "Has: %d, current count: %d", maxUsers, currentCountUsers));
|
||||
}
|
||||
|
||||
user.setCompany(company);
|
||||
user.grantPermission(Permission.DEFAULT_USER_PERMISSIONS);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user