Skip to content

Commit

Permalink
Mise à jour vers Scala 3 (#2072)
Browse files Browse the repository at this point in the history
  • Loading branch information
niladic authored Sep 9, 2024
1 parent a5d625b commit 52b9ae0
Show file tree
Hide file tree
Showing 45 changed files with 585 additions and 495 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
if: ${{ env.CODACY_PROJECT_TOKEN }}
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: target/scala-2.13/coverage-report/cobertura.xml
coverage-reports: 'target/scala-*/coverage-report/cobertura.xml'

ts-build:
name: TypeScript Build
Expand Down
2 changes: 2 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ OrganizeImports {
"*"
]
importsOrder = SymbolsFirst
# TODO: "OrganizeImports.removeUnused"is not supported on 3.3.3 as the compiler is not providing enough information. Please upgrade the Scala compiler to 3.4.0 or greater. Otherwise, run the rule with "OrganizeImports.removeUnused" set to false to organize imports while keeping potentially unused imports.
removeUnused = false
}
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version = "3.8.3"
runner.dialect = scala213source3
runner.dialect = scala3
maxColumn = 100
spaces.afterKeywordBeforeParen = true
newlines.topLevelStatements = [before, after]
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/ApiController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.util.UUID
import javax.inject.{Inject, Singleton}
import models.{Area, Authorization, Error, EventType, Organisation, User, UserGroup}
import play.api.libs.json.{JsValue, Json}
import play.api.mvc._
import play.api.mvc.{Action, AnyContent, BaseController, ControllerComponents, Result}
import scala.concurrent.{ExecutionContext, Future}
import serializers.ApiModel._
import serializers.Keys
Expand All @@ -24,13 +24,14 @@ import services.{
@Singleton
case class ApiController @Inject() (
anonymizedDataService: AnonymizedDataService,
val controllerComponents: ControllerComponents,
loginAction: LoginAction,
eventService: EventService,
organisationService: OrganisationService,
userService: UserService,
userGroupService: UserGroupService
)(implicit val ec: ExecutionContext)
extends InjectedController
extends BaseController
with UserOperators {
import OrganisationService.FranceServiceInstance

Expand Down
20 changes: 16 additions & 4 deletions app/controllers/ApplicationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ import play.api.data._
import play.api.i18n.I18nSupport
import play.api.libs.json.Json
import play.api.libs.ws.WSClient
import play.api.mvc.{Action, AnyContent, Call, InjectedController, RequestHeader, Result, Session}
import play.api.mvc.{
Action,
AnyContent,
BaseController,
Call,
ControllerComponents,
RequestHeader,
Result,
Session
}
import play.twirl.api.Html
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success, Try}
Expand Down Expand Up @@ -78,6 +87,7 @@ case class ApplicationController @Inject() (
applicationService: ApplicationService,
businessDaysService: BusinessDaysService,
config: AppConfig,
val controllerComponents: ControllerComponents,
dependencies: ServicesDependencies,
eventService: EventService,
fileService: FileService,
Expand All @@ -89,7 +99,7 @@ case class ApplicationController @Inject() (
userService: UserService,
ws: WSClient,
)(implicit ec: ExecutionContext, webJarsUtil: WebJarsUtil)
extends InjectedController
extends BaseController
with I18nSupport
with Operators.Common
with Operators.ApplicationOperators
Expand Down Expand Up @@ -621,7 +631,8 @@ case class ApplicationController @Inject() (
views.applications.myApplicationsLegacy
.page(user, userRights, filteredByStatus.map(_.application), userGroups, infos)
)
).withHeaders(CACHE_CONTROL -> "no-store")
)
.withHeaders(CACHE_CONTROL -> "no-store")
}

private def applicationBoardInfos(
Expand Down Expand Up @@ -1130,7 +1141,8 @@ case class ApplicationController @Inject() (
}
}
coworkers.combine(instructorsCoworkers)
}).map(
})
.map(
_.filterNot(user =>
user.id === request.currentUser.id || application.invitedUsers.contains(user.id)
)
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/AreaController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import models._
import models.EventType.{AllAreaUnauthorized, DeploymentDashboardUnauthorized}
import modules.AppConfig
import org.webjars.play.WebJarsUtil
import play.api.mvc.{Action, AnyContent, InjectedController}
import play.api.mvc.{Action, AnyContent, BaseController, ControllerComponents}
import scala.concurrent.{ExecutionContext, Future}
import services.{EventService, UserGroupService, UserService}

@Singleton
case class AreaController @Inject() (
config: AppConfig,
val controllerComponents: ControllerComponents,
loginAction: LoginAction,
eventService: EventService,
userService: UserService,
userGroupService: UserGroupService,
)(implicit ec: ExecutionContext, val webJarsUtil: WebJarsUtil)
extends InjectedController
extends BaseController
with Operators.Common
with UserOperators {

Expand Down
19 changes: 11 additions & 8 deletions app/controllers/CSVImportController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import actions.LoginAction
import cats.syntax.all._
import controllers.Operators.{GroupOperators, UserOperators}
import helper.MiscHelpers.toTupleOpt
import helper.PlayFormHelpers.{inOption, normalizedOptionalText, normalizedText}
import helper.StringHelper._
import helper.Time
Expand Down Expand Up @@ -33,22 +34,24 @@ import org.webjars.play.WebJarsUtil
import play.api.data.{Form, Mapping}
import play.api.data.Forms._
import play.api.data.validation.Constraints.{maxLength, nonEmpty}
import play.api.mvc.{Action, AnyContent, InjectedController}
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, BaseController, ControllerComponents}
import scala.concurrent.{ExecutionContext, Future}
import serializers.UserAndGroupCsvSerializer
import serializers.UserAndGroupCsvSerializer.UserGroupBlock
import services.{EventService, NotificationService, UserGroupService, UserService}

case class CSVImportController @Inject() (
config: AppConfig,
val controllerComponents: ControllerComponents,
loginAction: LoginAction,
userService: UserService,
groupService: UserGroupService,
notificationsService: NotificationService,
eventService: EventService
)(implicit ec: ExecutionContext, webJarsUtil: WebJarsUtil)
extends InjectedController
with play.api.i18n.I18nSupport
extends BaseController
with I18nSupport
with Operators.Common
with UserOperators
with GroupOperators {
Expand Down Expand Up @@ -171,7 +174,7 @@ case class CSVImportController @Inject() (
"instructor" -> boolean,
"groupAdmin" -> boolean,
"phoneNumber" -> normalizedOptionalText
)(CSVReviewUserFormData.apply)(CSVReviewUserFormData.unapply)
)(CSVReviewUserFormData.apply)(toTupleOpt)

private def groupImportMapping(date: ZonedDateTime): Mapping[UserGroup] =
mapping(
Expand All @@ -195,7 +198,7 @@ case class CSVImportController @Inject() (
"email" -> optional(email),
"publicNote" -> ignored(Option.empty[String]),
"internalSupportComment" -> ignored(Option.empty[String])
)(UserGroup.apply)(UserGroup.unapply)
)(UserGroup.apply)(toTupleOpt)

private def importUsersAfterReviewForm(date: ZonedDateTime): Form[List[CSVUserGroupFormData]] =
Form(
Expand All @@ -210,12 +213,12 @@ case class CSVImportController @Inject() (
"alreadyExists" -> boolean,
"alreadyExistingUser" -> ignored(Option.empty[User]),
"isInMoreThanOneGroup" -> optional(boolean)
)(CSVUserFormData.apply)(CSVUserFormData.unapply)
)(CSVUserFormData.apply)(toTupleOpt)
),
"alreadyExistsOrAllUsersAlreadyExist" -> boolean,
"doNotInsert" -> boolean,
"alreadyExistingGroup" -> ignored(Option.empty[UserGroup])
)(CSVUserGroupFormData.apply)(CSVUserGroupFormData.unapply)
)(CSVUserGroupFormData.apply)(toTupleOpt)
)
)
)
Expand Down Expand Up @@ -438,7 +441,7 @@ case class CSVImportController @Inject() (
},
{ _ =>
usersToInsert.foreach { user =>
notificationsService.newUser(user)
val _ = notificationsService.newUser(user)
eventService.log(
UserCreated,
"Utilisateur ajouté",
Expand Down
15 changes: 12 additions & 3 deletions app/controllers/GroupController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ import modules.AppConfig
import org.webjars.play.WebJarsUtil
import play.api.data.Form
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, Call, InjectedController, RequestHeader, Result}
import play.api.mvc.{
Action,
AnyContent,
BaseController,
Call,
ControllerComponents,
RequestHeader,
Result
}
import play.libs.ws.WSClient
import scala.concurrent.{ExecutionContext, Future}
import serializers.Keys
Expand All @@ -39,14 +47,15 @@ import views.editMyGroups.UserInfos
case class GroupController @Inject() (
applicationService: ApplicationService,
config: AppConfig,
val controllerComponents: ControllerComponents,
dependencies: ServicesDependencies,
eventService: EventService,
groupService: UserGroupService,
loginAction: LoginAction,
userService: UserService,
ws: WSClient,
)(implicit ec: ExecutionContext, webJarsUtil: WebJarsUtil)
extends InjectedController
extends BaseController
with I18nSupport
with Operators.Common
with GroupOperators
Expand Down Expand Up @@ -253,7 +262,7 @@ case class GroupController @Inject() (
)
Future(Unauthorized("Le groupe est utilisé."))
} else {
groupService.deleteById(groupId)
val _ = groupService.deleteById(groupId)
eventService.log(
UserGroupDeleted,
"Groupe supprimé",
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/HomeController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.webjars.play.WebJarsUtil
import play.api.Logger
import play.api.db.Database
import play.api.i18n.I18nSupport
import play.api.mvc._
import play.api.mvc.{Action, AnyContent, BaseController, ControllerComponents}
import serializers.Keys
import views.home.LoginPanel

Expand All @@ -17,10 +17,11 @@ import views.home.LoginPanel
@Singleton
class HomeController @Inject() (
val config: AppConfig,
val controllerComponents: ControllerComponents,
loginAction: LoginAction,
db: Database,
)(implicit webJarsUtil: WebJarsUtil)
extends InjectedController
extends BaseController
with I18nSupport
with Operators.Common {

Expand Down
7 changes: 4 additions & 3 deletions app/controllers/JavascriptController.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package controllers

import javax.inject.Singleton
import javax.inject.{Inject, Singleton}
import play.api.http.MimeTypes
import play.api.mvc.{Action, AnyContent, InjectedController}
import play.api.mvc.{Action, AnyContent, BaseController, ControllerComponents}
import play.api.routing.JavaScriptReverseRouter

@Singleton
class JavascriptController() extends InjectedController {
class JavascriptController @Inject() (val controllerComponents: ControllerComponents)
extends BaseController {

def javascriptRoutes: Action[AnyContent] =
Action { implicit request =>
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/LoginController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import models.{Authorization, EventType, LoginToken, User}
import models.EventType.{GenerateToken, UnknownEmail}
import modules.AppConfig
import org.webjars.play.WebJarsUtil
import play.api.mvc.{Action, AnyContent, InjectedController, Request}
import play.api.mvc.{Action, AnyContent, BaseController, ControllerComponents, Request}
import scala.concurrent.{ExecutionContext, Future}
import serializers.Keys
import services.{
Expand All @@ -26,14 +26,15 @@ import views.home.LoginPanel
@Singleton
class LoginController @Inject() (
val config: AppConfig,
val controllerComponents: ControllerComponents,
dependencies: ServicesDependencies,
userService: UserService,
notificationService: NotificationService,
tokenService: TokenService,
eventService: EventService,
signupService: SignupService
)(implicit ec: ExecutionContext, webJarsUtil: WebJarsUtil)
extends InjectedController
extends BaseController
with Operators.Common {

import dependencies.ioRuntime
Expand Down Expand Up @@ -129,7 +130,7 @@ class LoginController @Inject() (
)(implicit request: Request[AnyContent]) = {
// Note: we have a small race condition here
// this should be OK almost always
tokenService.create(token)
val _ = tokenService.create(token)
// Here we want to redirect some users to more useful pages:
// observer => /stats
val path: String = {
Expand Down
9 changes: 5 additions & 4 deletions app/controllers/MandatController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import models.jsonApiModels.mandat._
import modules.AppConfig
import org.webjars.play.WebJarsUtil
import play.api.libs.json.{JsError, JsString, JsValue, Json}
import play.api.mvc.{Action, AnyContent, InjectedController, PlayBodyParsers}
import play.api.mvc.{Action, AnyContent, BaseController, ControllerComponents, PlayBodyParsers}
import scala.concurrent.{ExecutionContext, Future}
import services.{
EventService,
Expand All @@ -28,6 +28,7 @@ import services.{
case class MandatController @Inject() (
bodyParsers: PlayBodyParsers,
config: AppConfig,
val controllerComponents: ControllerComponents,
eventService: EventService,
loginAction: LoginAction,
mandatService: MandatService,
Expand All @@ -37,7 +38,7 @@ case class MandatController @Inject() (
userGroupService: UserGroupService,
userService: UserService
)(implicit val ec: ExecutionContext, webJarsUtil: WebJarsUtil)
extends InjectedController
extends BaseController
with Operators.Common
with UserOperators {

Expand Down Expand Up @@ -68,7 +69,7 @@ case class MandatController @Inject() (
EventType.MandatGenerated,
s"Le mandat ${mandat.id.underlying} (version ${mandat.version}) a été créé."
)
notificationsService.mandatV2Generated(mandat.id, request.currentUser)
val _ = notificationsService.mandatV2Generated(mandat.id, request.currentUser)
Ok(Json.toJson(mandat))
}
)
Expand Down Expand Up @@ -132,7 +133,7 @@ case class MandatController @Inject() (
s"Le mandat par SMS ${mandat.id.underlying} a été créé. " +
s"Le SMS de demande ${sms.apiId.underlying} a été envoyé"
)
notificationsService.mandatSmsSent(mandat.id, request.currentUser)
val _ = notificationsService.mandatSmsSent(mandat.id, request.currentUser)
Ok(Json.toJson(mandat))
}
)
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/SignupController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import modules.AppConfig
import org.webjars.play.WebJarsUtil
import play.api.data.Form
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, InjectedController, Request, Result}
import play.api.mvc.{Action, AnyContent, BaseController, ControllerComponents, Request, Result}
import scala.concurrent.{ExecutionContext, Future}
import scala.util.Try
import serializers.Keys
Expand All @@ -34,6 +34,7 @@ import services.{
@Singleton
case class SignupController @Inject() (
config: AppConfig,
val controllerComponents: ControllerComponents,
dependencies: ServicesDependencies,
eventService: EventService,
groupService: UserGroupService,
Expand All @@ -42,7 +43,7 @@ case class SignupController @Inject() (
signupService: SignupService,
userService: UserService,
)(implicit ec: ExecutionContext, webJarsUtil: WebJarsUtil)
extends InjectedController
extends BaseController
with I18nSupport
with Operators.Common
with UserOperators {
Expand Down
Loading

0 comments on commit 52b9ae0

Please sign in to comment.