Skip to content

Commit

Permalink
fix lateinit error in role creation
Browse files Browse the repository at this point in the history
  • Loading branch information
coutinho21 committed Mar 14, 2024
1 parent 5f67feb commit 5a4806f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/pt/up/fe/ni/website/backend/model/Role.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ class Role(
if (associatedActivities.isEmpty()) {
return permissionsPayload
}
return "$permissionsPayload ${associatedActivities.joinToString(" ").trimEnd()}"
return "$this.name $permissionsPayload ${associatedActivities.joinToString(" ").trimEnd()}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand All @@ -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())
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/kotlin/pt/up/fe/ni/website/backend/service/RoleService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5a4806f

Please sign in to comment.