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

Allow to skip questions during checkin #35

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -43,16 +43,16 @@
inner class ApiResponse(val data: JSONObject?, val response: Response)

@Throws(ApiException::class, JSONException::class)
fun redeem(eventSlug: String, secret: String, datetime: Date?, force: Boolean, nonce: String?, answers: List<Answer>?, listId: Long, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, source_type: String?, callTimeout: Long? = null): ApiResponse {
fun redeem(eventSlug: String, secret: String, datetime: Date?, force: Boolean, nonce: String?, answers: List<Answer>?, listId: Long, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, source_type: String?, callTimeout: Long? = null, questions_supported: Boolean = true): ApiResponse {

Check warning on line 46 in libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt

View check run for this annotation

Codecov / codecov/patch

libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt#L46

Added line #L46 was not covered by tests
var dt: String? = null
if (datetime != null) {
dt = QueuedCheckIn.formatDatetime(datetime)
}
return redeem(eventSlug, secret, dt, force, nonce, answers, listId, ignore_unpaid, pdf_data, type, source_type, callTimeout)
return redeem(eventSlug, secret, dt, force, nonce, answers, listId, ignore_unpaid, pdf_data, type, source_type, callTimeout, questions_supported)

Check warning on line 51 in libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt

View check run for this annotation

Codecov / codecov/patch

libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt#L51

Added line #L51 was not covered by tests
}

@Throws(ApiException::class, JSONException::class)
open fun redeem(eventSlug: String, secret: String, datetime: String?, force: Boolean, nonce: String?, answers: List<Answer>?, listId: Long, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, source_type: String?, callTimeout: Long? = null): ApiResponse {
open fun redeem(eventSlug: String, secret: String, datetime: String?, force: Boolean, nonce: String?, answers: List<Answer>?, listId: Long, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, source_type: String?, callTimeout: Long? = null, questions_supported: Boolean=true): ApiResponse {

Check warning on line 55 in libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt

View check run for this annotation

Codecov / codecov/patch

libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt#L55

Added line #L55 was not covered by tests
val body = JSONObject()
if (datetime != null) {
body.put("datetime", datetime)
Expand Down Expand Up @@ -80,7 +80,7 @@
}
}
body.put("answers", answerbody)
body.put("questions_supported", true)
body.put("questions_supported", questions_supported)

Check warning on line 83 in libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt

View check run for this annotation

Codecov / codecov/patch

libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt#L83

Added line #L83 was not covered by tests
body.put("canceled_supported", true)
var pd = ""
if (pdf_data) {
Expand All @@ -90,16 +90,16 @@
}

@Throws(ApiException::class, JSONException::class)
fun redeem(lists: List<Long>, secret: String, datetime: Date?, force: Boolean, nonce: String?, answers: List<Answer>?, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, callTimeout: Long? = null): ApiResponse {
fun redeem(lists: List<Long>, secret: String, datetime: Date?, force: Boolean, nonce: String?, answers: List<Answer>?, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, callTimeout: Long? = null, questions_supported: Boolean = true): ApiResponse {

Check warning on line 93 in libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt

View check run for this annotation

Codecov / codecov/patch

libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt#L93

Added line #L93 was not covered by tests
var dt: String? = null
if (datetime != null) {
dt = QueuedCheckIn.formatDatetime(datetime)
}
return redeem(lists, secret, dt, force, nonce, answers, ignore_unpaid, pdf_data, type, callTimeout)
return redeem(lists, secret, dt, force, nonce, answers, ignore_unpaid, pdf_data, type, callTimeout, questions_supported)

Check warning on line 98 in libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt

View check run for this annotation

Codecov / codecov/patch

libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt#L98

Added line #L98 was not covered by tests
}

@Throws(ApiException::class, JSONException::class)
open fun redeem(lists: List<Long>, secret: String, datetime: String?, force: Boolean, nonce: String?, answers: List<Answer>?, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, callTimeout: Long? = null): ApiResponse {
open fun redeem(lists: List<Long>, secret: String, datetime: String?, force: Boolean, nonce: String?, answers: List<Answer>?, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, callTimeout: Long? = null, questions_supported: Boolean = true): ApiResponse {

Check warning on line 102 in libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt

View check run for this annotation

Codecov / codecov/patch

libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt#L102

Added line #L102 was not covered by tests
val body = JSONObject()
if (datetime != null) {
body.put("datetime", datetime)
Expand All @@ -126,7 +126,7 @@
}
}
body.put("answers", answerbody)
body.put("questions_supported", true)
body.put("questions_supported", questions_supported)

Check warning on line 129 in libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt

View check run for this annotation

Codecov / codecov/patch

libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt#L129

Added line #L129 was not covered by tests
body.put("canceled_supported", true)
body.put("secret", secret)
val jlists = JSONArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
return RSAResult(givenAnswers, requiredAnswers, shownAnswers, askQuestions)
}

private fun checkOfflineWithoutData(eventsAndCheckinLists: Map<String, Long>, ticketid: String, type: TicketCheckProvider.CheckInType, answers: List<Answer>?, nonce: String?): TicketCheckProvider.CheckResult {
private fun checkOfflineWithoutData(eventsAndCheckinLists: Map<String, Long>, ticketid: String, type: TicketCheckProvider.CheckInType, answers: List<Answer>?, nonce: String?, allowQuestions: Boolean): TicketCheckProvider.CheckResult {
val dt = now()
val events = dataStore.select(Event::class.java)
.where(Event.SLUG.`in`(eventsAndCheckinLists.keys.toList()))
Expand Down Expand Up @@ -429,7 +429,7 @@
var required_answers: MutableList<TicketCheckProvider.QuestionAnswer> = ArrayList()
var shown_answers: MutableList<TicketCheckProvider.QuestionAnswer> = ArrayList()
var ask_questions = false
if (type != TicketCheckProvider.CheckInType.EXIT) {
if (type != TicketCheckProvider.CheckInType.EXIT && allowQuestions) {
val rsa = extractRequiredShownAnswers(questions, answerMap)
givenAnswers = rsa.givenAnswers
required_answers = rsa.requiredAnswers
Expand Down Expand Up @@ -491,6 +491,7 @@
with_badge_data: Boolean,
type: TicketCheckProvider.CheckInType,
nonce: String?,
allowQuestions: Boolean,
): TicketCheckProvider.CheckResult {
sentry.addBreadcrumb("provider.check", "offline check started")

Expand Down Expand Up @@ -521,6 +522,7 @@
ignore_unpaid,
type,
nonce,
allowQuestions,
)
}

Expand All @@ -530,6 +532,7 @@
type,
answers ?: emptyList(),
nonce,
allowQuestions,
)
} else if (tickets.size > 1) {
val eventSlug = tickets[0].getOrder().getEvent_slug()
Expand All @@ -551,10 +554,10 @@
)
return TicketCheckProvider.CheckResult(TicketCheckProvider.CheckResult.Type.AMBIGUOUS)
}
return checkOfflineWithData(eventsAndCheckinLists, ticketid, tickets, answers, ignore_unpaid, type, nonce = nonce)
return checkOfflineWithData(eventsAndCheckinLists, ticketid, tickets, answers, ignore_unpaid, type, nonce = nonce, allowQuestions = allowQuestions)

Check warning on line 557 in libpretixsync/src/main/java/eu/pretix/libpretixsync/check/AsyncCheckProvider.kt

View check run for this annotation

Codecov / codecov/patch

libpretixsync/src/main/java/eu/pretix/libpretixsync/check/AsyncCheckProvider.kt#L557

Added line #L557 was not covered by tests
}

private fun checkOfflineWithData(eventsAndCheckinLists: Map<String, Long>, secret: String, tickets: List<OrderPosition>, answers: List<Answer>?, ignore_unpaid: Boolean, type: TicketCheckProvider.CheckInType, nonce: String?): TicketCheckProvider.CheckResult {
private fun checkOfflineWithData(eventsAndCheckinLists: Map<String, Long>, secret: String, tickets: List<OrderPosition>, answers: List<Answer>?, ignore_unpaid: Boolean, type: TicketCheckProvider.CheckInType, nonce: String?, allowQuestions: Boolean): TicketCheckProvider.CheckResult {

Check warning on line 560 in libpretixsync/src/main/java/eu/pretix/libpretixsync/check/AsyncCheckProvider.kt

View check run for this annotation

Codecov / codecov/patch

libpretixsync/src/main/java/eu/pretix/libpretixsync/check/AsyncCheckProvider.kt#L560

Added line #L560 was not covered by tests
// !!! When extending this, also extend checkOfflineWithoutData !!!
val dt = now()
val eventSlug = tickets[0].getOrder().getEvent_slug()
Expand Down Expand Up @@ -782,7 +785,7 @@
var required_answers: MutableList<TicketCheckProvider.QuestionAnswer> = ArrayList()
var shown_answers: MutableList<TicketCheckProvider.QuestionAnswer> = ArrayList()
var ask_questions = false
if (type != TicketCheckProvider.CheckInType.EXIT) {
if (type != TicketCheckProvider.CheckInType.EXIT && allowQuestions) {
val rsa = extractRequiredShownAnswers(questions, answerMap)
givenAnswers = rsa.givenAnswers
required_answers = rsa.requiredAnswers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
ignore_unpaid: Boolean,
with_badge_data: Boolean,
type: TicketCheckProvider.CheckInType,
nonce: String?
nonce: String?,
allowQuestions: Boolean
): TicketCheckProvider.CheckResult {
val ticketid_cleaned = ticketid.replace(Regex("[\\p{C}]"), "�") // remove unprintable characters
val nonce_cleaned = nonce ?: NonceGenerator.nextNonce()
Expand All @@ -68,6 +69,7 @@
with_badge_data,
type.toString().lowercase(Locale.getDefault()),
callTimeout = if (fallback != null) fallbackTimeout.toLong() else null,
questions_supported = allowQuestions,

Check warning on line 72 in libpretixsync/src/main/java/eu/pretix/libpretixsync/check/OnlineCheckProvider.kt

View check run for this annotation

Codecov / codecov/patch

libpretixsync/src/main/java/eu/pretix/libpretixsync/check/OnlineCheckProvider.kt#L72

Added line #L72 was not covered by tests
)
} else {
if (eventsAndCheckinLists.size != 1) throw CheckException("Multi-event scan not supported by server.")
Expand All @@ -84,6 +86,7 @@
type.toString().lowercase(Locale.getDefault()),
source_type,
callTimeout = if (fallback != null) fallbackTimeout.toLong() else null,
questions_supported = allowQuestions,

Check warning on line 89 in libpretixsync/src/main/java/eu/pretix/libpretixsync/check/OnlineCheckProvider.kt

View check run for this annotation

Codecov / codecov/patch

libpretixsync/src/main/java/eu/pretix/libpretixsync/check/OnlineCheckProvider.kt#L89

Added line #L89 was not covered by tests
)
}
if (responseObj.response.code == 404) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
ignore_unpaid: Boolean,
with_badge_data: Boolean,
type: TicketCheckProvider.CheckInType,
nonce: String?
nonce: String?,
allowQuestions: Boolean
): TicketCheckProvider.CheckResult {
val data: MutableMap<String, Any> = HashMap()
data["events_and_checkin_lists"] = eventsAndCheckinLists
Expand All @@ -113,6 +114,7 @@
data["with_badge_data"] = with_badge_data
data["source_type"] = source_type
data["type"] = type
data["allowQuestions"] = allowQuestions

Check warning on line 117 in libpretixsync/src/main/java/eu/pretix/libpretixsync/check/ProxyCheckProvider.kt

View check run for this annotation

Codecov / codecov/patch

libpretixsync/src/main/java/eu/pretix/libpretixsync/check/ProxyCheckProvider.kt#L117

Added line #L117 was not covered by tests
if (nonce != null) {
data["nonce"] = nonce
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ interface TicketCheckProvider {
class StatusResult(var eventName: String?, var totalTickets: Int, var alreadyScanned: Int, var currentlyInside: Int?, var items: List<StatusResultItem>?) {
}

fun check(eventsAndCheckinLists: Map<String, Long>, ticketid: String, source_type: String, answers: List<Answer>?, ignore_unpaid: Boolean, with_badge_data: Boolean, type: CheckInType, nonce: String? = null): CheckResult
fun check(eventsAndCheckinLists: Map<String, Long>, ticketid: String, source_type: String, answers: List<Answer>?, ignore_unpaid: Boolean, with_badge_data: Boolean, type: CheckInType, nonce: String? = null, allowQuestions: Boolean = true): CheckResult
fun check(eventsAndCheckinLists: Map<String, Long>, ticketid: String): CheckResult
@Throws(CheckException::class)
fun search(eventsAndCheckinLists: Map<String, Long>, query: String, page: Int): List<SearchResult>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,9 +728,9 @@
}
if (qci.getDatetime_string() == null || qci.getDatetime_string().equals("")) {
// Backwards compatibility
ar = api.redeem(qci.getEvent_slug(), qci.getSecret(), qci.getDatetime(), true, qci.getNonce(), answers, qci.checkinListId, false, false, qci.getType(), st, null);
ar = api.redeem(qci.getEvent_slug(), qci.getSecret(), qci.getDatetime(), true, qci.getNonce(), answers, qci.checkinListId, false, false, qci.getType(), st, null, false);

Check warning on line 731 in libpretixsync/src/main/java/eu/pretix/libpretixsync/sync/SyncManager.java

View check run for this annotation

Codecov / codecov/patch

libpretixsync/src/main/java/eu/pretix/libpretixsync/sync/SyncManager.java#L731

Added line #L731 was not covered by tests
} else {
ar = api.redeem(qci.getEvent_slug(), qci.getSecret(), qci.getDatetime_string(), true, qci.getNonce(), answers, qci.checkinListId, false, false, qci.getType(), st, null);
ar = api.redeem(qci.getEvent_slug(), qci.getSecret(), qci.getDatetime_string(), true, qci.getNonce(), answers, qci.checkinListId, false, false, qci.getType(), st, null, false);

Check warning on line 733 in libpretixsync/src/main/java/eu/pretix/libpretixsync/sync/SyncManager.java

View check run for this annotation

Codecov / codecov/patch

libpretixsync/src/main/java/eu/pretix/libpretixsync/sync/SyncManager.java#L733

Added line #L733 was not covered by tests
}
if (connectivityFeedback != null) {
connectivityFeedback.recordSuccess(System.currentTimeMillis() - startedAt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,14 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {
assertEquals(TicketCheckProvider.CheckResult.Type.VALID, r.type)
}

@Test
fun testQuestionsIgnored() {
QuestionSyncAdapter(dataStore, FakeFileStorage(), "demo", fakeApi, "", null).standaloneRefreshFromJSON(jsonResource("questions/question1.json"))

var r = p!!.check(mapOf("demo" to 1L), "kfndgffgyw4tdgcacx6bb3bgemq69cxj", "barcode", ArrayList(), false, true, TicketCheckProvider.CheckInType.ENTRY, allowQuestions = false)
assertEquals(TicketCheckProvider.CheckResult.Type.VALID, r.type)
}

@Test
fun testQuestionsRequired() {
QuestionSyncAdapter(dataStore, FakeFileStorage(), "demo", fakeApi, "", null).standaloneRefreshFromJSON(jsonResource("questions/question1.json"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class FakePretixApi : PretixApi("http://1.1.1.1/", "a", "demo", 1, DefaultHttpCl
ignore_unpaid: Boolean,
pdf_data: Boolean,
type: String?,
callTimeout: Long?
callTimeout: Long?,
questions_supported: Boolean
): ApiResponse {
redeemRequestSecret = secret
redeemRequestDatetime = datetime
Expand All @@ -65,7 +66,8 @@ class FakePretixApi : PretixApi("http://1.1.1.1/", "a", "demo", 1, DefaultHttpCl
pdf_data: Boolean,
type: String?,
source_type: String?,
callTimeout: Long?
callTimeout: Long?,
questions_supported: Boolean
): ApiResponse {
redeemRequestSecret = secret
redeemRequestDatetime = datetime
Expand Down
Loading