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

Add AccountKeyRequirement.manual #75

Merged
merged 8 commits into from
Sep 15, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ struct AccountKeyConfigurationImpl<Key: AccountKey>: AccountKeyConfiguration {

let keyPathDescription: String

init(_ keyPath: KeyPath<AccountKeys, Key.Type>, type: AccountKeyRequirement) {
init(_ keyPath: KeyPath<AccountKeys, Key.Type>, requirement: AccountKeyRequirement) {
self.key = Key.self
self.requirement = type
self.requirement = requirement
self.keyPathDescription = keyPath.shortDescription
}
}
Expand All @@ -58,6 +58,8 @@ extension AccountKeyConfigurationImpl {
return ".collects(\(keyPathDescription))"
case .supported:
return ".supports(\(keyPathDescription))"
case .hidden:
return ".hidden(\(keyPathDescription))"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public enum AccountKeyRequirement {
/// The account value is **not** collected at signup. However, it is displayed in the account overview
/// and a user can supply a value by editing their account details.
case supported
/// The associated account value **can** be provided by the user at a later point in time.
///
/// The account value is **not** collected at signup. It is also not displayed in the account overview.
case hidden
Supereg marked this conversation as resolved.
Show resolved Hide resolved
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,31 @@ public struct ConfiguredAccountKey {
/// - Parameter keyPath: The `KeyPath` referencing the ``AccountKey``.
/// - Returns: Returns the ``AccountKey`` configuration.
public static func requires<Key: AccountKey>(_ keyPath: KeyPath<AccountKeys, Key.Type>) -> ConfiguredAccountKey {
.init(configuration: AccountKeyConfigurationImpl(keyPath, type: .required))
.init(configuration: AccountKeyConfigurationImpl(keyPath, requirement: .required))
}

/// Configure an ``AccountKey`` as ``AccountKeyRequirement/collected``.
/// - Parameter keyPath: The `KeyPath` referencing the ``AccountKey``.
/// - Returns: Returns the ``AccountKey`` configuration.
@_disfavoredOverload
public static func collects<Key: AccountKey>(_ keyPath: KeyPath<AccountKeys, Key.Type>) -> ConfiguredAccountKey {
.init(configuration: AccountKeyConfigurationImpl(keyPath, type: .collected))
.init(configuration: AccountKeyConfigurationImpl(keyPath, requirement: .collected))
}

/// Configure an ``AccountKey`` as ``AccountKeyRequirement/supported``.
/// - Parameter keyPath: The `KeyPath` referencing the ``AccountKey``.
/// - Returns: Returns the ``AccountKey`` configuration.
@_disfavoredOverload
public static func supports<Key: AccountKey>(_ keyPath: KeyPath<AccountKeys, Key.Type>) -> ConfiguredAccountKey {
.init(configuration: AccountKeyConfigurationImpl(keyPath, type: .supported))
.init(configuration: AccountKeyConfigurationImpl(keyPath, requirement: .supported))
}

/// Configure an ``AccountKey`` as ``AccountKeyRequirement/hidden``.
/// - Parameter keyPath: The `KeyPath` referencing the ``AccountKey``.
/// - Returns: Returns the ``AccountKey`` configuration.
@_disfavoredOverload
Supereg marked this conversation as resolved.
Show resolved Hide resolved
public static func hidden<Key: AccountKey>(_ keyPath: KeyPath<AccountKeys, Key.Type>) -> ConfiguredAccountKey {
.init(configuration: AccountKeyConfigurationImpl(keyPath, requirement: .hidden))
}

/// Configure an ``AccountKey`` as ``AccountKeyRequirement/required`` as ``RequiredAccountKey`` can only be configured as required.
Expand Down
6 changes: 6 additions & 0 deletions Sources/SpeziAccount/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,9 @@
}
}
}
},
"Date of Birth" : {

},
"DELETE" : {
"localizations" : {
Expand Down Expand Up @@ -664,6 +667,9 @@
}
}
}
},
"E-Mail and Password" : {

},
"EDIT" : {
"localizations" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AccountOverviewFormViewModel {


init(_ valueConfiguration: AccountValueConfiguration, _ serviceConfiguration: AccountServiceConfiguration) {
self.categorizedAccountKeys = valueConfiguration.allCategorized()
self.categorizedAccountKeys = valueConfiguration.allCategorized(filteredBy: [.required, .collected, .supported])
self.accountServiceConfiguration = serviceConfiguration
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import SwiftUI


private let logger = Logger(subsystem: "edu.stanford.sepzi.SepziAccount", category: "AccountRequiredModifier")
private let logger = Logger(subsystem: "edu.stanford.spezi.SpeziAccount", category: "AccountRequiredModifier")

Check warning on line 13 in Sources/SpeziAccount/ViewModifier/AccountRequiredModifier.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS / Test using xcodebuild or run fastlane

let 'logger' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor; this is an error in Swift 6

Check warning on line 13 in Sources/SpeziAccount/ViewModifier/AccountRequiredModifier.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS / Test using xcodebuild or run fastlane

let 'logger' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor; this is an error in Swift 6

Check warning on line 13 in Sources/SpeziAccount/ViewModifier/AccountRequiredModifier.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS / Test using xcodebuild or run fastlane

let 'logger' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor; this is an error in Swift 6

Check warning on line 13 in Sources/SpeziAccount/ViewModifier/AccountRequiredModifier.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests / Test using xcodebuild or run fastlane

let 'logger' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor; this is an error in Swift 6

Check warning on line 13 in Sources/SpeziAccount/ViewModifier/AccountRequiredModifier.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests / Test using xcodebuild or run fastlane

let 'logger' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor; this is an error in Swift 6

Check warning on line 13 in Sources/SpeziAccount/ViewModifier/AccountRequiredModifier.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS / Test using xcodebuild or run fastlane

let 'logger' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor; this is an error in Swift 6

Check warning on line 13 in Sources/SpeziAccount/ViewModifier/AccountRequiredModifier.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS / Test using xcodebuild or run fastlane

let 'logger' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor; this is an error in Swift 6
pauljohanneskraft marked this conversation as resolved.
Show resolved Hide resolved


struct AccountRequiredModifier<SetupSheet: View>: ViewModifier {
Expand Down
5 changes: 5 additions & 0 deletions Tests/UITests/TestApp/AccountTestsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ struct AccountTestsView: View {
} label: {
Text(verbatim: "License Information")
}
if let invitationCode = account.details?.invitationCode {
LabeledContent("Invitation Code") {
Text(invitationCode)
}
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Tests/UITests/TestApp/TestAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
.collects(\.name),
.collects(\.genderIdentity),
.collects(\.dateOfBirth),
.supports(\.biography)
.supports(\.biography),
.hidden(\.invitationCode)

Check failure on line 36 in Tests/UITests/TestApp/TestAppDelegate.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests / Test using xcodebuild or run fastlane

generic parameter 'Key' could not be inferred

Check failure on line 36 in Tests/UITests/TestApp/TestAppDelegate.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests / Test using xcodebuild or run fastlane

value of type 'AccountKeys' has no member 'invitationCode'

Check failure on line 36 in Tests/UITests/TestApp/TestAppDelegate.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests Latest / Test using xcodebuild or run fastlane

generic parameter 'Key' could not be inferred

Check failure on line 36 in Tests/UITests/TestApp/TestAppDelegate.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests Latest / Test using xcodebuild or run fastlane

value of type 'AccountKeys' has no member 'invitationCode'

Check failure on line 36 in Tests/UITests/TestApp/TestAppDelegate.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS / Test using xcodebuild or run fastlane

generic parameter 'Key' could not be inferred

Check failure on line 36 in Tests/UITests/TestApp/TestAppDelegate.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS / Test using xcodebuild or run fastlane

value of type 'AccountKeys' has no member 'invitationCode'
Supereg marked this conversation as resolved.
Show resolved Hide resolved
]
case .allRequired:
#if os(visionOS)
Expand Down
19 changes: 19 additions & 0 deletions Tests/UITests/TestApp/Utils/InvitationCodeKey.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// This source file is part of the Spezi open-source project
//
// SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md)
//
// SPDX-License-Identifier: MIT
//

import SpeziAccount
import SwiftUI

extension AccountDetails {
@AccountKey(name: "Invitation Code", category: .other, as: String.self)
var invitationCode: String?
}


@KeyEntry(\.invitationCode)
extension AccountKeys {}
Loading