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

feat(feedback): prefill user info in form #4630

Merged
merged 6 commits into from
Dec 13, 2024
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
11 changes: 11 additions & 0 deletions Samples/iOS-Swift/iOS-Swift-UITests/UserFeedbackUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ class UserFeedbackUITests: BaseUITest {
XCTAssertFalse(app.staticTexts["Thy name (Required)"].exists)
}

func testPrefilledUserInformation() throws {
launchApp(args: ["--io.sentry.feedback.use-sentry-user"], env: [
"--io.sentry.user.name": "ui test user",
"--io.sentry.user.email": "[email protected]"
])

widgetButton.tap()
XCTAssertEqual(try XCTUnwrap(nameField.value as? String), "ui test user")
XCTAssertEqual(try XCTUnwrap(emailField.value as? String), "[email protected]")
}

// MARK: Tests validating happy path / successful submission

func testSubmitFullyFilledForm() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
argument = "--disable-file-io-tracing"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "--io.sentry.feedback.use-sentry-user"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "--io.sentry.feedback.require-name"
isEnabled = "NO">
Expand Down Expand Up @@ -236,6 +240,11 @@
value = ""
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "--io.sentry.user.name"
value = ""
isEnabled = "NO">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
Expand Down
4 changes: 3 additions & 1 deletion Samples/iOS-Swift/iOS-Swift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
user.email = env["--io.sentry.user.email"] ?? "[email protected]"
// first check if the username has been overridden in the scheme for testing purposes; then try to use the system username so each person gets an automatic way to easily filter things on the dashboard; then fall back on a hardcoded value if none of these are present
let username = env["--io.sentry.user.username"] ?? (env["SIMULATOR_HOST_HOME"] as? NSString)?
.lastPathComponent ?? "cocoa developer"
.lastPathComponent ?? "cocoadev"
user.username = username
user.name = env["--io.sentry.user.name"] ?? "cocoa developer"
scope.setUser(user)

if let path = Bundle.main.path(forResource: "Tongariro", ofType: "jpg") {
Expand All @@ -174,6 +175,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return
}
config.animations = !args.contains("--io.sentry.feedback.no-animations")
config.useSentryUser = args.contains("--io.sentry.feedback.use-sentry-user")
config.useShakeGesture = true
config.showFormForScreenshots = true
config.configureWidget = { widget in
Expand Down
8 changes: 8 additions & 0 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@
8431F01C29B2854200D8DC56 /* libSentryTestUtils.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8431F00A29B284F200D8DC56 /* libSentryTestUtils.a */; };
84354E1129BF944900CDBB8B /* SentryProfileTimeseries.h in Headers */ = {isa = PBXBuildFile; fileRef = 84354E0F29BF944900CDBB8B /* SentryProfileTimeseries.h */; };
84354E1229BF944900CDBB8B /* SentryProfileTimeseries.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84354E1029BF944900CDBB8B /* SentryProfileTimeseries.mm */; };
843FB3232D0CD04D00558F18 /* SentryUserAccess.m in Sources */ = {isa = PBXBuildFile; fileRef = 843FB3222D0CD04D00558F18 /* SentryUserAccess.m */; };
843FB3242D0CD04D00558F18 /* SentryUserAccess.h in Headers */ = {isa = PBXBuildFile; fileRef = 843FB3212D0CD04D00558F18 /* SentryUserAccess.h */; };
844EDC6F294143B900C86F34 /* SentryNSProcessInfoWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 844EDC6D294143B900C86F34 /* SentryNSProcessInfoWrapper.h */; };
844EDC70294143B900C86F34 /* SentryNSProcessInfoWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 844EDC6E294143B900C86F34 /* SentryNSProcessInfoWrapper.mm */; };
844EDC76294144DB00C86F34 /* SentrySystemWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 844EDC74294144DB00C86F34 /* SentrySystemWrapper.h */; };
Expand Down Expand Up @@ -1697,6 +1699,8 @@
84354E0F29BF944900CDBB8B /* SentryProfileTimeseries.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryProfileTimeseries.h; path = Sources/Sentry/include/SentryProfileTimeseries.h; sourceTree = SOURCE_ROOT; };
84354E1029BF944900CDBB8B /* SentryProfileTimeseries.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = SentryProfileTimeseries.mm; path = Sources/Sentry/SentryProfileTimeseries.mm; sourceTree = SOURCE_ROOT; };
843BD6282AD8752300B0098F /* .clang-format */ = {isa = PBXFileReference; lastKnownFileType = text; path = ".clang-format"; sourceTree = "<group>"; };
843FB3212D0CD04D00558F18 /* SentryUserAccess.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryUserAccess.h; sourceTree = "<group>"; };
843FB3222D0CD04D00558F18 /* SentryUserAccess.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryUserAccess.m; sourceTree = "<group>"; };
8446F5182BE172290040D57E /* SentryContinuousProfilerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryContinuousProfilerTests.swift; sourceTree = "<group>"; };
844A34C3282B278500C6D1DF /* .github */ = {isa = PBXFileReference; lastKnownFileType = folder; path = .github; sourceTree = "<group>"; };
844A3563282B3C9F00C6D1DF /* .sauce */ = {isa = PBXFileReference; lastKnownFileType = folder; path = .sauce; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2232,6 +2236,8 @@
639FCF9B1EBC7F9500778193 /* SentryThread.m */,
639FCFAA1EBC811400778193 /* SentryUser.h */,
639FCFAB1EBC811400778193 /* SentryUser.m */,
843FB3212D0CD04D00558F18 /* SentryUserAccess.h */,
843FB3222D0CD04D00558F18 /* SentryUserAccess.m */,
92F6726A29C8B7B000BFD34D /* SentryUser+Private.h */,
9286059429A5096600F96038 /* SentryGeo.h */,
9286059629A5098900F96038 /* SentryGeo.m */,
Expand Down Expand Up @@ -4269,6 +4275,7 @@
6334314120AD9AE40077E581 /* SentryMechanism.h in Headers */,
03F84D2827DD414C008FE43F /* SentryCPU.h in Headers */,
0A80E435291017D500095219 /* SentryWatchdogTerminationScopeObserver.h in Headers */,
843FB3242D0CD04D00558F18 /* SentryUserAccess.h in Headers */,
7B610D642512399600B0B5D9 /* SentryHub+Private.h in Headers */,
D8F6A24B2885515C00320515 /* SentryPredicateDescriptor.h in Headers */,
848A451E2BBF9504006AAAEC /* SentryProfilerTestHelpers.h in Headers */,
Expand Down Expand Up @@ -4665,6 +4672,7 @@
62FC18AF2C9D5FAC008803CD /* SentryANRTracker.swift in Sources */,
63FE711120DA4C1000CDBAE8 /* SentryCrashDebug.c in Sources */,
7B883F49253D714C00879E62 /* SentryCrashUUIDConversion.c in Sources */,
843FB3232D0CD04D00558F18 /* SentryUserAccess.m in Sources */,
63FE716720DA4C1100CDBAE8 /* SentryCrashCPU.c in Sources */,
63FE717320DA4C1100CDBAE8 /* SentryCrashC.c in Sources */,
63FE712120DA4C1000CDBAE8 /* SentryCrashSymbolicator.c in Sources */,
Expand Down
13 changes: 13 additions & 0 deletions Sources/Sentry/SentryUserAccess.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This provides convenience access to internal ObjC API of internal Swift implementation, which
// can't be directly imported in SentryPrivate.h

#import <Foundation/Foundation.h>

@class SentryClient;
@class SentryUser;

NS_ASSUME_NONNULL_BEGIN

SentryUser *_Nullable sentry_getCurrentUser(void);

NS_ASSUME_NONNULL_END
6 changes: 6 additions & 0 deletions Sources/Sentry/SentryUserAccess.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import "SentryUserAccess.h"
#import "SentryHub.h"
#import "SentrySDK+Private.h"
#import "SentryScope+Private.h"

SentryUser *_Nullable sentry_getCurrentUser(void) { return SentrySDK.currentHub.scope.userObject; }
4 changes: 3 additions & 1 deletion Sources/Sentry/include/SentryPrivate.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Sentry internal headers that are needed for swift code
// Sentry internal headers that are needed for swift code; you cannot import headers that depend on
// public interfaces here
#import "NSLocale+Sentry.h"
#import "SentryDispatchQueueWrapper.h"
#import "SentryNSDataUtils.h"
#import "SentryRandom.h"
#import "SentryTime.h"
#import "SentryUserAccess.h"

// Headers that also import SentryDefines should be at the end of this list
// otherwise it wont compile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@
field.accessibilityLabel = config.formConfig.nameTextFieldAccessibilityLabel
field.accessibilityIdentifier = "io.sentry.feedback.form.name"
field.delegate = self
field.autocapitalizationType = .words

Check warning on line 264 in Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift#L264

Added line #L264 was not covered by tests
if config.useSentryUser {
field.text = sentry_getCurrentUser()?.name

Check warning on line 266 in Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift#L266

Added line #L266 was not covered by tests
}
return field
}()

Expand All @@ -277,6 +281,10 @@
field.accessibilityIdentifier = "io.sentry.feedback.form.email"
field.delegate = self
field.keyboardType = .emailAddress
field.autocapitalizationType = .none

Check warning on line 284 in Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift#L284

Added line #L284 was not covered by tests
if config.useSentryUser {
field.text = sentry_getCurrentUser()?.email

Check warning on line 286 in Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift#L286

Added line #L286 was not covered by tests
}
return field
}()

Expand Down
Loading