Skip to content
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
3 changes: 3 additions & 0 deletions apple/TablePro/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -229928,6 +229928,9 @@
},
"This Mac is not signed in to iCloud." : {

},
"This Mac is still reading the team's keys from the server, and carries on by itself." : {

},
"This Mac isn't approved for your keys yet." : {

Expand Down
3 changes: 2 additions & 1 deletion apple/TablePro/Views/Sync/Keys/TeamKeysLiveService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ internal final class TeamKeysLiveService: TeamKeysService {
canReconfirm: $0.canReconfirm
)
},
soleConfirmer: info.soleConfirmer
soleConfirmer: info.soleConfirmer,
holdersKnown: info.holdersKnown
)
}
}
5 changes: 5 additions & 0 deletions apple/TablePro/Views/Sync/Keys/TeamKeysPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ private struct TeamKeyStatusSection: View {
Text("The team's owner hasn't set up its keys yet.")
.foregroundStyle(.secondary)
}
case .readingKeys:
NoticeLabel(
String(localized: "This Mac is still reading the team's keys from the server, and carries on by itself."),
severity: .info
)
case .noHolderLeft(let canRestart):
if canRestart {
actionRow(
Expand Down
6 changes: 6 additions & 0 deletions apple/TablePro/Views/Sync/Keys/TeamKeysPresentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ internal enum TeamKeyStatus: Equatable {
case restoreWait
case restartHeld
case noKeys(canCreate: Bool)
// This Mac has the version but has not read yet who holds it, so no restart is offered (core ADR 0118).
case readingKeys
case noHolderLeft(canRestart: Bool)
case awaitingConfirmation
// This account waits while it is the team's only owner or admin, so a holder must be made an admin first.
Expand Down Expand Up @@ -57,6 +59,10 @@ internal enum TeamKeysPresentation {
guard let version = snapshot.version else {
return .noKeys(canCreate: team.role == .owner)
}
// A restart before this Mac read who holds the version would replace a key the account may hold.
if !snapshot.holdersKnown {
return .readingKeys
}
// 0056, Teams, No holder left: only an owner restarts, and only while no one on the roster holds the key.
if !snapshot.holder, !snapshot.members.contains(where: { $0.status == .holder }) {
return .noHolderLeft(canRestart: team.role == .owner)
Expand Down
2 changes: 2 additions & 0 deletions apple/TablePro/Views/Sync/Keys/TeamKeysService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ nonisolated internal struct TeamKeysSnapshot: Equatable, Sendable {
let stoppedDevices: [TeamStoppedDevice]
// This account is the team's only owner or admin while another member holds the key (core ADR 0106).
var soleConfirmer = false
// False while this Mac has the version but not yet the key objects that say who holds it (core ADR 0118).
var holdersKnown = true

func member(_ account: String) -> TeamMemberKeys? {
members.first { $0.account == account }
Expand Down
6 changes: 4 additions & 2 deletions apple/TableProTests/Views/Sync/Keys/FakeTeamKeysService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ enum TeamKeysFixtures {
holder: Bool = true,
members: [TeamMemberKeys]? = nil,
stoppedDevices: [TeamStoppedDevice] = [],
soleConfirmer: Bool = false
soleConfirmer: Bool = false,
holdersKnown: Bool = true
) -> TeamKeysSnapshot {
TeamKeysSnapshot(
version: version,
Expand All @@ -54,7 +55,8 @@ enum TeamKeysFixtures {
member(bo, name: "Bo", status: .alert),
],
stoppedDevices: stoppedDevices,
soleConfirmer: soleConfirmer
soleConfirmer: soleConfirmer,
holdersKnown: holdersKnown
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ struct TeamKeysPresentationTests {
#expect(TeamKeysPresentation.status(snapshot, team: F.keysTeam(role: .admin)) == .noHolderLeft(canRestart: false))
}

// E2E W12: an approval brought the version before this Mac read who holds it, so no one on the roster reads as a
// holder yet, and Start Over then would replace a key the account holds.
@Test("An owner whose Mac has not read who holds the key is offered no restart")
func unreadHoldersOfferNoRestart() {
let members = [F.member(F.you, isYou: true, role: .owner, status: .awaitingConfirmation)]
let unread = F.snapshot(holder: false, members: members, holdersKnown: false)
let read = F.snapshot(holder: false, members: members)

#expect(TeamKeysPresentation.status(unread, team: F.keysTeam(role: .owner)) == .readingKeys)
#expect(TeamKeysPresentation.status(read, team: F.keysTeam(role: .owner)) == .noHolderLeft(canRestart: true))
}

@Test("A Mac that holds no version while a teammate does waits to be confirmed")
func waitsForConfirmationWhileATeammateHolds() {
let snapshot = F.snapshot(holder: false, members: [
Expand Down
Loading