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: configuration management #158

Merged
merged 12 commits into from
Nov 21, 2023
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,8 @@ xcode-frameworks

vendor/
.bundle/

venv/
Podfile.lock
config_settings.yaml
default_config/
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct FieldsView: View {

let fields: [FieldConfiguration]
let router: BaseRouter
let configuration: Config
let config: ConfigProtocol
let cssInjector: CSSInjector
let proxy: GeometryProxy
@Environment(\.colorScheme) var colorScheme
Expand Down Expand Up @@ -107,7 +107,7 @@ struct FieldsView_Previews: PreviewProvider {
FieldsView(
fields: fields,
router: AuthorizationRouterMock(),
configuration: ConfigMock(),
config: ConfigMock(),
cssInjector: CSSInjectorMock(),
proxy: proxy
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public class SignInViewModel: ObservableObject {
}

let router: AuthorizationRouter
private let config: Config
private let config: ConfigProtocol
private let interactor: AuthInteractorProtocol
private let analytics: AuthorizationAnalytics
private let validator: Validator

public init(
interactor: AuthInteractorProtocol,
router: AuthorizationRouter,
config: Config,
config: ConfigProtocol,
analytics: AuthorizationAnalytics,
validator: Validator
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ public struct SignUpView: View {

FieldsView(fields: requiredFields,
router: viewModel.router,
configuration: viewModel.config,
config: viewModel.config,
cssInjector: viewModel.cssInjector,
proxy: proxy)

if !viewModel.isShowProgress {
DisclosureGroup(isExpanded: $disclosureGroupOpen, content: {
FieldsView(fields: nonRequiredFields,
router: viewModel.router,
configuration: viewModel.config,
config: viewModel.config,
cssInjector: viewModel.cssInjector,
proxy: proxy).padding(.horizontal, 1)
}, label: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SignUpViewModel: ObservableObject {
@Published var fields: [FieldConfiguration] = []

let router: AuthorizationRouter
let config: Config
let config: ConfigProtocol
let cssInjector: CSSInjector

private let interactor: AuthInteractorProtocol
Expand All @@ -36,7 +36,7 @@ public class SignUpViewModel: ObservableObject {
interactor: AuthInteractorProtocol,
router: AuthorizationRouter,
analytics: AuthorizationAnalytics,
config: Config,
config: ConfigProtocol,
cssInjector: CSSInjector,
validator: Validator
) {
Expand Down
47 changes: 46 additions & 1 deletion Core/Core.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
07DDFCBD29A780BB00572595 /* UINavigationController+Animation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07DDFCBC29A780BB00572595 /* UINavigationController+Animation.swift */; };
C8C446EF233F81B9FABB77D2 /* Pods_App_Core.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 349B90CD6579F7B8D257E515 /* Pods_App_Core.framework */; };
CFC84952299F8B890055E497 /* Debounce.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFC84951299F8B890055E497 /* Debounce.swift */; };
DBF6F2412B014ADA0098414B /* FirebaseConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF6F2402B014ADA0098414B /* FirebaseConfig.swift */; };
DBF6F2462B01DAFE0098414B /* AgreementConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF6F2452B01DAFE0098414B /* AgreementConfig.swift */; };
DBF6F2482B01E20A0098414B /* ConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF6F2472B01E20A0098414B /* ConfigTests.swift */; };
DBF6F24A2B0380E00098414B /* FeaturesConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF6F2492B0380E00098414B /* FeaturesConfig.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -243,6 +247,10 @@
9D5B06CAA99EA5CD49CBE2BB /* Pods-App-Core.debugdev.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Core.debugdev.xcconfig"; path = "Target Support Files/Pods-App-Core/Pods-App-Core.debugdev.xcconfig"; sourceTree = "<group>"; };
C7E5BCE79CE297B20777B27A /* Pods-App-Core.debugprod.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Core.debugprod.xcconfig"; path = "Target Support Files/Pods-App-Core/Pods-App-Core.debugprod.xcconfig"; sourceTree = "<group>"; };
CFC84951299F8B890055E497 /* Debounce.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Debounce.swift; sourceTree = "<group>"; };
DBF6F2402B014ADA0098414B /* FirebaseConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseConfig.swift; sourceTree = "<group>"; };
DBF6F2452B01DAFE0098414B /* AgreementConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgreementConfig.swift; sourceTree = "<group>"; };
DBF6F2472B01E20A0098414B /* ConfigTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigTests.swift; sourceTree = "<group>"; };
DBF6F2492B0380E00098414B /* FeaturesConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeaturesConfig.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -366,9 +374,9 @@
0727876E28D233EC002E9142 /* Configuration */ = {
isa = PBXGroup;
children = (
DBF6F2422B014AF30098414B /* Config */,
CFC84955299FAC4D0055E497 /* Combine */,
0770DE1828D0847D006D8A5D /* BaseRouter.swift */,
0727876F28D23411002E9142 /* Config.swift */,
0231CDBD2922422D00032416 /* CSSInjector.swift */,
02280F5A294B4E6F0032823A /* Connectivity.swift */,
);
Expand Down Expand Up @@ -467,6 +475,7 @@
0770DE5D28D0B209006D8A5D /* Localizable.strings */,
0770DE5128D0ADFF006D8A5D /* Assets.xcassets */,
071009CF28D1E3A600344290 /* Constants.swift */,
DBFB74502B0CA508004370F9 /* Tests */,
);
path = Core;
sourceTree = "<group>";
Expand Down Expand Up @@ -564,6 +573,25 @@
path = Combine;
sourceTree = "<group>";
};
DBF6F2422B014AF30098414B /* Config */ = {
isa = PBXGroup;
children = (
0727876F28D23411002E9142 /* Config.swift */,
DBF6F2402B014ADA0098414B /* FirebaseConfig.swift */,
DBF6F2492B0380E00098414B /* FeaturesConfig.swift */,
DBF6F2452B01DAFE0098414B /* AgreementConfig.swift */,
);
path = Config;
sourceTree = "<group>";
};
DBFB74502B0CA508004370F9 /* Tests */ = {
isa = PBXGroup;
children = (
DBF6F2472B01E20A0098414B /* ConfigTests.swift */,
);
path = Tests;
sourceTree = "<group>";
};
F1620A3A2C8B0699EAA61B57 /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -638,6 +666,7 @@
TargetAttributes = {
07169468296D996800E3DED6 = {
CreatedOnToolsVersion = 14.2;
LastSwiftMigration = 1500;
};
0770DE0728D07831006D8A5D = {
CreatedOnToolsVersion = 14.0;
Expand Down Expand Up @@ -738,6 +767,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DBF6F2482B01E20A0098414B /* ConfigTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -747,6 +777,7 @@
files = (
0727878528D31657002E9142 /* Data_User.swift in Sources */,
02F6EF4A28D9F0A700835477 /* DateExtension.swift in Sources */,
DBF6F2462B01DAFE0098414B /* AgreementConfig.swift in Sources */,
027BD3AF2909475000392132 /* DismissKeyboardTapHandler.swift in Sources */,
02E225B0291D29EB0067769A /* UrlExtension.swift in Sources */,
0770DE7928D0C4A9006D8A5D /* RoundedCorners.swift in Sources */,
Expand Down Expand Up @@ -810,6 +841,7 @@
0770DE1928D0847D006D8A5D /* BaseRouter.swift in Sources */,
0284DBFE28D48C5300830893 /* CourseItem.swift in Sources */,
0248C92329C075EF00DC8402 /* CourseBlockModel.swift in Sources */,
DBF6F2412B014ADA0098414B /* FirebaseConfig.swift in Sources */,
072787B628D37A0E002E9142 /* Validator.swift in Sources */,
0236961D28F9A2D200EEF206 /* Data_AuthResponse.swift in Sources */,
02B2B594295C5C7A00914876 /* Thread.swift in Sources */,
Expand All @@ -832,6 +864,7 @@
02F6EF3B28D9B8EC00835477 /* CourseCellView.swift in Sources */,
023A1138291432FD00D0D354 /* FieldConfiguration.swift in Sources */,
024D865E28F02C6B0077E0A0 /* WebView.swift in Sources */,
DBF6F24A2B0380E00098414B /* FeaturesConfig.swift in Sources */,
02F164372902A9EB0090DDEF /* StringExtension.swift in Sources */,
0231CDBE2922422D00032416 /* CSSInjector.swift in Sources */,
0236961928F9A26900EEF206 /* AuthRepository.swift in Sources */,
Expand Down Expand Up @@ -974,6 +1007,7 @@
02DD1C9B29E80CE400F35DCE /* DebugStage */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = L8PG7LC3Y3;
Expand All @@ -986,6 +1020,7 @@
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down Expand Up @@ -1086,6 +1121,7 @@
02DD1C9E29E80CED00F35DCE /* ReleaseStage */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = L8PG7LC3Y3;
Expand All @@ -1106,6 +1142,7 @@
07169470296D996900E3DED6 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = L8PG7LC3Y3;
Expand All @@ -1118,6 +1155,7 @@
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -1126,6 +1164,7 @@
07169471296D996900E3DED6 /* DebugProd */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = L8PG7LC3Y3;
Expand All @@ -1138,6 +1177,7 @@
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -1146,6 +1186,7 @@
07169472296D996900E3DED6 /* DebugDev */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = L8PG7LC3Y3;
Expand All @@ -1158,6 +1199,7 @@
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -1166,6 +1208,7 @@
07169473296D996900E3DED6 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = L8PG7LC3Y3;
Expand All @@ -1186,6 +1229,7 @@
07169474296D996900E3DED6 /* ReleaseProd */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = L8PG7LC3Y3;
Expand All @@ -1206,6 +1250,7 @@
07169475296D996900E3DED6 /* ReleaseDev */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = L8PG7LC3Y3;
Expand Down
9 changes: 3 additions & 6 deletions Core/Core/Configuration/CSSInjector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ public class CSSInjector {

public let baseURL: URL

public init(baseURL: String) {
guard let url = URL(string: baseURL) else {
fatalError("Ivalid baseURL")
}
self.baseURL = url
public init(config: ConfigProtocol) {
self.baseURL = config.baseURL
}

public enum CssType {
Expand Down Expand Up @@ -151,7 +148,7 @@ public class CSSInjector {
#if DEBUG
public class CSSInjectorMock: CSSInjector {
public convenience init() {
self.init(baseURL: "https://google.com/")
self.init(config: ConfigMock())
}
}
#endif
55 changes: 0 additions & 55 deletions Core/Core/Configuration/Config.swift

This file was deleted.

31 changes: 31 additions & 0 deletions Core/Core/Configuration/Config/AgreementConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// AgreementConfig.swift
// Core
//
// Created by Muhammad Umer on 11/13/23.
//

import Foundation

private enum AgreementKeys: String {
case privacyPolicyURL = "PRIVACY_POLICY_URL"
case tosURL = "TOS_URL"
}

public class AgreementConfig: NSObject {
public var privacyPolicyURL: URL?
public var tosURL: URL?

init(dictionary: [String: AnyObject]) {
privacyPolicyURL = (dictionary[AgreementKeys.privacyPolicyURL.rawValue] as? String).flatMap(URL.init)
tosURL = (dictionary[AgreementKeys.tosURL.rawValue] as? String).flatMap(URL.init)
super.init()
}
}

private let key = "AGREEMENT_URLS"
extension Config {
public var agreement: AgreementConfig {
return AgreementConfig(dictionary: self[key] as? [String: AnyObject] ?? [:])
}
}
Loading