-
Notifications
You must be signed in to change notification settings - Fork 0
feat: auto delete myndla users after inactivity #864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b3e7637
feat: auto delete myndla users after inactivity
jnatten 3d26786
refactor: remove unused function
jnatten b717e9a
chore(myndla-api): add explanatory comment to `getUsersToEmail`
jnatten 2a98d59
refactor(myndla-api): move `UserService` constants into companion object
jnatten 4d04b15
refactor(myndla-api): attempt to simplify `cleanupInactiveUsers` logic
jnatten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
common/src/main/scala/no/ndla/common/aws/NdlaEmailClient.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Part of NDLA common | ||
| * Copyright (C) 2026 NDLA | ||
| * | ||
| * See LICENSE | ||
| * | ||
| */ | ||
|
|
||
| package no.ndla.common.aws | ||
|
|
||
| import no.ndla.common.TryUtil.throwIfInterrupted | ||
| import software.amazon.awssdk.regions.Region | ||
| import software.amazon.awssdk.services.sesv2.{SesV2Client, SesV2ClientBuilder} | ||
| import software.amazon.awssdk.services.sesv2.model.* | ||
|
|
||
| import scala.util.Try | ||
|
|
||
| class NdlaEmailClient(senderEmail: String, senderName: String, region: Option[String]) { | ||
| lazy val client: SesV2Client = { | ||
| val builder: SesV2ClientBuilder = SesV2Client.builder() | ||
| region match { | ||
| case Some(value) => builder.region(Region.of(value)).build() | ||
| case None => builder.build() | ||
| } | ||
| } | ||
|
|
||
| def sendEmail(to: String, subject: String, bodyStr: String): Try[Boolean] = { | ||
| Try.throwIfInterrupted { | ||
| val destination = Destination.builder().toAddresses(to).build() | ||
| val content = Content.builder().data(bodyStr).build() | ||
| val sub = Content.builder().data(subject).build() | ||
| val body = Body.builder().html(content).build() | ||
| val msg = Message.builder().subject(sub).body(body).build() | ||
| val bodyEmailContent = EmailContent.builder().simple(msg).build() | ||
| val emailRequest = SendEmailRequest | ||
| .builder() | ||
| .destination(destination) | ||
| .fromEmailAddress(s"$senderName <$senderEmail>") | ||
| .content(bodyEmailContent) | ||
| .build() | ||
|
|
||
| val response = client.sendEmail(emailRequest) | ||
|
|
||
| Option(response.messageId()).exists(_.nonEmpty) | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
common/src/test/scala/no/ndla/common/aws/NdlaEmailClientIntegrationTest.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Part of NDLA common | ||
| * Copyright (C) 2026 NDLA | ||
| * | ||
| * See LICENSE | ||
| * | ||
| */ | ||
|
|
||
| package no.ndla.common.aws | ||
|
|
||
| import no.ndla.testbase.UnitTestSuiteBase | ||
|
|
||
| class NdlaEmailClientIntegrationTest extends UnitTestSuiteBase { | ||
| test("Send email via AWS SES (manual)") { | ||
| val areWeTesting = Option(System.getenv("NDLA_TEST_AWS_SES")).contains("true") | ||
| val to = Option(System.getenv("NDLA_TEST_AWS_SES_EMAIL")) | ||
| assume(areWeTesting && to.isDefined) | ||
|
|
||
| val client = new NdlaEmailClient( | ||
| senderEmail = "noreply@mail.test.ndla.no", | ||
| senderName = "NDLA-testing", | ||
| region = Some("eu-west-1"), | ||
| ) | ||
|
|
||
| val subject = "NDLA SES test email" | ||
| val body = "This is a test email sent by NdlaEmailClient via AWS SES." | ||
| val result = client.sendEmail(to.get, subject, body) | ||
| result.failIfFailure should be(true) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...pi/src/main/resources/no/ndla/myndlaapi/db/migration/V27__add_last_cleanup_date_table.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| CREATE TABLE user_cleanup_audit ( | ||
| id BIGINT GENERATED ALWAYS AS IDENTITY, | ||
| num_cleanup INT, | ||
| num_emailed INT, | ||
| last_cleanup_date TIMESTAMP | ||
| ); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
myndla-api/src/main/scala/no/ndla/myndlaapi/model/api/InactiveUserResultDTO.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /* | ||
| * Part of NDLA myndla-api | ||
| * Copyright (C) 2026 NDLA | ||
| * | ||
| * See LICENSE | ||
| * | ||
| */ | ||
|
|
||
| package no.ndla.myndlaapi.model.api | ||
|
|
||
| import io.circe.{Decoder, Encoder} | ||
| import io.circe.generic.semiauto.* | ||
|
|
||
| case class InactiveUserResultDTO(numberOfUsersDeleted: Int, numberOfUsersEmailed: Int) | ||
|
|
||
| object InactiveUserResultDTO { | ||
| implicit def encoder: Encoder[InactiveUserResultDTO] = deriveEncoder[InactiveUserResultDTO] | ||
| implicit def decoder: Decoder[InactiveUserResultDTO] = deriveDecoder[InactiveUserResultDTO] | ||
| } |
13 changes: 13 additions & 0 deletions
13
myndla-api/src/main/scala/no/ndla/myndlaapi/model/domain/InactiveUserCleanupResult.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /* | ||
| * Part of NDLA myndla-api | ||
| * Copyright (C) 2026 NDLA | ||
| * | ||
| * See LICENSE | ||
| * | ||
| */ | ||
|
|
||
| package no.ndla.myndlaapi.model.domain | ||
|
|
||
| import no.ndla.common.model.NDLADate | ||
|
|
||
| case class InactiveUserCleanupResult(id: Long, numCleanup: Int, numEmailed: Int, lastCleanupDate: NDLADate) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.