-
Notifications
You must be signed in to change notification settings - Fork 25
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
Introduce the CalendarEventAttendance/get JMAP method #1447
Merged
chibenwa
merged 8 commits into
linagora:master
from
HoussemNasri:introduce-get-attendance-jmap-api2
Jan 13, 2025
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
402ca81
Introduce the CalendarEventAttendance/get JMAP method
HoussemNasri a9ac2b8
Add a few integration tests
HoussemNasri 10357fb
Add more integration tests
HoussemNasri b0a0954
Return needsAction when mail message accessible but no flags attached
HoussemNasri cbb7e25
Fix failing tests
HoussemNasri 8e97b5a
Test behavior on delegation
HoussemNasri e890ebb
Fix formatting
HoussemNasri ecd7ac4
Document CalendarEventAttendance/get
HoussemNasri 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
308 changes: 308 additions & 0 deletions
308
...la/com/linagora/tmail/james/common/LinagoraCalendarEventAttendanceGetMethodContract.scala
This file contains 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,308 @@ | ||
package com.linagora.tmail.james.common | ||
|
||
import com.linagora.tmail.james.common.LinagoraCalendarEventMethodContractUtilities.sendInvitationEmailToBobAndGetIcsBlobIds | ||
import io.netty.handler.codec.http.HttpHeaderNames.ACCEPT | ||
import io.restassured.RestAssured.{`given`, requestSpecification} | ||
import io.restassured.http.ContentType.JSON | ||
import net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson | ||
import net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER | ||
import org.apache.http.HttpStatus.SC_OK | ||
import org.apache.james.GuiceJamesServer | ||
import org.apache.james.jmap.http.UserCredential | ||
import org.apache.james.jmap.rfc8621.contract.Fixture._ | ||
import org.apache.james.mailbox.model.MailboxPath | ||
import org.apache.james.modules.MailboxProbeImpl | ||
import org.apache.james.utils.DataProbeImpl | ||
import org.junit.jupiter.api.{BeforeEach, Test} | ||
|
||
trait LinagoraCalendarEventAttendanceGetMethodContract { | ||
|
||
@BeforeEach | ||
def setUp(server: GuiceJamesServer): Unit = { | ||
server.getProbe(classOf[DataProbeImpl]) | ||
.fluent | ||
.addDomain(_2_DOT_DOMAIN.asString) | ||
.addDomain(DOMAIN.asString) | ||
.addUser(BOB.asString, BOB_PASSWORD) | ||
.addUser(ALICE.asString, ALICE_PASSWORD) | ||
|
||
requestSpecification = baseRequestSpecBuilder(server) | ||
.setAuth(authScheme(UserCredential(BOB, BOB_PASSWORD))) | ||
.addHeader(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) | ||
.build | ||
|
||
server.getProbe(classOf[MailboxProbeImpl]).createMailbox(MailboxPath.inbox(BOB)) | ||
} | ||
|
||
@Test | ||
def shouldReturnAccepted(server: GuiceJamesServer): Unit = { | ||
val blobId: String = | ||
sendInvitationEmailToBobAndGetIcsBlobIds(server, "emailWithAliceInviteBobIcsAttachment.eml", icsPartId = "3") | ||
|
||
acceptInvitation(blobId) | ||
|
||
val request: String = | ||
s"""{ | ||
| "using": [ | ||
| "urn:ietf:params:jmap:core", | ||
| "com:linagora:params:calendar:event"], | ||
| "methodCalls": [[ | ||
| "CalendarEventAttendance/get", | ||
| { | ||
| "accountId": "$ACCOUNT_ID", | ||
| "blobIds": [ "$blobId" ] | ||
| }, | ||
| "c1"]] | ||
|}""".stripMargin | ||
|
||
val response = | ||
`given` | ||
.body(request) | ||
.when | ||
.post | ||
.`then` | ||
.statusCode(SC_OK) | ||
.contentType(JSON) | ||
.extract | ||
.body | ||
.asString | ||
|
||
assertThatJson(response) | ||
.inPath("methodResponses[0]") | ||
.isEqualTo( | ||
s"""|[ | ||
| "CalendarEventAttendance/get", | ||
| { | ||
| "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", | ||
| "accepted": ["$blobId"], | ||
| "rejected": [], | ||
| "tentativelyAccepted": [], | ||
| "needsAction": [] | ||
| }, | ||
| "c1" | ||
|]""".stripMargin | ||
) | ||
} | ||
|
||
@Test | ||
def shouldReturnRejected(server: GuiceJamesServer): Unit = { | ||
val blobId: String = | ||
sendInvitationEmailToBobAndGetIcsBlobIds(server, "emailWithAliceInviteBobIcsAttachment.eml", icsPartId = "3") | ||
|
||
rejectInvitation(blobId) | ||
|
||
val request: String = | ||
s"""{ | ||
| "using": [ | ||
| "urn:ietf:params:jmap:core", | ||
| "com:linagora:params:calendar:event"], | ||
| "methodCalls": [[ | ||
| "CalendarEventAttendance/get", | ||
| { | ||
| "accountId": "$ACCOUNT_ID", | ||
| "blobIds": [ "$blobId" ] | ||
| }, | ||
| "c1"]] | ||
|}""".stripMargin | ||
|
||
val response = | ||
`given` | ||
.body(request) | ||
.when | ||
.post | ||
.`then` | ||
.statusCode(SC_OK) | ||
.contentType(JSON) | ||
.extract | ||
.body | ||
.asString | ||
|
||
assertThatJson(response) | ||
.inPath("methodResponses[0]") | ||
.isEqualTo( | ||
s"""|[ | ||
| "CalendarEventAttendance/get", | ||
| { | ||
| "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", | ||
| "accepted": [], | ||
| "rejected": ["$blobId"], | ||
| "tentativelyAccepted": [], | ||
| "needsAction": [] | ||
| }, | ||
| "c1" | ||
|]""".stripMargin | ||
) | ||
} | ||
|
||
@Test | ||
def shouldReturnMaybe(server: GuiceJamesServer): Unit = { | ||
val blobId: String = | ||
sendInvitationEmailToBobAndGetIcsBlobIds(server, "emailWithAliceInviteBobIcsAttachment.eml", icsPartId = "3") | ||
|
||
maybeInvitation(blobId) | ||
|
||
val request: String = | ||
s"""{ | ||
| "using": [ | ||
| "urn:ietf:params:jmap:core", | ||
| "com:linagora:params:calendar:event"], | ||
| "methodCalls": [[ | ||
| "CalendarEventAttendance/get", | ||
| { | ||
| "accountId": "$ACCOUNT_ID", | ||
| "blobIds": [ "$blobId" ] | ||
| }, | ||
| "c1"]] | ||
|}""".stripMargin | ||
|
||
val response = | ||
`given` | ||
.body(request) | ||
.when | ||
.post | ||
.`then` | ||
.statusCode(SC_OK) | ||
.contentType(JSON) | ||
.extract | ||
.body | ||
.asString | ||
|
||
assertThatJson(response) | ||
.inPath("methodResponses[0]") | ||
.isEqualTo( | ||
s"""|[ | ||
| "CalendarEventAttendance/get", | ||
| { | ||
| "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", | ||
| "accepted": [], | ||
| "rejected": [], | ||
| "tentativelyAccepted": ["$blobId"], | ||
| "needsAction": [] | ||
| }, | ||
| "c1" | ||
|]""".stripMargin | ||
) | ||
} | ||
|
||
@Test | ||
def shouldReturnNeedsActionByDefault(server: GuiceJamesServer): Unit = { | ||
val blobId: String = | ||
sendInvitationEmailToBobAndGetIcsBlobIds(server, "emailWithAliceInviteBobIcsAttachment.eml", icsPartId = "3") | ||
|
||
val request: String = | ||
s"""{ | ||
| "using": [ | ||
| "urn:ietf:params:jmap:core", | ||
| "com:linagora:params:calendar:event"], | ||
| "methodCalls": [[ | ||
| "CalendarEventAttendance/get", | ||
| { | ||
| "accountId": "$ACCOUNT_ID", | ||
| "blobIds": [ "$blobId" ] | ||
| }, | ||
| "c1"]] | ||
|}""".stripMargin | ||
|
||
val response = | ||
`given` | ||
.body(request) | ||
.when | ||
.post | ||
.`then` | ||
.statusCode(SC_OK) | ||
.contentType(JSON) | ||
.extract | ||
.body | ||
.asString | ||
|
||
assertThatJson(response) | ||
.inPath("methodResponses[0]") | ||
.isEqualTo( | ||
s"""|[ | ||
| "CalendarEventAttendance/get", | ||
| { | ||
| "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", | ||
| "accepted": [], | ||
| "rejected": [], | ||
| "tentativelyAccepted": [], | ||
| "needsAction": ["$blobId"] | ||
| }, | ||
| "c1" | ||
|]""".stripMargin | ||
) | ||
} | ||
|
||
private def acceptInvitation(blobId: String) = { | ||
val request: String = | ||
s"""{ | ||
| "using": [ | ||
| "urn:ietf:params:jmap:core", | ||
| "com:linagora:params:calendar:event"], | ||
| "methodCalls": [[ | ||
| "CalendarEvent/accept", | ||
| { | ||
| "accountId": "$ACCOUNT_ID", | ||
| "blobIds": [ "$blobId" ] | ||
| }, | ||
| "c1"]] | ||
|}""".stripMargin | ||
|
||
`given` | ||
.body(request) | ||
.when | ||
.post | ||
.`then` | ||
.statusCode(SC_OK) | ||
.contentType(JSON) | ||
} | ||
|
||
private def rejectInvitation(blobId: String) = { | ||
val request: String = | ||
s"""{ | ||
| "using": [ | ||
| "urn:ietf:params:jmap:core", | ||
| "com:linagora:params:calendar:event"], | ||
| "methodCalls": [[ | ||
| "CalendarEvent/reject", | ||
| { | ||
| "accountId": "$ACCOUNT_ID", | ||
| "blobIds": [ "$blobId" ] | ||
| }, | ||
| "c1"]] | ||
|}""".stripMargin | ||
|
||
`given` | ||
.body(request) | ||
.when | ||
.post | ||
.`then` | ||
.statusCode(SC_OK) | ||
.contentType(JSON) | ||
} | ||
|
||
|
||
private def maybeInvitation(blobId: String) = { | ||
val request: String = | ||
s"""{ | ||
| "using": [ | ||
| "urn:ietf:params:jmap:core", | ||
| "com:linagora:params:calendar:event"], | ||
| "methodCalls": [[ | ||
| "CalendarEvent/maybe", | ||
| { | ||
| "accountId": "$ACCOUNT_ID", | ||
| "blobIds": [ "$blobId" ] | ||
| }, | ||
| "c1"]] | ||
|}""".stripMargin | ||
|
||
`given` | ||
.body(request) | ||
.when | ||
.post | ||
.`then` | ||
.statusCode(SC_OK) | ||
.contentType(JSON) | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...est/java/com/linagora/tmail/james/MemoryLinagoraCalendarEventAttendanceGetMethodTest.java
This file contains 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,34 @@ | ||
package com.linagora.tmail.james; | ||
|
||
import static org.apache.james.data.UsersRepositoryModuleChooser.Implementation.DEFAULT; | ||
|
||
import org.apache.james.JamesServerBuilder; | ||
import org.apache.james.JamesServerExtension; | ||
import org.apache.james.jmap.rfc8621.contract.probe.DelegationProbeModule; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.linagora.tmail.james.app.MemoryConfiguration; | ||
import com.linagora.tmail.james.app.MemoryServer; | ||
import com.linagora.tmail.james.common.LinagoraCalendarEventAcceptMethodContract; | ||
import com.linagora.tmail.james.common.LinagoraCalendarEventAttendanceGetMethodContract; | ||
import com.linagora.tmail.james.jmap.firebase.FirebaseModuleChooserConfiguration; | ||
import com.linagora.tmail.module.LinagoraTestJMAPServerModule; | ||
|
||
import java.util.UUID; | ||
|
||
public class MemoryLinagoraCalendarEventAttendanceGetMethodTest implements | ||
LinagoraCalendarEventAttendanceGetMethodContract { | ||
|
||
@RegisterExtension | ||
static JamesServerExtension | ||
jamesServerExtension = new JamesServerBuilder<MemoryConfiguration>(tmpDir -> | ||
MemoryConfiguration.builder() | ||
.workingDirectory(tmpDir) | ||
.configurationFromClasspath() | ||
.usersRepository(DEFAULT) | ||
.firebaseModuleChooserConfiguration(FirebaseModuleChooserConfiguration.DISABLED) | ||
.build()) | ||
.server(configuration -> MemoryServer.createServer(configuration) | ||
.overrideWith(new LinagoraTestJMAPServerModule(), new DelegationProbeModule())) | ||
.build(); | ||
} |
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please test edge cases: