Skip to content

Commit

Permalink
Unified Account View with rethought Account Service Model (#7)
Browse files Browse the repository at this point in the history
# Unified Account View with rethought Account Service Model

## ♻️ Current situation & Problem

Currently, `SepziAccount` exposes two distinct views: `Login` and
`SignUp`. While visually identical (expect for customizations), the
AccountService buttons navigate to the respective Login or SignUp views
for data entry. This introduces several navigation steps for the user
even for simple workflows (e.g. just signing in a returning user).
Further, it is not clear where to place Identity Provider buttons (e.g.,
Sign in with Apple), as these create a new account or just sign you in
to your existing one with the same, single button.

## 💡 Proposed solution
This PR makes the following changes:

* Unifying `Login` and `SignUp` views to be represented by a single
view, placing identity providers on the same page as regular Account
Services, the `AccountSetup` view.
* Restructure the Account Service Model:
* Make the necessary preparations to support third-party Identity
providers
* Introduce the concept of an `EmbeddableAccountService` and a new
`KeyPasswordBasedAccountService` as new abstraction layers.
This replaces the current `UsernamePasswordAccountService` and
`EmailPasswordAccountService` implementations. Those we really only Mock
implementations which provided extensibility through class inheritance.
This was replaced by providing the same functionality with a hierarchy
of protocols being more powerful and providing much more flexibility.
Further, we introduce new Mock Account services (e.g., used by
PreviewProviders) which more clearly communicate their use through their
updated name.
* Move the UI parts of an AccountService out into a distinct abstraction
layer (`AccountSetupViewStyle`s).
* Introduce the `Account Value` (through `AccountKey` implementations)
abstraction to support arbitrary account values
* They provide a name, a category (for optimized placement in the UI),
and a initial value
* The provide the UI components do display (`DataDisplayView`) and setup
or edit (`DataEntryView`) account values
* The provide easy to use accessors using extensions on `AccountKeys`
and `AccountValues`
* Optimized API surface for end-users:
  * Exposes the `signedIn` published property (same as previously)
* Exposees the `details` shared repository to access the
`AccountDetails` of the currently logged in use. This also provides
access to the `AccountService` and its configuration that was used to
setup the user account.
* Provide a new `AccountOverview` view:
  * Allows to view arbitrary account values
  * Allows to edit arbitrary account values
  * Provide Logout and account Removal functionality
* Enabled through StanfordSpezi/Spezi#72, one
can easily configure `SpeziAccount` centrally while other configured
components can provide their AccountServices via [Component
Communication](https://swiftpackageindex.com/stanfordspezi/spezi/documentation/spezi/component#Communication).

This PR tries to provide extensive documentation for all areas.

To provide some insights into the new user-facing API surface.

This is how you would configure Spezi Account now:
```swift
class YourAppDelegate: SpeziAppDelegate {
    override var configuration: Configuration {
        AccountConfiguration(configuration: [
            // the user defines what account values are used and if they are `required`, `collected` or just `supported`
            .requires(\.userId),
            .requires(\.password),
            .requires(\.name),
            .collects(\.dateOfBirth),
            .collects(\.genderIdentity)
        ])
    }
}
```

Below is an example on how to use the account setup view:
```swift
struct MyOnboardingView: View {
    var body: some View {
        AccountSetup {
           NavigationLink {
               // ... next view if already signed in
           } label: {
               Text("Continue")
           }
        }
    }
}
```

Lastly, the account overview is equally as easy to use:
```swift
struct MyView: View {
    var body: some View {
        AccountOverview()
    }
}
```

## ⚙️ Release Notes 
* New, unified `AccountSetup` view
* New `AccountOverview` view
* Introduce new `AccountService` abstraction
* Support arbitrary account values through `AccountKey`-based shared
repository implementation

## ➕ Additional Information

### Related PRs and Issues
* This PR provides the groundwork necessary for
StanfordSpezi/SpeziFirebase#7
* The updated Firebase implementation:
StanfordSpezi/SpeziFirebase#8

### Testing
Substantial UI tests were updated and added.

### Reviewer Nudging
As this is quite a large PR it would make sense to start reviewing by
reading through the documentation. First of all reviewing the
documentation itself (structure and readability). Code example on the
DocC article already explain a lot of the concepts.
The areas that sparked your attention, where you think that something is
off or hard to understand, I would recommend to deep dive into the
respective code area.

### Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).

---------

Co-authored-by: Paul Schmiedmayer <PSchmiedmayer@users.noreply.github.com>
  • Loading branch information
Supereg and PSchmiedmayer authored Sep 14, 2023
1 parent e5f8db6 commit 040aec4
Show file tree
Hide file tree
Showing 196 changed files with 11,551 additions and 3,628 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# This source file is part of the Spezi open source project
#
# SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md)
# SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md)
#
# SPDX-License-Identifier: MIT
#
Expand Down
10 changes: 5 additions & 5 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#
# This source file is part of the Stanford Spezi open-source project
#
# SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md)
# SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md)
#
# SPDX-License-Identifier: MIT
#
#

# The whitelist_rules configuration also includes rules that are enabled by default to provide a good overview of all rules.
only_rules:
Expand Down Expand Up @@ -198,7 +198,7 @@ only_rules:
- nimble_operator
# Prefer not to use extension access modifiers
- no_extension_access_modifier
# Fallthroughs can only be used if the case contains at least one other statement.
# Fallthroughs can only be used if the case contains at least one other statement.
- no_fallthrough_only
# Don’t add a space between the method name and the parentheses.
- no_space_in_method_call
Expand Down Expand Up @@ -429,7 +429,7 @@ nesting: # Types should be nested at most 2 level deep, and functions should be
warning: 2 # warning - default: 1
function_level:
warning: 5 # warning - default: 5

trailing_closure:
only_single_muted_parameter: true

Expand All @@ -444,7 +444,7 @@ type_name:
trailing_whitespace:
ignores_empty_lines: true # default: false
ignores_comments: true # default: false

unused_optional_binding:
ignore_optional_try: true

Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# This source file is part of the Spezi open source project
#
# SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md)
# SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md)
#
# SPDX-License-Identifier: MIT
#
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This source file is part of the Spezi open-source project.
SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md)
SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md)
SPDX-License-Identifier: MIT
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Stanford University and the project authors (see CONTRIBUTORS.md)
Copyright (c) 2023 Stanford University and the project authors (see CONTRIBUTORS.md)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
2 changes: 1 addition & 1 deletion LICENSES/MIT.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Stanford University and the project authors (see CONTRIBUTORS.md)
Copyright (c) 2023 Stanford University and the project authors (see CONTRIBUTORS.md)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
15 changes: 10 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// This source file is part of the Spezi open source project
//
// SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md)
// SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md)
//
// SPDX-License-Identifier: MIT
//
Expand All @@ -21,21 +21,26 @@ let package = Package(
.library(name: "SpeziAccount", targets: ["SpeziAccount"])
],
dependencies: [
.package(url: "https://github.com/StanfordSpezi/Spezi", .upToNextMinor(from: "0.7.0")),
.package(url: "https://github.com/StanfordSpezi/SpeziViews", .upToNextMinor(from: "0.4.0"))
.package(url: "https://github.com/StanfordSpezi/Spezi", .upToNextMinor(from: "0.7.2")),
.package(url: "https://github.com/StanfordSpezi/SpeziViews", .upToNextMinor(from: "0.5.0")),
.package(url: "https://github.com/StanfordBDHG/XCTRuntimeAssertions", .upToNextMinor(from: "0.2.5")),
.package(url: "https://github.com/apple/swift-collections.git", .upToNextMajor(from: "1.0.4"))
],
targets: [
.target(
name: "SpeziAccount",
dependencies: [
.product(name: "Spezi", package: "Spezi"),
.product(name: "SpeziViews", package: "SpeziViews")
.product(name: "SpeziViews", package: "SpeziViews"),
.product(name: "XCTRuntimeAssertions", package: "XCTRuntimeAssertions"),
.product(name: "OrderedCollections", package: "swift-collections")
]
),
.testTarget(
name: "SpeziAccountTests",
dependencies: [
.target(name: "SpeziAccount")
.target(name: "SpeziAccount"),
.product(name: "XCTRuntimeAssertions", package: "XCTRuntimeAssertions")
]
)
]
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This source file is part of the Spezi open-source project.
SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md)
SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md)
SPDX-License-Identifier: MIT
Expand All @@ -16,7 +16,9 @@ SPDX-License-Identifier: MIT
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FStanfordSpezi%2FSpeziAccount%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/StanfordSpezi/SpeziAccount)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FStanfordSpezi%2FSpeziAccount%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/StanfordSpezi/SpeziAccount)

The Account module allows users to incorporate account-related functionality for Spezi-based applications.
The Account module provides account-related functionality for Spezi-based applications.
It provides two standardized views with Account Setup, Overview and Edit functionality.
It allows integrating arbitrary account management services using the Account Service abstraction.

For more information, please refer to the [API documentation](https://swiftpackageindex.com/StanfordSpezi/SpeziAccount/documentation).

Expand All @@ -25,7 +27,6 @@ For more information, please refer to the [API documentation](https://swiftpacka

The [Spezi Template Application](https://github.com/StanfordSpezi/SpeziTemplateApplication) provides a great starting point and example using the Spezi Account module.


## Contributing

Contributions to this project are welcome. Please make sure to read the [contribution guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md) and the [contributor covenant code of conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) first.
Expand Down
Loading

0 comments on commit 040aec4

Please sign in to comment.