updated code for PreAuthorize role

This commit is contained in:
rajesh
2024-08-23 11:50:58 +05:30
parent 28045c1de0
commit b6692e206d
18 changed files with 71 additions and 68 deletions

View File

@@ -19,6 +19,7 @@ import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationExceptio
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import net.gepafin.tendermanagement.entities.LookUpDataEntity.LookUpDataTypeEnum;

View File

@@ -45,6 +45,7 @@ public class RoleDao {
private RoleEntity convertRoleRequestToRoleEntity(RoleReq roleReq) {
RoleEntity roleEntity = new RoleEntity();
roleEntity.setRoleName(roleReq.getRoleName());
roleEntity.setRoleType(roleReq.getRoleType());
roleEntity.setPermissions(roleReq.getPermissions());
roleEntity.setDescription(roleReq.getDescription());
roleEntity.setRegion(regionService.getRegionById(roleReq.getRegionId()));
@@ -57,6 +58,7 @@ public class RoleDao {
roleResponseBean.setCreatedDate(roleEntity.getCreatedDate());
roleResponseBean.setUpdatedDate(roleEntity.getUpdatedDate());
roleResponseBean.setRoleName(roleEntity.getRoleName());
roleResponseBean.setRoleType(roleEntity.getRoleType());
roleResponseBean.setDescription(roleEntity.getDescription());
roleResponseBean.setPermissions(roleEntity.getPermissions());
RegionResponseBean regionResponseBean = regionDao.convertRegionEntityToRegionResponse(roleEntity.getRegion());
@@ -73,6 +75,7 @@ public class RoleDao {
log.info("New role details: {}", roleReq);
setIfUpdated(existingRole::getRoleName, existingRole::setRoleName, roleReq.getRoleName());
setIfUpdated(existingRole::getRoleType, existingRole::setRoleType, roleReq.getRoleType());
setIfUpdated(existingRole::getDescription, existingRole::setDescription, roleReq.getDescription());
setIfUpdated(existingRole::getPermissions, existingRole::setPermissions, roleReq.getPermissions());

View File

@@ -47,7 +47,7 @@ public class UserDao {
public UserResponseBean createUser(UserReq userReq) {
log.info("Creating user with email: {}", userReq.getEmail());
if (userRepository.existsByEmail(userReq.getEmail())) {
if (userRepository.existsByEmailIgnoreCase(userReq.getEmail())) {
log.error("User creation failed: Email {} already exists", userReq.getEmail());
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
}
@@ -94,7 +94,7 @@ public class UserDao {
userEntity.setPassword(passwordEncoder.encode(userReq.getPassword()));
userEntity.setEmail(userReq.getEmail());
userEntity.setFirstName(userReq.getFirstName());
userEntity.setStatus(userReq.getStatus().getValue());
userEntity.setStatus(UserStatusEnum.PENDING_VERIFICATION.getValue());
userEntity.setLastName(userReq.getLastName());
userEntity.setOrganization(userReq.getOrganization());
userEntity.setAddress(userReq.getAddress());
@@ -127,10 +127,10 @@ public class UserDao {
log.info("Fetching user with ID: {}", id);
UserEntity userEntity = userRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
if (!UserStatusEnum.ACTIVE.getValue().equals(userEntity.getStatus())) {
log.info("User with ID: {} is not active", id);
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG));
}
// if (!UserStatusEnum.ACTIVE.getValue().equals(userEntity.getStatus())) {
// log.info("User with ID: {} is not active", id);
// throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG));
// }
log.info("User found: {}", userEntity);
return convertUserEntityToUserResponse(userEntity);
}