Skip to content

Commit 4b661d5

Browse files
committed
JMAP/changes: Update newState with last changeId if an invalid fromChangeId is provided
1 parent 1fbc7c0 commit 4b661d5

File tree

2 files changed

+33
-38
lines changed
  • crates

2 files changed

+33
-38
lines changed

crates/jmap/src/participant_identity/set.rs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ fn validate_identity_value(
199199
identity: &mut ParticipantIdentity,
200200
allowed_emails: &AHashSet<String>,
201201
) -> Result<(), SetError<ParticipantIdentityProperty>> {
202-
let mut changed_address = None;
203202
for (property, value) in update.into_expanded_object() {
204203
let Key::Property(property) = property else {
205204
return Err(SetError::invalid_properties()
@@ -213,7 +212,27 @@ fn validate_identity_value(
213212
}
214213
(ParticipantIdentityProperty::CalendarAddress, Value::Str(value)) => {
215214
if identity.calendar_address != value {
216-
changed_address = Some(value);
215+
let email = if let Some(email) = value.strip_prefix("mailto:") {
216+
sanitize_email(email)
217+
} else {
218+
sanitize_email(&value)
219+
};
220+
221+
if let Some(email) = email {
222+
if allowed_emails.iter().any(|e| e == &email) {
223+
identity.calendar_address = format!("mailto:{email}");
224+
} else {
225+
return Err(SetError::invalid_properties()
226+
.with_property(ParticipantIdentityProperty::CalendarAddress)
227+
.with_description(
228+
"Calendar address not configured for this account.".to_string(),
229+
));
230+
}
231+
} else {
232+
return Err(SetError::invalid_properties()
233+
.with_property(ParticipantIdentityProperty::CalendarAddress)
234+
.with_description("Invalid or missing calendar address.".to_string()));
235+
}
217236
}
218237
}
219238
(property, _) => {
@@ -223,34 +242,10 @@ fn validate_identity_value(
223242
}
224243
}
225244
}
245+
226246
// Validate email address
227247
if !identity.calendar_address.is_empty() {
228-
if let Some(new_address) = changed_address {
229-
let email = if let Some(email) = new_address.strip_prefix("mailto:") {
230-
sanitize_email(email)
231-
} else {
232-
sanitize_email(&new_address)
233-
};
234-
235-
if let Some(email) = email {
236-
if allowed_emails.iter().any(|e| e == &email) {
237-
identity.calendar_address = format!("mailto:{email}");
238-
Ok(())
239-
} else {
240-
Err(SetError::invalid_properties()
241-
.with_property(ParticipantIdentityProperty::CalendarAddress)
242-
.with_description(
243-
"Calendar address not configured for this account.".to_string(),
244-
))
245-
}
246-
} else {
247-
Err(SetError::invalid_properties()
248-
.with_property(ParticipantIdentityProperty::CalendarAddress)
249-
.with_description("Invalid or missing calendar address.".to_string()))
250-
}
251-
} else {
252-
Ok(())
253-
}
248+
Ok(())
254249
} else {
255250
Err(SetError::invalid_properties()
256251
.with_property(ParticipantIdentityProperty::CalendarAddress)

crates/store/src/query/log.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ impl Store {
6363
pub async fn changes(
6464
&self,
6565
account_id: u32,
66-
collection: LogCollection,
66+
collection_: LogCollection,
6767
query: Query,
6868
) -> trc::Result<Changes> {
6969
let is_share_log = matches!(
70-
collection,
70+
collection_,
7171
LogCollection::Sync(SyncCollection::ShareNotification)
7272
);
73-
let collection = u8::from(collection);
73+
let collection = u8::from(collection_);
7474

7575
let (is_inclusive, from_change_id, to_change_id) = match query {
7676
Query::All => (true, 0, u64::MAX),
@@ -127,13 +127,13 @@ impl Store {
127127
.await
128128
.caused_by(trc::location!())?;
129129

130-
if changelog.changes.is_empty() {
131-
changelog.from_change_id = from_change_id;
132-
changelog.to_change_id = if to_change_id != u64::MAX {
133-
to_change_id
134-
} else {
135-
from_change_id
136-
};
130+
// A non-existing change id was requested, return the last change id
131+
if changelog.changes.is_empty() && from_change_id != 0 && changelog.from_change_id == 0 {
132+
changelog.from_change_id = self
133+
.get_last_change_id(account_id, collection_)
134+
.await?
135+
.unwrap_or_default();
136+
changelog.to_change_id = changelog.from_change_id;
137137
}
138138

139139
Ok(changelog)

0 commit comments

Comments
 (0)