-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Move Application Passwords entry to user details #23834
Changes from all commits
ea57e2b
6bebb44
27855d2
9d67d18
dbb1690
10c98ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ struct UserDetailsView: View { | |
|
||
fileprivate let userService: UserServiceProtocol | ||
let user: DisplayUser | ||
let isCurrentUser: Bool | ||
let applicationTokenListDataProvider: ApplicationTokenListDataProvider | ||
|
||
@State private var presentPasswordAlert: Bool = false { | ||
didSet { | ||
|
@@ -20,19 +22,19 @@ struct UserDetailsView: View { | |
|
||
@StateObject | ||
fileprivate var viewModel: UserDetailViewModel | ||
@StateObject | ||
fileprivate var applicationTokenListViewModel: ApplicationTokenListViewModel | ||
|
||
@StateObject | ||
fileprivate var deleteUserViewModel: UserDeleteViewModel | ||
|
||
@Environment(\.dismiss) | ||
var dismissAction: DismissAction | ||
|
||
init(user: DisplayUser, userService: UserServiceProtocol, applicationTokenListDataProvider: ApplicationTokenListDataProvider) { | ||
init(user: DisplayUser, isCurrentUser: Bool, userService: UserServiceProtocol, applicationTokenListDataProvider: ApplicationTokenListDataProvider) { | ||
self.user = user | ||
self.isCurrentUser = isCurrentUser | ||
self.userService = userService | ||
self.applicationTokenListDataProvider = applicationTokenListDataProvider | ||
_viewModel = StateObject(wrappedValue: UserDetailViewModel(userService: userService)) | ||
_applicationTokenListViewModel = StateObject(wrappedValue: ApplicationTokenListViewModel(dataProvider: applicationTokenListDataProvider)) | ||
_deleteUserViewModel = StateObject(wrappedValue: UserDeleteViewModel(user: user, userService: userService)) | ||
} | ||
|
||
|
@@ -61,29 +63,34 @@ struct UserDetailsView: View { | |
} | ||
} | ||
|
||
if !applicationTokenListViewModel.applicationTokens.isEmpty { | ||
Section(ApplicationTokenListView.title) { | ||
ForEach(applicationTokenListViewModel.applicationTokens) { token in | ||
ApplicationTokenListItemView(item: token) | ||
} | ||
} | ||
} | ||
|
||
if viewModel.currentUserCanModifyUsers { | ||
if isCurrentUser || viewModel.currentUserCanModifyUsers { | ||
Section(Strings.accountManagementSectionTitle) { | ||
Button(Strings.setNewPasswordActionTitle) { | ||
presentPasswordAlert = true | ||
if isCurrentUser { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is why I couldn't see Application Passwords for other users? Can we make that possible? Doesn't have to be in this PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh sorry, I didn't realize your question was about the current implementation in the app. That's in my TODO list. It's not available now because the "Application Passwords" entry was implemented as for current user only. |
||
NavigationLink(ApplicationTokenListView.title) { | ||
ApplicationTokenListView(dataProvider: applicationTokenListDataProvider) | ||
} | ||
} | ||
Button(role: .destructive) { | ||
presentUserPicker = true | ||
} label: { | ||
Text( | ||
deleteUserViewModel.isDeletingUser ? | ||
Strings.deletingUserActionTitle | ||
: Strings.deleteUserActionTitle | ||
) | ||
|
||
if viewModel.currentUserCanModifyUsers { | ||
Button(Strings.setNewPasswordActionTitle) { | ||
presentPasswordAlert = true | ||
} | ||
Button(role: .destructive) { | ||
presentUserPicker = true | ||
Task { | ||
if deleteUserViewModel.otherUsers.isEmpty { | ||
await deleteUserViewModel.fetchOtherUsers() | ||
} | ||
} | ||
} label: { | ||
Text( | ||
deleteUserViewModel.isDeletingUser ? | ||
Strings.deletingUserActionTitle | ||
: Strings.deleteUserActionTitle | ||
) | ||
} | ||
.disabled(deleteUserViewModel.isDeletingUser) | ||
} | ||
.disabled(deleteUserViewModel.isDeletingUser) | ||
} | ||
} | ||
} | ||
|
@@ -114,11 +121,6 @@ struct UserDetailsView: View { | |
.onAppear() { | ||
Task { | ||
await viewModel.loadCurrentUserRole() | ||
await deleteUserViewModel.fetchOtherUsers() | ||
|
||
if await userService.isCurrentUser(user) { | ||
await applicationTokenListViewModel.fetchTokens() | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -397,6 +399,6 @@ private extension String { | |
|
||
#Preview { | ||
NavigationStack { | ||
UserDetailsView(user: DisplayUser.MockUser, userService: MockUserProvider(), applicationTokenListDataProvider: StaticTokenProvider(tokens: .success(.testTokens))) | ||
UserDetailsView(user: DisplayUser.MockUser, isCurrentUser: true, userService: MockUserProvider(), applicationTokenListDataProvider: StaticTokenProvider(tokens: .success(.testTokens))) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import XCTest | |
|
||
@testable import WordPress | ||
|
||
@MainActor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actors support in XCTest has been a bit shaky. I'd suggest writing all new tests in swift-testing. It's pretty similar to XCTest https://developer.apple.com/documentation/testing/migratingfromxctest |
||
class ApplicationPasswordsViewModelTests: XCTestCase { | ||
|
||
func testOrder() async throws { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) this should not be needed as long as you are displaying the
List
at the bottom. TheProgressView
could be shown as an.overlay
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't get it to work. Do you mind showing me an example?