From edbfacfe555d0ba2de267f85a0b996860882ef08 Mon Sep 17 00:00:00 2001 From: coutinho21 Date: Thu, 14 Mar 2024 16:53:46 +0000 Subject: [PATCH] fix lateinit error in role creation --- .../kotlin/pt/up/fe/ni/website/backend/model/Role.kt | 2 +- .../pt/up/fe/ni/website/backend/service/AuthService.kt | 6 ++---- .../pt/up/fe/ni/website/backend/service/RoleService.kt | 10 ++++++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/pt/up/fe/ni/website/backend/model/Role.kt b/src/main/kotlin/pt/up/fe/ni/website/backend/model/Role.kt index 75cd5b0f..cfe1dc40 100644 --- a/src/main/kotlin/pt/up/fe/ni/website/backend/model/Role.kt +++ b/src/main/kotlin/pt/up/fe/ni/website/backend/model/Role.kt @@ -54,6 +54,6 @@ class Role( if (associatedActivities.isEmpty()) { return permissionsPayload } - return "$permissionsPayload ${associatedActivities.joinToString(" ").trimEnd()}" + return "$this.name $permissionsPayload ${associatedActivities.joinToString(" ").trimEnd()}" } } diff --git a/src/main/kotlin/pt/up/fe/ni/website/backend/service/AuthService.kt b/src/main/kotlin/pt/up/fe/ni/website/backend/service/AuthService.kt index e695dbe5..a66afcc4 100644 --- a/src/main/kotlin/pt/up/fe/ni/website/backend/service/AuthService.kt +++ b/src/main/kotlin/pt/up/fe/ni/website/backend/service/AuthService.kt @@ -34,7 +34,7 @@ class AuthService( fun hasPermission(permission: String): Boolean { val authentication = SecurityContextHolder.getContext().authentication return authentication.authorities.any { - it.toString() == permission.trim().uppercase() + it.toString() == permission.trim().uppercase(Locale.getDefault()) } } @@ -47,9 +47,7 @@ class AuthService( return authentication.authorities.any { val payload = it.toString().split(":") payload.size == 2 && payload[0] == name && payload[1].split("-").any { p -> - p == permission.trim().uppercase( - Locale.getDefault() - ) + p == permission.trim().uppercase(Locale.getDefault()) } } } diff --git a/src/main/kotlin/pt/up/fe/ni/website/backend/service/RoleService.kt b/src/main/kotlin/pt/up/fe/ni/website/backend/service/RoleService.kt index 2ba45a9d..5961aae1 100644 --- a/src/main/kotlin/pt/up/fe/ni/website/backend/service/RoleService.kt +++ b/src/main/kotlin/pt/up/fe/ni/website/backend/service/RoleService.kt @@ -73,6 +73,16 @@ class RoleService( if (validator.validateProperty(generation, "roles").isNotEmpty()) { throw IllegalArgumentException(ErrorMessages.roleAlreadyExists(role.name, generation.schoolYear)) } + + for (perActivityRoleDto in dto.associatedActivities) { + val activity = activityService.getActivityById(perActivityRoleDto.activityId!!) + + for (perActivityRole in role.associatedActivities) { + perActivityRole.role = role + perActivityRole.activity = activity + } + } + role.generation = generation roleRepository.save(role) return role