Compare commits
5 Commits
f579af11a7
...
feature/au
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39d75aecf9 | ||
|
|
6949d8e083 | ||
|
|
db27bcc1f7 | ||
|
|
e0807e4539 | ||
|
|
fbdaa35087 |
@@ -6,5 +6,9 @@ cd ..
|
||||
cd huertos/
|
||||
mvn clean package
|
||||
cd ..
|
||||
cd mpaste/
|
||||
mvn clean package
|
||||
cd ..
|
||||
scp core/target/core-1.0.0.jar jomaa@10.0.0.254:/home/jomaa/transfer
|
||||
scp huertos/target/huertos-1.0.0.jar jomaa@10.0.0.254:/home/jomaa/transfer
|
||||
scp mpaste/target/mpaste-1.0.0.jar jomaa@10.0.0.254:/home/jomaa/transfer
|
||||
@@ -44,14 +44,6 @@ public class CredentialController {
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping("/test/{userId}")
|
||||
public ResponseEntity<String> test(@PathVariable("userId") UUID userId) {
|
||||
CorePrincipal principal = (CorePrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
return ResponseEntity.ok(
|
||||
userId.equals(principal.getUserId()) ? "OK" : "NO"
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping("/user/{userId}")
|
||||
public ResponseEntity<List<CredentialDto>> getByUserId(@PathVariable("userId") UUID userId) {
|
||||
CorePrincipal principal = (CorePrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
@@ -90,6 +82,19 @@ public class CredentialController {
|
||||
);
|
||||
}
|
||||
|
||||
@PutMapping("/{credential_id}/full")
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public ResponseEntity<CredentialDto> updateFull(
|
||||
@PathVariable("credential_id") UUID credentialId,
|
||||
@RequestBody CredentialDto dto
|
||||
) {
|
||||
return ResponseEntity.ok(
|
||||
CredentialMapper.toDto(
|
||||
credentialService.update(credentialId, CredentialMapper.toEntity(dto))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping("/{service_id}/{user_id}/status")
|
||||
public ResponseEntity<Byte> getStatus(@PathVariable("user_id") UUID userId, @PathVariable("service_id") Byte serviceId) {
|
||||
return ResponseEntity.ok(credentialService.getStatus(userId, serviceId));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.miarma.backend.huertos.client;
|
||||
|
||||
import net.miarma.backend.huertos.dto.MemberDto;
|
||||
import net.miarma.backend.huertos.dto.RequestMetadataDto;
|
||||
import net.miarma.backend.huertos.model.RequestMetadata;
|
||||
import net.miarma.backend.huertos.util.UsernameGenerator;
|
||||
@@ -66,7 +67,6 @@ public class HuertosWebClient {
|
||||
}
|
||||
|
||||
public UserWithCredentialDto createUser(RequestMetadataDto metadataDto) {
|
||||
// 1. Crear el usuario
|
||||
CreateUserDto userDto = new CreateUserDto(metadataDto.displayName(), null);
|
||||
HttpEntity<CreateUserDto> userRequestEntity = new HttpEntity<>(userDto);
|
||||
|
||||
@@ -116,6 +116,34 @@ public class HuertosWebClient {
|
||||
return new UserWithCredentialDto(createdUser, createdCred);
|
||||
}
|
||||
|
||||
public void updateUser(UUID userId, UserWithCredentialDto dto) {
|
||||
HttpEntity<UserDto> userRequestEntity = new HttpEntity<>(dto.user());
|
||||
ResponseEntity<Void> userResponse = restTemplate.exchange(
|
||||
coreUrl + "/users/{user_id}",
|
||||
HttpMethod.PUT,
|
||||
userRequestEntity,
|
||||
Void.class,
|
||||
userId
|
||||
);
|
||||
|
||||
if (!userResponse.getStatusCode().is2xxSuccessful()) {
|
||||
handleError(userResponse);
|
||||
}
|
||||
|
||||
HttpEntity<CredentialDto> credRequestEntity = new HttpEntity<>(dto.account());
|
||||
ResponseEntity<Void> credResponse = restTemplate.exchange(
|
||||
coreUrl + "/credentials/{credential_id}/full",
|
||||
HttpMethod.PUT,
|
||||
credRequestEntity,
|
||||
Void.class,
|
||||
dto.account().getCredentialId()
|
||||
);
|
||||
|
||||
if (!credResponse.getStatusCode().is2xxSuccessful()) {
|
||||
handleError(credResponse);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteUser(UUID userId) {
|
||||
ResponseEntity<Void> response = restTemplate.exchange(
|
||||
coreUrl + "/users/{user_id}",
|
||||
|
||||
@@ -122,4 +122,13 @@ public class MemberController {
|
||||
public ResponseEntity<MemberDto> getByDni(@PathVariable("dni") String dni) {
|
||||
return ResponseEntity.ok(memberService.getByDni(dni));
|
||||
}
|
||||
|
||||
@PutMapping("/{user_id:[0-9a-fA-F\\-]{36}}")
|
||||
@PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')")
|
||||
public ResponseEntity<MemberDto> update(
|
||||
@PathVariable("user_id") UUID userId,
|
||||
@RequestBody MemberDto changes
|
||||
) {
|
||||
return ResponseEntity.ok(memberService.update(userId, changes));
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,13 @@
|
||||
import net.miarma.backend.huertos.mapper.UserMetadataMapper;
|
||||
import net.miarma.backend.huertos.mapper.IncomeMapper;
|
||||
import net.miarma.backend.huertos.mapper.view.VIncomesWithInfoMapper;
|
||||
import net.miarma.backend.huertos.model.UserMetadata;
|
||||
import net.miarma.backend.huertos.security.NameCensorer;
|
||||
import net.miarma.backlib.dto.CredentialDto;
|
||||
import net.miarma.backlib.dto.UserDto;
|
||||
import net.miarma.backlib.dto.UserWithCredentialDto;
|
||||
import net.miarma.backlib.exception.NotFoundException;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -199,4 +203,15 @@
|
||||
.map(DropdownDtoMapper::toDto)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@CacheEvict(value = "members", allEntries = true)
|
||||
public MemberDto update(UUID userId, MemberDto changes) {
|
||||
try {
|
||||
huertosWebClient.updateUser(userId, new UserWithCredentialDto(changes.user(), changes.account()));
|
||||
metadataService.update(userId, UserMetadataMapper.fromDto(changes.metadata()));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("No se pudo actualizar el socio");
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class UserMetadataService {
|
||||
if (changes.getType() != null) metadata.setType(changes.getType());
|
||||
if (changes.getRole() != null) metadata.setRole(changes.getRole());
|
||||
if (changes.getNotes() != null) metadata.setNotes(changes.getNotes());
|
||||
if (changes.getAssignedAt() != null) metadata.setAssignedAt(changes.getAssignedAt());
|
||||
metadata.setAssignedAt(changes.getAssignedAt());
|
||||
if (changes.getDeactivatedAt() != null) metadata.setDeactivatedAt(changes.getDeactivatedAt());
|
||||
|
||||
return repository.save(metadata);
|
||||
|
||||
@@ -36,14 +36,17 @@ public class PasteController {
|
||||
}
|
||||
|
||||
@GetMapping("/{paste_key}")
|
||||
public ResponseEntity<PasteDto.Response> getByKey(@PathVariable("paste_key") String pasteKey, @RequestBody PastePassword dto) {
|
||||
public ResponseEntity<PasteDto.Response> getByKey(
|
||||
@PathVariable("paste_key") String pasteKey,
|
||||
@RequestParam(value = "password", required = false) String password
|
||||
) {
|
||||
return ResponseEntity.ok(
|
||||
PasteMapper.toResponse(pasteService.getByKey(pasteKey, dto.password()))
|
||||
PasteMapper.toResponse(pasteService.getByKey(pasteKey, password))
|
||||
);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<PasteDto.Response> create(PasteDto.Request request) {
|
||||
public ResponseEntity<PasteDto.Response> create(@RequestBody PasteDto.Request request) {
|
||||
return ResponseEntity.ok(
|
||||
PasteMapper.toResponse(
|
||||
pasteService.create(
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Paste {
|
||||
@Transient
|
||||
private UUID ownerId;
|
||||
|
||||
@Column(name = "paste_key", updatable = false, insertable = false, unique = true, nullable = false)
|
||||
@Column(name = "paste_key", updatable = false, unique = true, nullable = false)
|
||||
private String pasteKey;
|
||||
|
||||
@Column(nullable = false)
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.miarma.backend.mpaste.service;
|
||||
import jakarta.transaction.Transactional;
|
||||
import net.miarma.backend.mpaste.model.Paste;
|
||||
import net.miarma.backend.mpaste.repository.PasteRepository;
|
||||
import net.miarma.backend.mpaste.util.PasteKeyGenerator;
|
||||
import net.miarma.backend.mpaste.validation.PasteValidator;
|
||||
import net.miarma.backlib.exception.ForbiddenException;
|
||||
import net.miarma.backlib.exception.NotFoundException;
|
||||
@@ -62,6 +63,8 @@ public class PasteService {
|
||||
|
||||
public Paste create(Paste paste) {
|
||||
PasteValidator.validate(paste);
|
||||
paste.setPasteId(UUID.randomUUID());
|
||||
paste.setPasteKey(PasteKeyGenerator.generate(6));
|
||||
return pasteRepository.save(paste);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user