Skip to content
Draft
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# v153.0 (In progress)

## ✨ What's New ✨

### Autofill

- Added an optional `custom_label` field to the credit-card record so consumers can let users assign a user-defined label to a saved card. The field is nullable in the DB (NULL by default), defaults to `null` in the UniFFI bindings (no breaking change for existing Swift/Kotlin callers), and rides on the existing v3 credit-card sync payload as a kebab-cased `custom-label` key. It is omitted from outgoing payloads when unset so older clients see records unchanged. ([bug 1443042](https://bugzilla.mozilla.org/show_bug.cgi?id=1443042))

## 🔧 What's Fixed 🔧

### Logins
Expand Down
2 changes: 2 additions & 0 deletions components/autofill/sql/create_shared_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ CREATE TABLE IF NOT EXISTS credit_cards_data (
cc_exp_month INTEGER,
cc_exp_year INTEGER,
cc_type TEXT NOT NULL,
-- Optional user-assigned label (free text). NULL means unset.
custom_label TEXT,

time_created INTEGER NOT NULL,
time_last_used INTEGER,
Expand Down
5 changes: 5 additions & 0 deletions components/autofill/sql/migrations/v5_migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at http://mozilla.org/MPL/2.0/.

ALTER TABLE credit_cards_data ADD COLUMN custom_label TEXT;
100 changes: 100 additions & 0 deletions components/autofill/sql/tests/create_v4_db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at http://mozilla.org/MPL/2.0/.

-- Initialize the v4 schema. Same column layout as v3 — the v4 migration only
-- rewrites address_level1 data — so we reuse the v3 table definitions and seed
-- the post-v4 state.

CREATE TABLE IF NOT EXISTS addresses_data (
guid TEXT NOT NULL PRIMARY KEY CHECK(length(guid) != 0),
name TEXT NOT NULL,
organization TEXT NOT NULL,
street_address TEXT NOT NULL,
address_level3 TEXT NOT NULL,
address_level2 TEXT NOT NULL,
address_level1 TEXT NOT NULL,
postal_code TEXT NOT NULL,
country TEXT NOT NULL,
tel TEXT NOT NULL,
email TEXT NOT NULL,

time_created INTEGER NOT NULL,
time_last_used INTEGER NOT NULL,
time_last_modified INTEGER NOT NULL,
times_used INTEGER NOT NULL,

sync_change_counter INTEGER NOT NULL
);

CREATE TABLE IF NOT EXISTS addresses_mirror (
guid TEXT NOT NULL PRIMARY KEY CHECK(length(guid) != 0),
payload TEXT NOT NULL CHECK(length(payload) != 0)
);

CREATE TABLE IF NOT EXISTS addresses_tombstones (
guid TEXT PRIMARY KEY CHECK(length(guid) != 0),
time_deleted INTEGER NOT NULL
) WITHOUT ROWID;

CREATE TABLE IF NOT EXISTS credit_cards_data (
guid TEXT NOT NULL PRIMARY KEY CHECK(length(guid) != 0),
cc_name TEXT NOT NULL,
cc_number_enc TEXT NOT NULL CHECK(length(cc_number_enc) > 20 OR cc_number_enc == ''),
cc_number_last_4 TEXT NOT NULL CHECK(length(cc_number_last_4) <= 4),
cc_exp_month INTEGER,
cc_exp_year INTEGER,
cc_type TEXT NOT NULL,
time_created INTEGER NOT NULL,
time_last_used INTEGER,
time_last_modified INTEGER NOT NULL,
times_used INTEGER NOT NULL,
sync_change_counter INTEGER NOT NULL
);

CREATE TABLE IF NOT EXISTS credit_cards_mirror (
guid TEXT NOT NULL PRIMARY KEY CHECK(length(guid) != 0),
payload TEXT NOT NULL CHECK(length(payload) != 0)
);

CREATE TABLE IF NOT EXISTS credit_cards_tombstones (
guid TEXT PRIMARY KEY CHECK(length(guid) != 0),
time_deleted INTEGER NOT NULL
) WITHOUT ROWID;

CREATE TABLE IF NOT EXISTS moz_meta (
key TEXT PRIMARY KEY,
value NOT NULL
) WITHOUT ROWID;

INSERT INTO credit_cards_data (
guid, cc_name, cc_number_enc, cc_number_last_4, cc_exp_month, cc_exp_year,
cc_type, time_created, time_last_used, time_last_modified, times_used,
sync_change_counter
) VALUES (
"A", "Jane Doe", "012345678901234567890", "1234", 1, 2020, "visa", 0, 1, 2,
3, 0
);

INSERT INTO addresses_data (
guid, name, organization, street_address, address_level3,
address_level2, address_level1, postal_code, country, tel,
email, time_created, time_last_used, time_last_modified,
times_used, sync_change_counter
) VALUES (
"A", "Jane John Doe", "Mozilla", "123 Maple lane", "Shelbyville",
"Springfield", "MA", "12345", "US", "01-234-567-8000", "jane@hotmail.com", 0,
1, 2, 3, 0
);

INSERT INTO addresses_data (
guid, name, organization, street_address, address_level3,
address_level2, address_level1, postal_code, country, tel,
email, time_created, time_last_used, time_last_modified,
times_used, sync_change_counter
) VALUES (
"B", "", "Mozilla", "123 Maple lane", "Shelbyville",
"Toronto", "ON", "12345", "CA", "01-234-567-8000", "jane@hotmail.com", 0,
1, 2, 3, 0
);
PRAGMA user_version=4;
2 changes: 2 additions & 0 deletions components/autofill/src/autofill.udl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dictionary UpdatableCreditCardFields {
i64 cc_exp_month;
i64 cc_exp_year;
string cc_type;
string? custom_label = null;
};

/// What you get back as a credit-card.
Expand All @@ -34,6 +35,7 @@ dictionary CreditCard {
i64 cc_exp_month;
i64 cc_exp_year;
string cc_type;
string? custom_label = null;

i64 time_created;
i64? time_last_used;
Expand Down
18 changes: 18 additions & 0 deletions components/autofill/src/db/credit_cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub(crate) fn add_credit_card(
// Credit card types are a fixed set of strings as defined in the link below
// (https://searchfox.org/mozilla-central/rev/7ef5cefd0468b8f509efe38e0212de2398f4c8b3/toolkit/modules/CreditCard.jsm#9-22)
cc_type: new_credit_card_fields.cc_type,
custom_label: new_credit_card_fields.custom_label,
metadata: Metadata {
time_created: now,
time_last_modified: now,
Expand Down Expand Up @@ -76,6 +77,7 @@ pub(crate) fn add_internal_credit_card(
":cc_exp_month": card.cc_exp_month,
":cc_exp_year": card.cc_exp_year,
":cc_type": card.cc_type,
":custom_label": card.custom_label,
":time_created": card.metadata.time_created,
":time_last_used": card.metadata.time_last_used,
":time_last_modified": card.metadata.time_last_modified,
Expand Down Expand Up @@ -142,6 +144,7 @@ pub fn update_credit_card(
cc_exp_month = :cc_exp_month,
cc_exp_year = :cc_exp_year,
cc_type = :cc_type,
custom_label = :custom_label,
time_last_modified = :time_last_modified,
sync_change_counter = sync_change_counter + 1
WHERE guid = :guid",
Expand All @@ -152,6 +155,7 @@ pub fn update_credit_card(
":cc_exp_month": credit_card.cc_exp_month,
":cc_exp_year": credit_card.cc_exp_year,
":cc_type": credit_card.cc_type,
":custom_label": credit_card.custom_label,
":time_last_modified": Timestamp::now(),
":guid": guid,
},
Expand All @@ -178,6 +182,7 @@ pub(crate) fn update_internal_credit_card(
cc_exp_month = :cc_exp_month,
cc_exp_year = :cc_exp_year,
cc_type = :cc_type,
custom_label = :custom_label,
time_created = :time_created,
time_last_used = :time_last_used,
time_last_modified = :time_last_modified,
Expand All @@ -191,6 +196,7 @@ pub(crate) fn update_internal_credit_card(
":cc_exp_month": card.cc_exp_month,
":cc_exp_year": card.cc_exp_year,
":cc_type": card.cc_type,
":custom_label": card.custom_label,
":time_created": card.metadata.time_created,
":time_last_used": card.metadata.time_last_used,
":time_last_modified": card.metadata.time_last_modified,
Expand Down Expand Up @@ -361,6 +367,7 @@ pub(crate) mod tests {
cc_exp_month: 3,
cc_exp_year: 2022,
cc_type: "visa".to_string(),
custom_label: None,
},
)?;

Expand Down Expand Up @@ -434,6 +441,7 @@ pub(crate) mod tests {
cc_exp_month: 3,
cc_exp_year: 2022,
cc_type: "visa".to_string(),
custom_label: None,
},
)?;

Expand All @@ -446,6 +454,7 @@ pub(crate) mod tests {
cc_exp_month: 10,
cc_exp_year: 2025,
cc_type: "mastercard".to_string(),
custom_label: None,
},
)?;

Expand All @@ -459,6 +468,7 @@ pub(crate) mod tests {
cc_exp_month: 1,
cc_exp_year: 2024,
cc_type: "amex".to_string(),
custom_label: None,
},
)?;

Expand Down Expand Up @@ -502,6 +512,7 @@ pub(crate) mod tests {
cc_exp_month: 10,
cc_exp_year: 2025,
cc_type: "mastercard".to_string(),
custom_label: None,
},
)?;

Expand All @@ -514,6 +525,7 @@ pub(crate) mod tests {
cc_number_enc: "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB".to_string(),
cc_number_last_4: "1234".to_string(),
cc_type: "mastercard".to_string(),
custom_label: None,
cc_exp_month: 10,
cc_exp_year: 2025,
},
Expand Down Expand Up @@ -599,6 +611,7 @@ pub(crate) mod tests {
cc_exp_month: 10,
cc_exp_year: 2025,
cc_type: "mastercard".to_string(),
custom_label: None,
},
)?;

Expand All @@ -615,6 +628,7 @@ pub(crate) mod tests {
cc_exp_month: 5,
cc_exp_year: 2024,
cc_type: "visa".to_string(),
custom_label: None,
},
)?;

Expand Down Expand Up @@ -668,6 +682,7 @@ pub(crate) mod tests {
cc_exp_month: 10,
cc_exp_year: 2025,
cc_type: "mastercard".to_string(),
custom_label: None,
},
)?);
}
Expand Down Expand Up @@ -699,6 +714,7 @@ pub(crate) mod tests {
cc_exp_month: 9,
cc_exp_year: 2027,
cc_type: "visa".to_string(),
custom_label: None,
},
)?;

Expand All @@ -712,6 +728,7 @@ pub(crate) mod tests {
cc_exp_month: 10,
cc_exp_year: 2025,
cc_type: "mastercard".to_string(),
custom_label: None,
},
)?;

Expand Down Expand Up @@ -810,6 +827,7 @@ pub(crate) mod tests {
cc_exp_month: 5,
cc_exp_year: 2024,
cc_type: "visa".to_string(),
custom_label: None,
},
)?;

Expand Down
6 changes: 6 additions & 0 deletions components/autofill/src/db/models/credit_card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub struct UpdatableCreditCardFields {
// Credit card types are a fixed set of strings as defined in the link below
// (https://searchfox.org/mozilla-central/rev/7ef5cefd0468b8f509efe38e0212de2398f4c8b3/toolkit/modules/CreditCard.jsm#9-22)
pub cc_type: String,
// Optional user-assigned free-text label.
pub custom_label: Option<String>,
}

#[derive(Debug, Clone, Default)]
Expand All @@ -31,6 +33,7 @@ pub struct CreditCard {
// Credit card types are a fixed set of strings as defined in the link below
// (https://searchfox.org/mozilla-central/rev/7ef5cefd0468b8f509efe38e0212de2398f4c8b3/toolkit/modules/CreditCard.jsm#9-22)
pub cc_type: String,
pub custom_label: Option<String>,

// The metadata
pub time_created: i64,
Expand All @@ -51,6 +54,7 @@ impl From<InternalCreditCard> for CreditCard {
cc_exp_month: icc.cc_exp_month,
cc_exp_year: icc.cc_exp_year,
cc_type: icc.cc_type,
custom_label: icc.custom_label,
// note we can't use u64 in uniffi
time_created: u64::from(icc.metadata.time_created) as i64,
time_last_used: if icc.metadata.time_last_used.0 == 0 {
Expand All @@ -77,6 +81,7 @@ pub struct InternalCreditCard {
// Credit card types are a fixed set of strings as defined in the link below
// (https://searchfox.org/mozilla-central/rev/7ef5cefd0468b8f509efe38e0212de2398f4c8b3/toolkit/modules/CreditCard.jsm#9-22)
pub cc_type: String,
pub custom_label: Option<String>,
pub metadata: Metadata,
}

Expand All @@ -90,6 +95,7 @@ impl InternalCreditCard {
cc_exp_month: row.get("cc_exp_month")?,
cc_exp_year: row.get("cc_exp_year")?,
cc_type: row.get("cc_type")?,
custom_label: row.get("custom_label")?,
metadata: Metadata {
time_created: row.get("time_created")?,
time_last_used: row.get("time_last_used")?,
Expand Down
Loading