Skip to content
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
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please test edge cases:

  • invalid blob
  • blob is not an ICS
  • missing capability
  • etc...


@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)
}

}
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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import org.apache.james.core.Username;
import org.apache.james.jmap.mail.BlobIds;
import org.apache.james.mailbox.model.MessageId;
import org.reactivestreams.Publisher;

import com.linagora.tmail.james.jmap.method.CalendarEventAttendanceResults;
import com.linagora.tmail.james.jmap.model.CalendarEventReplyResults;
import com.linagora.tmail.james.jmap.model.LanguageLocation;

public interface EventAttendanceRepository {
Publisher<AttendanceStatus> getAttendanceStatus(Username username, MessageId messageId);
Publisher<CalendarEventAttendanceResults> getAttendanceStatus(Username username, BlobIds calendarEventBlobIds);

Publisher<CalendarEventReplyResults> setAttendanceStatus(Username username, AttendanceStatus attendanceStatus,
BlobIds eventBlobIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;
import scala.util.Failure;
import scala.util.Success;
import scala.util.Try;

public final class MessagePartBlobId {
private static final Pattern MESSAGE_PART_BLOB_ID_PATTERN =
Expand Down Expand Up @@ -40,6 +43,14 @@ public MessagePartBlobId(String value) {
.toList();
}

public static Try<MessagePartBlobId> tryParse(String blobId) {
try {
return new Success<>(new MessagePartBlobId(blobId));
} catch (Exception e) {
return new Failure<>(e);
}
}

public String getMessageId() {
return messageId;
}
Expand Down
Loading