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

chore: added SSO switch-on check #547

Merged
merged 1 commit into from
Dec 5, 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
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public struct StartupView: View {
}
.padding(.horizontal, isHorizontal ? 10 : 24)

LogistrationBottomView { buttonAction in
LogistrationBottomView(
ssoEnabled: viewModel.config.uiComponents.samlSSOLoginEnabled
) { buttonAction in
switch buttonAction {
case .signIn:
viewModel.router.showLoginScreen(sourceScreen: .startup)
Expand Down Expand Up @@ -139,7 +141,8 @@ struct StartupView_Previews: PreviewProvider {
static var previews: some View {
let vm = StartupViewModel(
router: AuthorizationRouterMock(),
analytics: CoreAnalyticsMock()
analytics: CoreAnalyticsMock(),
config: ConfigMock()
)

StartupView(viewModel: vm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ import Core
public class StartupViewModel: ObservableObject {
let router: AuthorizationRouter
let analytics: CoreAnalytics
let config: ConfigProtocol

@Published var searchQuery: String?

public init(
router: AuthorizationRouter,
analytics: CoreAnalytics
analytics: CoreAnalytics,
config: ConfigProtocol
) {
self.router = router
self.analytics = analytics
self.config = config
}

func logAnalytics(searchQuery: String?) {
Expand Down
32 changes: 18 additions & 14 deletions Core/Core/View/Base/LogistrationBottomView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public enum LogistrationAction: Sendable {

public struct LogistrationBottomView: View {
private let action: (LogistrationAction) -> Void
private let ssoEnabled: Bool

@Environment(\.isHorizontal) private var isHorizontal

public init(_ action: @escaping (LogistrationAction) -> Void) {
public init(ssoEnabled: Bool, _ action: @escaping (LogistrationAction) -> Void) {
self.ssoEnabled = ssoEnabled
self.action = action
}

Expand All @@ -52,17 +54,19 @@ public struct LogistrationBottomView: View {
.frame(width: 100)
.accessibilityIdentifier("logistration_signin_button")

StyledButton(
CoreLocalization.SignIn.logInWithSsoBtn,
action: {
action(.signInWithSSO)
},
color: Theme.Colors.white,
textColor: Theme.Colors.secondaryButtonTextColor,
borderColor: Theme.Colors.secondaryButtonBorderColor
)
.frame(width: 100)
.accessibilityIdentifier("logistration_signin_withsso_button")
if ssoEnabled {
StyledButton(
CoreLocalization.SignIn.logInWithSsoBtn,
action: {
action(.signInWithSSO)
},
color: Theme.Colors.white,
textColor: Theme.Colors.secondaryButtonTextColor,
borderColor: Theme.Colors.secondaryButtonBorderColor
)
.frame(width: 100)
.accessibilityIdentifier("logistration_signin_withsso_button")
}
}
.padding(.horizontal, isHorizontal ? 0 : 0)
}
Expand All @@ -73,12 +77,12 @@ public struct LogistrationBottomView: View {
#if DEBUG
struct LogistrationBottomView_Previews: PreviewProvider {
static var previews: some View {
LogistrationBottomView {_ in }
LogistrationBottomView(ssoEnabled: false) {_ in }
.preferredColorScheme(.light)
.previewDisplayName("StartupView Light")
.loadFonts()

LogistrationBottomView {_ in }
LogistrationBottomView(ssoEnabled: false) {_ in }
.preferredColorScheme(.dark)
.previewDisplayName("StartupView Dark")
.loadFonts()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ public struct CourseDetailsView: View {
}
}
if !viewModel.userloggedIn {
LogistrationBottomView { buttonAction in
LogistrationBottomView(
ssoEnabled: viewModel.config.uiComponents.samlSSOLoginEnabled
) { buttonAction in
switch buttonAction {
case .signIn:
viewModel.router.showLoginScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ public struct DiscoveryView: View {
}.accessibilityAction {}

if !viewModel.userloggedIn {
LogistrationBottomView { buttonAction in
LogistrationBottomView(
ssoEnabled: viewModel.config.uiComponents.samlSSOLoginEnabled
) { buttonAction in
switch buttonAction {
case .signIn:
viewModel.router.showLoginScreen(sourceScreen: .discovery)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ public struct DiscoveryWebview: View {
}

if !viewModel.userloggedIn, !isLoading {
LogistrationBottomView { buttonAction in
LogistrationBottomView(
ssoEnabled: viewModel.config.uiComponents.samlSSOLoginEnabled
) { buttonAction in
switch buttonAction {
case .signIn:
viewModel.router.showLoginScreen(sourceScreen: sourceScreen)
Expand Down
3 changes: 2 additions & 1 deletion OpenEdX/DI/ScreenAssembly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class ScreenAssembly: Assembly {
container.register(StartupViewModel.self) { @MainActor r in
StartupViewModel(
router: r.resolve(AuthorizationRouter.self)!,
analytics: r.resolve(CoreAnalytics.self)!
analytics: r.resolve(CoreAnalytics.self)!,
config: r.resolve(ConfigProtocol.self)!
)
}

Expand Down
Loading