diff --git a/app/controllers/UserReportsFiltersController.scala b/app/controllers/UserReportsFiltersController.scala deleted file mode 100644 index 366819770..000000000 --- a/app/controllers/UserReportsFiltersController.scala +++ /dev/null @@ -1,89 +0,0 @@ -package controllers - -import authentication.Authenticator -import models.User -import models.UserPermission -import models.report.ReportFilter -import orchestrators.UserReportsFiltersOrchestrator -import play.api.libs.json.JsError -import play.api.libs.json.JsValue -import play.api.libs.json.Json -import play.api.libs.json.Reads -import play.api.mvc.Action -import play.api.mvc.AnyContent -import play.api.mvc.ControllerComponents -import authentication.actions.UserAction.WithPermission - -import scala.concurrent.ExecutionContext -import scala.concurrent.Future - -class UserReportsFiltersController( - userReportsFiltersOrchestrator: UserReportsFiltersOrchestrator, - authenticator: Authenticator[User], - controllerComponents: ControllerComponents -)(implicit val ec: ExecutionContext) - extends BaseController(authenticator, controllerComponents) { - - case class UserReportsFiltersRequest(name: String, filters: ReportFilter) - - implicit val userReportsFiltersRequestReads: Reads[UserReportsFiltersRequest] = Json.reads[UserReportsFiltersRequest] - - def save(): Action[JsValue] = - SecuredAction.andThen(WithPermission(UserPermission.crudUserReportsFilters)).async(parse.json) { implicit request => - request.body - .validate[UserReportsFiltersRequest] - .fold( - errors => Future.successful(BadRequest(JsError.toJson(errors))), - userReportsFiltersRequest => - userReportsFiltersOrchestrator - .save(request.identity.id, userReportsFiltersRequest.name, (request.body \ "filters").as[JsValue]) - .map(_ => NoContent) - ) - } - - def get(name: String): Action[AnyContent] = - SecuredAction.andThen(WithPermission(UserPermission.crudUserReportsFilters)).async { implicit request => - userReportsFiltersOrchestrator - .get(request.identity.id, name) - .map { - case Some(userReportsFilters) => Ok(Json.toJson(userReportsFilters.reportsFilters)) - case None => NotFound - } - } - - def list(): Action[AnyContent] = - SecuredAction.andThen(WithPermission(UserPermission.crudUserReportsFilters)).async { implicit request => - userReportsFiltersOrchestrator - .list(request.identity.id) - .map(userReportsFiltersList => Ok(Json.toJson(userReportsFiltersList))) - } - - def delete(name: String): Action[AnyContent] = - SecuredAction.andThen(WithPermission(UserPermission.crudUserReportsFilters)).async { implicit request => - userReportsFiltersOrchestrator - .delete(request.identity.id, name) - .map(_ => NoContent) - } - - def rename(oldName: String, newName: String): Action[AnyContent] = - SecuredAction.andThen(WithPermission(UserPermission.crudUserReportsFilters)).async { implicit request => - userReportsFiltersOrchestrator - .rename(request.identity.id, oldName, newName) - .map(_ => NoContent) - } - - def setAsDefault(name: String): Action[AnyContent] = - SecuredAction.andThen(WithPermission(UserPermission.crudUserReportsFilters)).async { implicit request => - userReportsFiltersOrchestrator - .setAsDefault(request.identity.id, name) - .map(_ => NoContent) - } - - def unsetDefault(name: String): Action[AnyContent] = - SecuredAction.andThen(WithPermission(UserPermission.crudUserReportsFilters)).async { implicit request => - userReportsFiltersOrchestrator - .unsetDefault(request.identity.id, name) - .map(_ => NoContent) - } - -} diff --git a/app/loader/SignalConsoApplicationLoader.scala b/app/loader/SignalConsoApplicationLoader.scala index b4812f321..0bb0ff4b8 100644 --- a/app/loader/SignalConsoApplicationLoader.scala +++ b/app/loader/SignalConsoApplicationLoader.scala @@ -85,8 +85,6 @@ import repositories.subscription.SubscriptionRepositoryInterface import repositories.tasklock.TaskRepository import repositories.user.UserRepository import repositories.user.UserRepositoryInterface -import repositories.usersettings.UserReportsFiltersRepository -import repositories.usersettings.UserReportsFiltersRepositoryInterface import repositories.website.WebsiteRepository import repositories.website.WebsiteRepositoryInterface import services._ @@ -734,14 +732,6 @@ class SignalConsoComponents( controllerComponents ) - val userReportsFiltersRepository: UserReportsFiltersRepositoryInterface = new UserReportsFiltersRepository(dbConfig) - val userReportsFiltersOrchestrator = new UserReportsFiltersOrchestrator(userReportsFiltersRepository) - val userReportsFiltersController = new UserReportsFiltersController( - userReportsFiltersOrchestrator, - cookieAuthenticator, - controllerComponents - ) - val siretExtractorService = new SiretExtractorService(applicationConfiguration.siretExtractor) val siretExtractorController = new SiretExtractorController(siretExtractorService, cookieAuthenticator, controllerComponents) @@ -813,7 +803,6 @@ class SignalConsoComponents( reportedPhoneController, reportBlockedNotificationController, blacklistedEmailsController, - userReportsFiltersController, signalConsoReviewController, siretExtractorController, importController, diff --git a/app/models/User.scala b/app/models/User.scala index ca9364ca1..dc61d0253 100644 --- a/app/models/User.scala +++ b/app/models/User.scala @@ -51,7 +51,7 @@ object User { object UserPermission extends Enumeration { val listReports, updateReport, deleteReport, deleteFile, createReportAction, activateAccount, updateCompany, editDocuments, subscribeReports, manageAdminOrAgentUsers, softDeleteUsers, viewDeletedUsers, - manageBlacklistedEmails, crudUserReportsFilters, generateConsumerReportEmailAsPDF, viewConsumerReviewDetails = + manageBlacklistedEmails, generateConsumerReportEmailAsPDF, viewConsumerReviewDetails = Value implicit val enumReads: Reads[UserPermission.Value] = EnumUtils.enumReads(UserPermission) diff --git a/app/models/UserReportsFilters.scala b/app/models/UserReportsFilters.scala deleted file mode 100644 index d7c9edf53..000000000 --- a/app/models/UserReportsFilters.scala +++ /dev/null @@ -1,19 +0,0 @@ -package models - -import play.api.libs.json.JsValue -import play.api.libs.json.Json -import play.api.libs.json.Writes - -import java.util.UUID - -case class UserReportsFilters(userId: UUID, name: String, reportsFilters: JsValue, defaultFilters: Boolean = false) - -object UserReportsFilters { - implicit val writes: Writes[UserReportsFilters] = Writes { userReportsFilters => - Json.obj( - "name" -> userReportsFilters.name, - "filters" -> userReportsFilters.reportsFilters, - "default" -> userReportsFilters.defaultFilters - ) - } -} diff --git a/app/models/UserRole.scala b/app/models/UserRole.scala index 835e12053..9c6bcd949 100644 --- a/app/models/UserRole.scala +++ b/app/models/UserRole.scala @@ -21,7 +21,6 @@ object UserRole extends PlayEnum[UserRole] { UserPermission.listReports, UserPermission.createReportAction, UserPermission.subscribeReports, - UserPermission.crudUserReportsFilters, UserPermission.viewConsumerReviewDetails ) override val isAgentOrAdmin = true @@ -32,7 +31,6 @@ object UserRole extends PlayEnum[UserRole] { UserPermission.listReports, UserPermission.createReportAction, UserPermission.subscribeReports, - UserPermission.crudUserReportsFilters, UserPermission.viewConsumerReviewDetails ) override val isAgentOrAdmin = true diff --git a/app/orchestrators/UserReportsFiltersOrchestrator.scala b/app/orchestrators/UserReportsFiltersOrchestrator.scala deleted file mode 100644 index 6ef3b06e3..000000000 --- a/app/orchestrators/UserReportsFiltersOrchestrator.scala +++ /dev/null @@ -1,32 +0,0 @@ -package orchestrators - -import models.UserReportsFilters -import play.api.libs.json.JsValue -import repositories.usersettings.UserReportsFiltersRepositoryInterface - -import java.util.UUID -import scala.concurrent.Future - -class UserReportsFiltersOrchestrator(userReportsFiltersRepository: UserReportsFiltersRepositoryInterface) { - def save(userId: UUID, name: String, filters: JsValue): Future[UserReportsFilters] = - userReportsFiltersRepository.createOrUpdate(UserReportsFilters(userId, name, filters)) - - def get(userId: UUID, name: String): Future[Option[UserReportsFilters]] = - userReportsFiltersRepository.get(userId, name) - - def list(userId: UUID): Future[List[UserReportsFilters]] = - userReportsFiltersRepository.list(userId) - - def delete(userId: UUID, name: String): Future[Unit] = - userReportsFiltersRepository.delete(userId, name) - - def rename(userId: UUID, oldName: String, newName: String): Future[Unit] = - userReportsFiltersRepository.rename(userId, oldName, newName) - - def setAsDefault(userId: UUID, name: String): Future[Unit] = - userReportsFiltersRepository.setAsDefault(userId, name) - - def unsetDefault(userId: UUID, name: String): Future[Unit] = - userReportsFiltersRepository.unsetDefault(userId, name) - -} diff --git a/app/repositories/usersettings/UserReportsFiltersRepository.scala b/app/repositories/usersettings/UserReportsFiltersRepository.scala deleted file mode 100644 index 1b9350e78..000000000 --- a/app/repositories/usersettings/UserReportsFiltersRepository.scala +++ /dev/null @@ -1,47 +0,0 @@ -package repositories.usersettings - -import models.UserReportsFilters -import slick.basic.DatabaseConfig -import slick.jdbc.JdbcProfile - -import java.util.UUID -import scala.concurrent.ExecutionContext -import scala.concurrent.Future - -class UserReportsFiltersRepository(val dbConfig: DatabaseConfig[JdbcProfile])(implicit val ec: ExecutionContext) - extends UserReportsFiltersRepositoryInterface { - - import repositories.PostgresProfile.api._ - import dbConfig._ - - val table: TableQuery[UserReportsFiltersTable] = TableQuery[UserReportsFiltersTable] - - override def createOrUpdate(element: UserReportsFilters): Future[UserReportsFilters] = - db.run( - table - .insertOrUpdate(element) - .map(_ => element) - ) - - override def get(userId: UUID, name: String): Future[Option[UserReportsFilters]] = - db.run(table.filter(_.user_id === userId).filter(_.name === name).result.headOption) - - override def list(userId: UUID): Future[List[UserReportsFilters]] = - db.run(table.filter(_.user_id === userId).to[List].result) - - override def delete(userId: UUID, name: String): Future[Unit] = - db.run(table.filter(_.user_id === userId).filter(_.name === name).delete).map(_ => ()) - - override def rename(userId: UUID, oldName: String, newName: String): Future[Unit] = - db.run(table.filter(_.user_id === userId).filter(_.name === oldName).map(_.name).update(newName)).map(_ => ()) - - override def setAsDefault(userId: UUID, name: String): Future[Unit] = { - val removeDefault = - table.filter(_.user_id === userId).filter(_.default_filters === true).map(_.default_filters).update(false) - val setDefault = table.filter(_.user_id === userId).filter(_.name === name).map(_.default_filters).update(true) - db.run(DBIO.seq(removeDefault, setDefault)) - } - - override def unsetDefault(userId: UUID, name: String): Future[Unit] = - db.run(table.filter(_.user_id === userId).filter(_.name === name).map(_.default_filters).update(false)).map(_ => ()) -} diff --git a/app/repositories/usersettings/UserReportsFiltersRepositoryInterface.scala b/app/repositories/usersettings/UserReportsFiltersRepositoryInterface.scala deleted file mode 100644 index 122578b67..000000000 --- a/app/repositories/usersettings/UserReportsFiltersRepositoryInterface.scala +++ /dev/null @@ -1,22 +0,0 @@ -package repositories.usersettings - -import models.UserReportsFilters - -import java.util.UUID -import scala.concurrent.Future - -trait UserReportsFiltersRepositoryInterface { - def createOrUpdate(element: UserReportsFilters): Future[UserReportsFilters] - - def get(userId: UUID, name: String): Future[Option[UserReportsFilters]] - - def list(userId: UUID): Future[List[UserReportsFilters]] - - def delete(userId: UUID, name: String): Future[Unit] - - def rename(userId: UUID, oldName: String, newName: String): Future[Unit] - - def setAsDefault(userId: UUID, name: String): Future[Unit] - - def unsetDefault(userId: UUID, name: String): Future[Unit] -} diff --git a/app/repositories/usersettings/UserReportsFiltersTable.scala b/app/repositories/usersettings/UserReportsFiltersTable.scala deleted file mode 100644 index 4c4088d6b..000000000 --- a/app/repositories/usersettings/UserReportsFiltersTable.scala +++ /dev/null @@ -1,25 +0,0 @@ -package repositories.usersettings - -import models.UserReportsFilters -import play.api.libs.json.JsValue -import repositories.PostgresProfile.api._ -import slick.lifted.ProvenShape - -import java.util.UUID - -class UserReportsFiltersTable(tag: Tag) extends Table[UserReportsFilters](tag, "user_reports_filters") { - - def user_id = column[UUID]("user_id") - def name = column[String]("name") - def reports_filters = column[JsValue]("filters") - def default_filters = column[Boolean]("default_filters") - def pk = primaryKey("pk_user_id_name", (user_id, name)) - - override def * : ProvenShape[UserReportsFilters] = - ( - user_id, - name, - reports_filters, - default_filters - ) <> ((UserReportsFilters.apply _).tupled, UserReportsFilters.unapply) -} diff --git a/conf/db/migration/default/V36__drop_filters.sql b/conf/db/migration/default/V36__drop_filters.sql new file mode 100644 index 000000000..0b019b8f5 --- /dev/null +++ b/conf/db/migration/default/V36__drop_filters.sql @@ -0,0 +1 @@ +DROP TABLE user_reports_filters \ No newline at end of file diff --git a/conf/routes b/conf/routes index 0d199ba34..f4c109bbf 100644 --- a/conf/routes +++ b/conf/routes @@ -205,14 +205,6 @@ GET /api/blacklisted-ips controll POST /api/blacklisted-ips controllers.AdminController.createBlacklistedIp() DELETE /api/blacklisted-ips/:ip controllers.AdminController.deleteBlacklistedIp(ip: String) -POST /api/user-reports-filters controllers.UserReportsFiltersController.save() -GET /api/user-reports-filters/:name controllers.UserReportsFiltersController.get(name: String) -GET /api/user-reports-filters controllers.UserReportsFiltersController.list() -DELETE /api/user-reports-filters/:name controllers.UserReportsFiltersController.delete(name) -PUT /api/user-reports-filters/rename/:oldName/:newName controllers.UserReportsFiltersController.rename(oldName, newName) -PUT /api/user-reports-filters/default/:name controllers.UserReportsFiltersController.setAsDefault(name) -DELETE /api/user-reports-filters/default/:name controllers.UserReportsFiltersController.unsetDefault(name) - GET /api/review controllers.SignalConsoReviewController.signalConsoReview() # Siret extractor gateway diff --git a/test/controllers/UserReportsFiltersControllerSpec.scala b/test/controllers/UserReportsFiltersControllerSpec.scala deleted file mode 100644 index 6f7176617..000000000 --- a/test/controllers/UserReportsFiltersControllerSpec.scala +++ /dev/null @@ -1,157 +0,0 @@ -package controllers - -import models.UserReportsFilters -import org.specs2.concurrent.ExecutionEnv -import org.specs2.matcher.FutureMatchers -import org.specs2.mutable.Specification -import play.api.libs.json.JsValue -import play.api.libs.json.Json -import play.api.mvc.Results -import play.api.test.FakeRequest -import play.api.test.Helpers._ -import utils.AppSpec -import utils.Fixtures -import utils.TestApp -import utils.AuthHelpers._ - -import scala.concurrent.Await -import scala.concurrent.duration.Duration - -class UserReportsFiltersControllerSpec(implicit ee: ExecutionEnv) - extends Specification - with AppSpec - with Results - with FutureMatchers { - - val user = Fixtures.genDgccrfUser.sample.get - val user2 = Fixtures.genDgccrfUser.sample.get - - val (app, components) = TestApp.buildApp( - ) - - override def afterAll(): Unit = { - app.stop() - () - } - - lazy val userRepository = components.userRepository - lazy val userReportsFiltersRepository = components.userReportsFiltersRepository - - override def setupData() = - Await.result( - for { - _ <- userRepository.create(user) - _ <- userRepository.create(user2) - } yield (), - Duration.Inf - ) - - "UserReportsFiltersController" should { - sequential - "list only filters of the user" in { - val request = FakeRequest(GET, routes.UserReportsFiltersController.list().toString) - .withAuthCookie(user.email, components.cookieAuthenticator) - - val result = for { - _ <- userReportsFiltersRepository.createOrUpdate(UserReportsFilters(user.id, "test_list", Json.obj())) - _ <- userReportsFiltersRepository.createOrUpdate(UserReportsFilters(user2.id, "test_list", Json.obj())) - res <- route(app, request).get - } yield res - - status(result) must beEqualTo(OK) - contentAsJson(result).as[List[JsValue]] must haveLength(1) - } - "save minimal reports filters" in { - val jsonBody = Json.obj( - "name" -> "test", - "filters" -> Json.obj() - ) - - val request = FakeRequest(POST, routes.UserReportsFiltersController.save().toString) - .withJsonBody(jsonBody) - .withAuthCookie(user.email, components.cookieAuthenticator) - - val result = for { - res <- route(app, request).get - savedFilters <- userReportsFiltersRepository.get(user.id, "test") - } yield (res, savedFilters.get.reportsFilters) - - status(result.map(_._1)) must beEqualTo(NO_CONTENT) - result.map(_._2) must beEqualTo(Json.obj()).await - - } - "save full reports filters" in { - val jsonString = - """ - |{ - | "withTags": [ - | "DemarchageTelephonique", - | "DemarchageInternet" - | ], - | "withoutTags": [ - | "AbsenceDeMediateur" - | ], - | "companyCountries": [ - | "CY", - | "HR" - | ], - | "siretSirenList": [ - | "12345" - | ], - | "activityCodes": [ - | "01.12Z", - | "01.13Z" - | ], - | "status": [ - | "TraitementEnCours", - | "Transmis" - | ], - | "email": "c", - | "websiteURL": "a", - | "phone": "b", - | "category": "Eau / Gaz / Electricité", - | "details": "test", - | "contactAgreement": false, - | "hasPhone": true, - | "hasWebsite": true, - | "hasForeignCountry": true, - | "hasCompany": true, - | "hasAttachment": true - |} - |""".stripMargin - val jsonBody = Json.obj( - "name" -> "test", - "filters" -> Json.parse(jsonString) - ) - - val request = FakeRequest(POST, routes.UserReportsFiltersController.save().toString) - .withJsonBody(jsonBody) - .withAuthCookie(user.email, components.cookieAuthenticator) - - val result = for { - res <- route(app, request).get - savedFilters <- userReportsFiltersRepository.get(user.id, "test") - } yield (res, savedFilters.get.reportsFilters) - - status(result.map(_._1)) must beEqualTo(NO_CONTENT) - result.map(_._2) must beEqualTo(Json.parse(jsonString)).await - } - - "reject when user is not authenticated" in { - val jsonBody = Json.obj( - "name" -> "", - "filters" -> Json.obj("test" -> "test") - ) - - val request = FakeRequest(POST, routes.UserReportsFiltersController.save().toString) - .withJsonBody(jsonBody) - - val result = for { - res <- route(app, request).get - } yield res - - status(result) must beEqualTo(UNAUTHORIZED) - - } - } -}