Resolved Conflicts.
This commit is contained in:
@@ -664,7 +664,29 @@ public class Utils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// Method to convert a JSON string to an object of type T
|
||||
public static <T> T convertStringToObject(String jsonString, Class<T> clazz) {
|
||||
try {
|
||||
return mapper.readValue(jsonString, clazz);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// Handle the exception appropriately (e.g., throw a custom exception)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Method to convert an object of type T to a JSON string
|
||||
public static <T> String convertObjectToString(T object) {
|
||||
try {
|
||||
return mapper.writeValueAsString(object);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// Handle the exception appropriately (e.g., throw a custom exception)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String createChannelForUserAndCompany(Long userId, Long companyId) {
|
||||
return GepafinConstant.COMMON_SINGLE_CHANNEL_PREFIX + userId + GepafinConstant.COMPANY_PREFIX + companyId;
|
||||
}
|
||||
|
||||
@@ -90,6 +90,8 @@ public class Validator {
|
||||
validateHubId(request, companyEntity.getHub().getId());
|
||||
if (checkIsSuperAdmin()) {
|
||||
return companyEntity;
|
||||
} else if (checkIsInstructorManager()) {
|
||||
return companyEntity;
|
||||
}
|
||||
Map<String, Object> userInfo = tokenProvider.getUserInfoAndUserIdFromToken(request);
|
||||
companyService.validateUserWithCompny(getUserId(userInfo), companyId);
|
||||
@@ -105,7 +107,7 @@ public class Validator {
|
||||
}
|
||||
}
|
||||
|
||||
private Long getUserId(Map<String, Object> userInfo) {
|
||||
public Long getUserId(Map<String, Object> userInfo) {
|
||||
return Long.parseLong(userInfo.get("userId").toString());
|
||||
}
|
||||
|
||||
@@ -127,8 +129,11 @@ public class Validator {
|
||||
UserEntity requestedUser = userService.validateUser(userId);
|
||||
|
||||
validateHubId(request, requestedUser.getHub().getId());
|
||||
if (Boolean.FALSE.equals(user.getRoleEntity().getRoleType().equals(RoleStatusEnum.ROLE_SUPER_ADMIN.getValue()))
|
||||
&& Boolean.FALSE.equals(user.getId().equals(userId))) {
|
||||
// if (Boolean.FALSE.equals(user.getRoleEntity().getRoleType().equals(RoleStatusEnum.ROLE_SUPER_ADMIN.getValue()))
|
||||
// && Boolean.FALSE.equals(user.getId().equals(userId)))
|
||||
if (checkIsSuperAdmin() || checkIsInstructorManager()) {
|
||||
|
||||
} else if(Boolean.FALSE.equals(user.getId().equals(userId))) {
|
||||
throw new ForbiddenAccessException(Status.FORBIDDEN,
|
||||
Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
|
||||
}
|
||||
@@ -164,6 +169,11 @@ public class Validator {
|
||||
validateHubId(request, preInstructorUser.getHub().getId());
|
||||
}
|
||||
return preInstructorUser;
|
||||
} else if (checkIsInstructorManager()) {
|
||||
if (preInstructorUserId != null) {
|
||||
validateHubId(request, preInstructorUser.getHub().getId());
|
||||
}
|
||||
return preInstructorUser;
|
||||
} else if (checkIsPreInstructor()) {
|
||||
return validateUserId(request, preInstructorUserId);
|
||||
} else {
|
||||
@@ -171,5 +181,18 @@ public class Validator {
|
||||
Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Boolean checkIsInstructorManager() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (authentication != null && authentication.isAuthenticated()) {
|
||||
// Check if the user has the ROLE_INSTRUCTOR_MANAGER authority
|
||||
for (GrantedAuthority authority : authentication.getAuthorities()) {
|
||||
if (RoleStatusEnum.ROLE_INSTRUCTOR_MANAGER.getValue().equals(authority.getAuthority())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user