diff --git a/Ai-labar.postman_collection.json b/Ai-labar.postman_collection.json index 55fb63c..091653f 100644 --- a/Ai-labar.postman_collection.json +++ b/Ai-labar.postman_collection.json @@ -56,6 +56,34 @@ }, "response": [] }, + { + "name": "adminAccess", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"password\": \"f40c05434358a62bde28b7991e16f880d059d99adb2c20242cf2db46c197e322\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "localhost:8080/users/adminAccess", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "users", + "adminAccess" + ] + } + }, + "response": [] + }, { "name": "createUser", "request": { diff --git a/Backend/ai-labar/pom.xml b/Backend/ai-labar/pom.xml index f40780b..9d2a8a0 100644 --- a/Backend/ai-labar/pom.xml +++ b/Backend/ai-labar/pom.xml @@ -2,17 +2,17 @@ 4.0.0 + com.capgemini + ai-labar + 2.3.0 + ai-labar + AI-Labar Project org.springframework.boot spring-boot-starter-parent 2.7.14 - com.capgemini - ai-labar - 2.3.0 - ai-labar - AI-Labar Project 11 diff --git a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/AiLabarApplication.java b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/AiLabarApplication.java index 6529c81..3472dd9 100644 --- a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/AiLabarApplication.java +++ b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/AiLabarApplication.java @@ -1,5 +1,8 @@ package com.capgemini.ailabar; +import com.capgemini.ailabar.commons.utils.AccessPom; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; @@ -7,7 +10,10 @@ @SpringBootApplication @EnableScheduling public class AiLabarApplication { + private static final Logger logger = LogManager.getLogger(AiLabarApplication.class); + public static void main(String[] args) { SpringApplication.run(AiLabarApplication.class, args); + logger.info(AccessPom.showAppVersion()); } } diff --git a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/commons/utils/AccessPom.java b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/commons/utils/AccessPom.java new file mode 100644 index 0000000..496e4a5 --- /dev/null +++ b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/commons/utils/AccessPom.java @@ -0,0 +1,37 @@ +package com.capgemini.ailabar.commons.utils; + +import org.springframework.stereotype.Component; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import java.io.File; + +@Component +public final class AccessPom { + private AccessPom() {} + public static String showAppVersion() { + try { + File pomFile = new File("pom.xml"); + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); + + Document document = documentBuilder.parse(pomFile); + Element rootElement = document.getDocumentElement(); + NodeList versionNodeList = rootElement.getElementsByTagName("version"); + + if (versionNodeList.getLength() > 0) { + Node versionNode = versionNodeList.item(0); + return "AiLabar " + versionNode.getTextContent(); + } else { + return "No se encontró la versión en el pom.xml"; + } + + } catch (Exception e) { + return e.getMessage(); + } + } +} diff --git a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/groups/application/usecases/GetGroupUseCaseImpl.java b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/groups/application/usecases/GetGroupUseCaseImpl.java index f742554..20a8c89 100644 --- a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/groups/application/usecases/GetGroupUseCaseImpl.java +++ b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/groups/application/usecases/GetGroupUseCaseImpl.java @@ -41,6 +41,7 @@ public GroupsModel getGroup(GroupsModel groupsModel) { List membersList = new ArrayList<>(); membersIdList.forEach(id -> { try { + //membersList.add(groupsRepositoryPort.getUserNameEMailByUserId(id)); membersList.add(groupsRepositoryPort.getUserNameByUserId(id)); } catch (GetGroupException getGroupException) { throw new GetGroupException("An error occurred while retrieving group members"); diff --git a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/groups/domain/ports/out/GroupsRepositoryPort.java b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/groups/domain/ports/out/GroupsRepositoryPort.java index da293ff..054e9ea 100644 --- a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/groups/domain/ports/out/GroupsRepositoryPort.java +++ b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/groups/domain/ports/out/GroupsRepositoryPort.java @@ -37,5 +37,7 @@ public interface GroupsRepositoryPort { String getUserNameByUserId(Integer id); + String getUserNameEMailByUserId(Integer id); + void insertMember(Integer groupId, Integer userId); } diff --git a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/groups/infraestructure/adapters/out/GroupsRepositoryAdapter.java b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/groups/infraestructure/adapters/out/GroupsRepositoryAdapter.java index e4245dd..93d1266 100644 --- a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/groups/infraestructure/adapters/out/GroupsRepositoryAdapter.java +++ b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/groups/infraestructure/adapters/out/GroupsRepositoryAdapter.java @@ -95,6 +95,10 @@ public String getUserNameByUserId(Integer id) { return groupsRepository.getUserNameByUserId(id); } + @Override + public String getUserNameEMailByUserId(Integer id) { + return groupsRepository.getUserNameEMailByUserId(id); + } @Override public void insertMember(Integer groupId, Integer userId) { groupsRepository.insertMember(groupId, userId); diff --git a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/groups/infraestructure/repositories/GroupsRepository.java b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/groups/infraestructure/repositories/GroupsRepository.java index f65d193..9f722db 100644 --- a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/groups/infraestructure/repositories/GroupsRepository.java +++ b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/groups/infraestructure/repositories/GroupsRepository.java @@ -47,7 +47,8 @@ public interface GroupsRepository extends JpaRepository { @Query("SELECT u.user FROM UsersEntity u WHERE u.id = :id") String getUserNameByUserId(@Param("id") Integer id); - + @Query("SELECT CONCAT(u.user, ' (', u.email, ')') FROM UsersEntity u WHERE u.id = :id") + String getUserNameEMailByUserId(@Param("id") Integer id); @Modifying @Query(value = "INSERT INTO members (group_id, user_id) VALUES (:groupId, :userId)", nativeQuery = true) void insertMember(@Param("groupId") Integer groupId, @Param("userId") Integer userId); diff --git a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/application/services/UsersService.java b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/application/services/UsersService.java index 5ed8e89..24f1d7c 100644 --- a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/application/services/UsersService.java +++ b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/application/services/UsersService.java @@ -9,10 +9,12 @@ import java.util.List; @Service -public class UsersService implements LoginUseCase, CreateUserUseCase, EditUserUseCase, DeleteUserUseCase, - GetUsersByMatchUseCase, EditVisualizationUseCase, GetAllUsersUseCase, GetUsersDatabaseUseCase, - EditLanguageUseCase, LogoutUseCase { +public class UsersService implements LoginUseCase, AdminAccessUseCase, CreateUserUseCase, EditUserUseCase, + DeleteUserUseCase, GetUsersByMatchUseCase, EditVisualizationUseCase, GetAllUsersUseCase, + GetUsersDatabaseUseCase, EditLanguageUseCase, LogoutUseCase { private final LoginUseCase loginUseCase; + + private final AdminAccessUseCase adminAccessUseCase; private final CreateUserUseCase createUserUseCase; private final EditUserUseCase editUserUseCase; private final DeleteUserUseCase deleteUserUseCase; @@ -23,12 +25,14 @@ public class UsersService implements LoginUseCase, CreateUserUseCase, EditUserUs private final GetUsersDatabaseUseCase getUsersDatabaseUseCase; private final LogoutUseCase logoutUseCase; - public UsersService(LoginUseCase loginUseCase, CreateUserUseCase createUserUseCase, - EditUserUseCase editUserUseCase, DeleteUserUseCase deleteUserUseCase, - GetUsersByMatchUseCase getUsersByMatch, EditVisualizationUseCase editVisualizationUseCase, - GetAllUsersUseCase getAllUsersUseCase, GetUsersDatabaseUseCase getUsersDatabaseUseCase , - EditLanguageUseCase editLanguageUseCase, LogoutUseCase logoutUseCase) { + public UsersService(LoginUseCase loginUseCase, AdminAccessUseCase adminAccessUseCase, + CreateUserUseCase createUserUseCase, EditUserUseCase editUserUseCase, + DeleteUserUseCase deleteUserUseCase, GetUsersByMatchUseCase getUsersByMatch, + EditVisualizationUseCase editVisualizationUseCase, GetAllUsersUseCase getAllUsersUseCase, + GetUsersDatabaseUseCase getUsersDatabaseUseCase , EditLanguageUseCase editLanguageUseCase, + LogoutUseCase logoutUseCase) { this.loginUseCase = loginUseCase; + this.adminAccessUseCase = adminAccessUseCase; this.createUserUseCase = createUserUseCase; this.editUserUseCase = editUserUseCase; this.deleteUserUseCase = deleteUserUseCase; @@ -48,6 +52,15 @@ public List login(UsersModel usersModel, PrivateKey privateKey) { } } + @Override + public void adminAccess(UsersModel usersModel) { + try { + adminAccessUseCase.adminAccess(usersModel); + } catch (AdminAccessException adminAccessException) { + throw adminAccessException; + } + } + @Override public void createUser(UsersModel usersModel) { try { diff --git a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/application/usecases/AdminAccessUseCaseImpl.java b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/application/usecases/AdminAccessUseCaseImpl.java new file mode 100644 index 0000000..0af424e --- /dev/null +++ b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/application/usecases/AdminAccessUseCaseImpl.java @@ -0,0 +1,24 @@ +package com.capgemini.ailabar.users.application.usecases; + +import com.capgemini.ailabar.users.domain.exceptions.AdminAccessException; +import com.capgemini.ailabar.users.domain.models.UsersModel; +import com.capgemini.ailabar.users.domain.ports.in.AdminAccessUseCase; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +@Service +public class AdminAccessUseCaseImpl implements AdminAccessUseCase { + @Value("${admin.access}") + private String adminPass; + + @Override + public void adminAccess(UsersModel usersModel) { + if(usersModel.getPassword().isBlank()) { + throw new AdminAccessException("Password is required"); + } + + if (Boolean.FALSE.equals(usersModel.getPassword().equals(adminPass))) { + throw new AdminAccessException("Wrong Password"); + } + } +} diff --git a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/application/usecases/EditUserUseCaseImpl.java b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/application/usecases/EditUserUseCaseImpl.java index 7ec8911..2fff2df 100644 --- a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/application/usecases/EditUserUseCaseImpl.java +++ b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/application/usecases/EditUserUseCaseImpl.java @@ -39,6 +39,10 @@ public void editUser(UsersModel usersModel) { throw new EditUserException("The new username already exists"); } + if (Boolean.TRUE.equals(usersRepositoryPort.checkEmail(usersModel.getEmail()))) { + throw new EditUserException("The email already exists"); + } + UsersEntity userEntity = usersRepositoryPort.getUserByName(usersModel.getUser()); if(usersModel.getNewUser() != null && !usersModel.getNewUser().isBlank()) { diff --git a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/application/usecases/LoginUseCaseImpl.java b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/application/usecases/LoginUseCaseImpl.java index 87a44a0..2914f76 100644 --- a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/application/usecases/LoginUseCaseImpl.java +++ b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/application/usecases/LoginUseCaseImpl.java @@ -1,6 +1,7 @@ package com.capgemini.ailabar.users.application.usecases; import com.capgemini.ailabar.commons.utils.DateTime; +import com.capgemini.ailabar.users.domain.exceptions.CreateUserException; import com.capgemini.ailabar.users.domain.exceptions.LoginException; import com.capgemini.ailabar.users.domain.models.UsersModel; import com.capgemini.ailabar.users.domain.ports.in.LoginUseCase; @@ -70,14 +71,33 @@ public List login(UsersModel usersModel, PrivateKey privateKey) { private String loginCap(UsersModel usersModel) { JSONObject jsonObject = requestToCapgemini(usersModel); - if(!usersRepositoryPort.checkUser(usersModel.getUser())) { - createCapgeminiUser(usersModel, jsonObject); + JSONObject decodedClaims = readJWT(jsonObject); + + String userSubName = decodedClaims.getString("sub"); + String email = decodedClaims.getString("email"); + + if(!usersRepositoryPort.checkEmail(email)) { + // Descomentar cuando se quiera volver a registrar a los usuarios con el primer login en la aplicación + //createCapgeminiUser(usersModel, jsonObject); + throw new LoginException("Unauthorized user in the application"); } String token = jsonObject.getString("token"); - UsersEntity usersEntity = usersRepositoryPort.getUserByName(usersModel.getUser()); - usersRepositoryPort.updateToken(usersEntity.getId(), token); + UsersEntity usersEntity = usersRepositoryPort.getUserByEmail(email); + if(usersEntity != null) { + if (Boolean.TRUE.equals(usersRepositoryPort.checkUser(userSubName)) && !userSubName.equals(usersModel.getUser())) { + throw new CreateUserException("The user already exists"); + } + + try { + usersRepositoryPort.updateUserNameAndToken(usersEntity.getId(), userSubName, token); + } catch (Exception e) { + throw new LoginException("Error updating user during login"); + } + } else { + throw new LoginException("User not found"); + } return token; } diff --git a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/domain/exceptions/AdminAccessException.java b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/domain/exceptions/AdminAccessException.java new file mode 100644 index 0000000..65243e2 --- /dev/null +++ b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/domain/exceptions/AdminAccessException.java @@ -0,0 +1,7 @@ +package com.capgemini.ailabar.users.domain.exceptions; + +public class AdminAccessException extends RuntimeException { + public AdminAccessException(String message) { + super(message); + } +} diff --git a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/domain/ports/in/AdminAccessUseCase.java b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/domain/ports/in/AdminAccessUseCase.java new file mode 100644 index 0000000..d016621 --- /dev/null +++ b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/domain/ports/in/AdminAccessUseCase.java @@ -0,0 +1,7 @@ +package com.capgemini.ailabar.users.domain.ports.in; + +import com.capgemini.ailabar.users.domain.models.UsersModel; + +public interface AdminAccessUseCase { + void adminAccess(UsersModel usersModel); +} diff --git a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/domain/ports/out/UsersRepositoryPort.java b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/domain/ports/out/UsersRepositoryPort.java index a5c07dd..21b37cc 100644 --- a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/domain/ports/out/UsersRepositoryPort.java +++ b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/domain/ports/out/UsersRepositoryPort.java @@ -1,14 +1,13 @@ package com.capgemini.ailabar.users.domain.ports.out; import com.capgemini.ailabar.users.infraestructure.entities.UsersEntity; -import org.springframework.data.repository.query.Param; import java.util.List; public interface UsersRepositoryPort { boolean checkAuthorization(String user, String token); - boolean checkEmail(String email); + boolean checkEmail(String user); boolean checkUser(String user); @@ -18,6 +17,8 @@ public interface UsersRepositoryPort { List getAllUsers(); + UsersEntity getUserByEmail(String email); + UsersEntity getUserByName(String user); List getUsersByMatch(String matcher); @@ -28,7 +29,7 @@ public interface UsersRepositoryPort { void deleteMembersByUserId(Integer userId); - void updateToken(@Param("userId") Integer userId, @Param("newToken") String newToken); + void updateUserNameAndToken(Integer userId, String user, String newToken); - boolean login(String user, String password); + boolean login(String email, String password); } diff --git a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/infraestructure/adapters/out/UsersRepositoryAdapter.java b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/infraestructure/adapters/out/UsersRepositoryAdapter.java index cd737f1..a9576ae 100644 --- a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/infraestructure/adapters/out/UsersRepositoryAdapter.java +++ b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/infraestructure/adapters/out/UsersRepositoryAdapter.java @@ -45,6 +45,11 @@ public List getAllUsers() { return usersRepository.getAllUsers(); } + @Override + public UsersEntity getUserByEmail(String email) { + return usersRepository.getUserByEmail(email); + } + @Override public UsersEntity getUserByName(String user) { return usersRepository.getUserByName(user); @@ -71,8 +76,8 @@ public void deleteMembersByUserId(Integer userId) { } @Override - public void updateToken(Integer userId, String newToken) { - usersRepository.updateToken(userId, newToken); + public void updateUserNameAndToken(Integer userId, String user, String newToken) { + usersRepository.updateUserNameAndToken(userId, user, newToken); } @Override diff --git a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/infraestructure/controllers/UsersController.java b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/infraestructure/controllers/UsersController.java index 2adce58..dfd9003 100644 --- a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/infraestructure/controllers/UsersController.java +++ b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/infraestructure/controllers/UsersController.java @@ -75,6 +75,17 @@ public ResponseEntity login(@RequestBody UsersModel usersModel) return new ResponseEntity<>(specialResponse(loginData, responseJson), HttpStatus.OK); } + /* + * METHOD TO ACCESS USER CREATION + */ + @PostMapping("/adminAccess") + public ResponseEntity adminAccess(@RequestBody UsersModel usersModel) { + JSONObject responseJson = new JSONObject(); + usersService.adminAccess(usersModel); + responseJson.put("message", "Admin access successful"); + return new ResponseEntity<>(specialResponse(null, responseJson), HttpStatus.OK); + } + /* * CREATES A USER IN THE DATABASE: * 1. In this case, the password should arrive encrypted with SHA256 from the frontend. In the backend, the password will be re-encrypted in SHA256, and a token will be generated with the user's unique name, password, and ID. @@ -195,6 +206,13 @@ ResponseEntity handlerLoginException (LoginException loginExcep return new ResponseEntity<>(specialResponse(null, responseJson), HttpStatus.INTERNAL_SERVER_ERROR); } + @ExceptionHandler(AdminAccessException.class) + ResponseEntity handlerAdminAccessException (AdminAccessException adminAccessException){ + JSONObject responseJson = new JSONObject(); + responseJson.put("message", adminAccessException.getMessage()); + return new ResponseEntity<>(specialResponse(null, responseJson), HttpStatus.INTERNAL_SERVER_ERROR); + } + @ExceptionHandler(CreateUserException.class) ResponseEntity handlerCreateUserException (CreateUserException createUserException){ JSONObject responseJson = new JSONObject(); diff --git a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/infraestructure/repositories/UsersRepository.java b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/infraestructure/repositories/UsersRepository.java index 360b1bb..ca2ee5f 100644 --- a/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/infraestructure/repositories/UsersRepository.java +++ b/Backend/ai-labar/src/main/java/com/capgemini/ailabar/users/infraestructure/repositories/UsersRepository.java @@ -29,10 +29,13 @@ public interface UsersRepository extends JpaRepository { @Query("SELECT u.user FROM UsersEntity u WHERE u.user NOT LIKE '%Deactivated%'") List getAllUsers(); + @Query("SELECT u FROM UsersEntity u WHERE u.email = :email") + UsersEntity getUserByEmail(@Param("email") String email); + @Query("SELECT u FROM UsersEntity u WHERE u.user = :user") UsersEntity getUserByName(@Param("user") String user); - @Query("SELECT u.user FROM UsersEntity u WHERE upper(u.user) LIKE %:matcher% AND u.user NOT LIKE '%Deactivated%'") + @Query("SELECT CONCAT(u.user, ' (', u.email, ')') AS user FROM UsersEntity u WHERE (UPPER(u.user) LIKE %:matcher% OR UPPER(u.email) LIKE %:matcher%) AND u.user NOT LIKE '%Deactivated%'") List getUsersByNameMatch(@Param("matcher") String matcher); @Modifying @@ -44,8 +47,8 @@ public interface UsersRepository extends JpaRepository { void deleteMembersByUserId(@Param("userId") Integer userId); @Modifying - @Query("UPDATE UsersEntity u SET u.token = :newToken WHERE u.id = :userId") - void updateToken(@Param("userId") Integer userId, @Param("newToken") String newToken); + @Query("UPDATE UsersEntity u SET u.user = :user, u.token = :newToken WHERE u.id = :userId") + void updateUserNameAndToken(@Param("userId") Integer userId, @Param("user") String user, @Param("newToken") String newToken); @Override S save(S entity); diff --git a/Backend/ai-labar/src/main/resources/application.properties b/Backend/ai-labar/src/main/resources/application.properties index 93fa498..0cd3beb 100644 --- a/Backend/ai-labar/src/main/resources/application.properties +++ b/Backend/ai-labar/src/main/resources/application.properties @@ -1,10 +1,13 @@ -#configuracion de la aplicacion +# Configuracion de la aplicacion allowed.origins=http://localhost:4200 # Usuario y clave para acceder a las rutas protegidas con Spring Security (esto debería ir guardado en el servidor, no aquí) -spring.security.user.name=${SPRING_ADMIN_USER:user} +spring.security.user.name=${SPRING_ADMIN_USER:admin} spring.security.user.password=${SPRING_ADMIN_PASSWORD:abcd1234} +# Clave para el acceso como administrador para el registro de usuarios (se debe poner la clave cifrada en SHA256) +admin.access=${ADMIN_ACCESS:adminPass} + #Database MySQL spring.jpa.hibernate.ddl-auto=none spring.jpa.database=mysql @@ -46,4 +49,4 @@ activate.mail=false # Gestión Login CAP login.cap.active=true -login.cap.url=${SSO_URL:http://www.url.com}/authenticate \ No newline at end of file +login.cap.url=${SSO_URL:http://www.x.com}/authenticate \ No newline at end of file diff --git a/Frontend/ai-labar/package.json b/Frontend/ai-labar/package.json index efd0b46..519079e 100644 --- a/Frontend/ai-labar/package.json +++ b/Frontend/ai-labar/package.json @@ -1,6 +1,6 @@ { "name": "ailabar", - "version": "1.0.0", + "version": "1.0.5", "scripts": { "ng": "ng", "start": "ng serve", diff --git a/Frontend/ai-labar/src/assets/i18n/en.json b/Frontend/ai-labar/src/assets/i18n/en.json index 7306994..5a8f475 100644 --- a/Frontend/ai-labar/src/assets/i18n/en.json +++ b/Frontend/ai-labar/src/assets/i18n/en.json @@ -6,7 +6,9 @@ "REGISTER": "Register", "EMAIL": "E-mail", "ADD_IMG": "Add image", - "CANCELAR": "Cancel" + "CANCELAR": "Cancel", + "PASS_ADMIN": "Administrator password", + "SEND":"Send" }, "TOPIC": { "MANAGING_GROUPS": "Managing groups", @@ -161,7 +163,8 @@ "ERROR_SEND_LANGUAGE": "The language could not be saved", "ERROR_USER_IMAGE_SIZE": "The image is too large. The maximum allowed size is 5MB.", "ERROR_NO_PARTICIPANTS": "You have not selected participants.", - "ERROR_EDIT_GROUP":"Unable to edit the group" + "ERROR_EDIT_GROUP":"Unable to edit the group", + "ERROR_ADMIN_PASS": "Password verification error: " }, "OK_MESSAGES": { "OK_SEND_SELECTION": "Selection sent successfully", diff --git a/Frontend/ai-labar/src/assets/i18n/es.json b/Frontend/ai-labar/src/assets/i18n/es.json index efb6380..bebd807 100644 --- a/Frontend/ai-labar/src/assets/i18n/es.json +++ b/Frontend/ai-labar/src/assets/i18n/es.json @@ -6,7 +6,9 @@ "REGISTER": "Registro", "EMAIL": "E-mail", "ADD_IMG": "Añadir imagen", - "CANCELAR": "Cancelar" + "CANCELAR": "Cancelar", + "PASS_ADMIN": "Contraseña administrador", + "SEND":"Enviar" }, "TOPIC": { "MANAGING_GROUPS": "Gestionar grupos", @@ -161,7 +163,8 @@ "ERROR_SEND_LANGUAGE": "No se ha podido guardar el idioma", "ERROR_USER_IMAGE_SIZE": "La imagen es demasiado grande. El tamaño máximo permitido es de 5MB.", "ERROR_NO_PARTICIPANTS": "No ha seleccionado participantes.", - "ERROR_EDIT_GROUP":"No se ha podido editar el grupo" + "ERROR_EDIT_GROUP":"No se ha podido editar el grupo", + "ERROR_ADMIN_PASS": "Error al verificar la contraseña: erro" }, "OK_MESSAGES": { "OK_SEND_SELECTION": "Selección enviada con éxito", diff --git a/Frontend/ai-labar/src/pages/login/components/login/login.component.html b/Frontend/ai-labar/src/pages/login/components/login/login.component.html index 2d09b84..241d179 100644 --- a/Frontend/ai-labar/src/pages/login/components/login/login.component.html +++ b/Frontend/ai-labar/src/pages/login/components/login/login.component.html @@ -2,12 +2,13 @@
+
v.{{ appVersion }}
@@ -154,6 +155,7 @@

{{ "MANAGING_GROUPS.MANAGING_GROUP" | translate }}

[value]="selectedUsersGroup.join(', ')" rows="3" name="currentSelection" + readonly="true" > diff --git a/Frontend/ai-labar/src/pages/topics/components/groups/groups.component.ts b/Frontend/ai-labar/src/pages/topics/components/groups/groups.component.ts index ba5e2a7..f8f7537 100644 --- a/Frontend/ai-labar/src/pages/topics/components/groups/groups.component.ts +++ b/Frontend/ai-labar/src/pages/topics/components/groups/groups.component.ts @@ -159,11 +159,13 @@ export class GroupsComponent implements OnInit, OnDestroy { this.selectedUsersGroup = []; } this.usersGroupsNames.map((item) => { + //const username = item; + const username = item.split('(')[0].trim(); let user = { name: item, - checked: this.selectedUsersGroup.includes(item), + checked: this.selectedUsersGroup.includes(username), hidden: false, - modal: this.selectedUsersGroup.includes(item) + modal: this.selectedUsersGroup.includes(username) }; this.usersGroups.push(user); if (!this.isFilterUsersGroups) { @@ -189,9 +191,11 @@ export class GroupsComponent implements OnInit, OnDestroy { loadForm() { this.users = []; this.usersNames.map((item) => { + //const username = item; + const username = item.split('(')[0].trim(); let user = { name: item, - checked: this.selectedUsers.includes(item), + checked: this.selectedUsers.includes(username), hidden: false, modal: false }; @@ -254,12 +258,14 @@ export class GroupsComponent implements OnInit, OnDestroy { */ selectUser(user: IUser): void { user.checked = !user.checked; + //const userName = user.name; + const userName = user.name.split('(')[0].trim(); if (user.checked) { - if (!this.selectedUsers.includes(user.name)) { - this.selectedUsers.push(user.name); + if (!this.selectedUsers.includes(userName)) { + this.selectedUsers.push(userName); } } else { - const index = this.selectedUsers.indexOf(user.name); + const index = this.selectedUsers.indexOf(userName); if (index !== -1) { this.selectedUsers.splice(index, 1); } @@ -272,12 +278,14 @@ export class GroupsComponent implements OnInit, OnDestroy { */ selectUserGroup(user: IUser): void { user.checked = !user.checked; + //const userName = user.name; + const userName = user.name.split('(')[0].trim(); if (user.checked) { - if (!this.selectedUsersGroup.includes(user.name)) { - this.selectedUsersGroup.push(user.name); + if (!this.selectedUsersGroup.includes(userName)) { + this.selectedUsersGroup.push(userName); } } else { - const index = this.selectedUsersGroup.indexOf(user.name); + const index = this.selectedUsersGroup.indexOf(userName); if (index !== -1) { this.selectedUsersGroup.splice(index, 1); } @@ -289,9 +297,16 @@ export class GroupsComponent implements OnInit, OnDestroy { * Creates a new group with the selected users and saves it to the server. */ saveGroup() { + + const modifiedSelectedUsers: string[] = []; + for (const selectedUser of this.selectedUsers) { + const userName = selectedUser.split('(')[0]; + modifiedSelectedUsers.push(userName.trim()); + } + const groupBody = { groupName: this.groupsForm.value.groupName, - members: this.selectedUsers, + members: modifiedSelectedUsers, user: this.cookie.get('user'), token: this.cookie.get('token'), }; @@ -320,9 +335,15 @@ export class GroupsComponent implements OnInit, OnDestroy { * Edit a group with the selected users and saves it to the server. */ editGroup() { + const modifiedSelectedUsers: string[] = []; + for (const selectedUser of this.selectedUsersGroup) { + const userName = selectedUser.split('(')[0]; + modifiedSelectedUsers.push(userName.trim()); + } + const groupBody = { groupName: this.actualGroupName, - members: this.selectedUsersGroup, + members: modifiedSelectedUsers, user: this.cookie.get('user'), token: this.cookie.get('token'), id: this.idGroup, diff --git a/Frontend/ai-labar/src/pages/topics/components/topics-create/topics-create.component.ts b/Frontend/ai-labar/src/pages/topics/components/topics-create/topics-create.component.ts index 9fddf82..6cce6bf 100644 --- a/Frontend/ai-labar/src/pages/topics/components/topics-create/topics-create.component.ts +++ b/Frontend/ai-labar/src/pages/topics/components/topics-create/topics-create.component.ts @@ -124,7 +124,7 @@ export class TopicsCreateComponent implements OnInit, OnDestroy { this.selectedType = this.typeAs; this.surveyOptions = []; for (const object of this.childComponent.objectsToBack) { - const option = { option: object }; + const option = { option: object.split('(')[0].trim() }; this.surveyOptions.push(option); } } else if (this.childComponent.isSurveyImageText) { diff --git a/Frontend/ai-labar/tsconfig.json b/Frontend/ai-labar/tsconfig.json index f531992..d476083 100644 --- a/Frontend/ai-labar/tsconfig.json +++ b/Frontend/ai-labar/tsconfig.json @@ -21,7 +21,9 @@ "lib": [ "es2020", "dom" - ] + ], + "resolveJsonModule": true, + "allowSyntheticDefaultImports": true }, "angularCompilerOptions": { "enableI18nLegacyMessageIdFormat": false,