From 21a122c297db47f7bed21f52f035af3ee1b875a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20Cisin=CC=81ski?= Date: Wed, 13 Mar 2024 13:42:52 +0100 Subject: [PATCH] Fix for OpenSource Contributing description and database generated files --- CONTRIBUTING.md | 2 +- ...IconDescriptionDatabaseImpl+Database.swift | 51 +----- ...rviceDefinitionDatabaseImpl+Database.swift | 151 +----------------- 3 files changed, 3 insertions(+), 201 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f326d8d5..f1ae553e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,7 +20,7 @@ We welcome meaningful code contributions to the 2FAS for iOS project. If you are 1. Fork this repository to your own GitHub account 2. Clone the repository to your local machine 3. Copy example Keys.swift from TwoFAS/opensource folder to TwoFAS/Protection (override the encrypted file) -4. Copy IconDescriptionDatabaseImpl+Database.swift and ServiceDefinitionDatabaseImpl+Database.swift from TwoFAS/opensource to TwoFAS/Content/Sources (override files) +4. Copy IconDescriptionDatabaseImpl+Database.swift and ServiceDefinitionDatabaseImpl+Database.swift from TwoFAS/opensource to TwoFAS/Content/Sources (override files). Remove all files with "*DatabaseImpl+Database[number].swift" in it. 5. Copy Assets.car from TwoFAS/opensource to TwoFAS/Content/Assets (override the file) 6. Create a new branch for your changes (e.g. `feature/new-login-screen`) 7. Make your changes diff --git a/TwoFAS/opensource/IconDescriptionDatabaseImpl+Database.swift b/TwoFAS/opensource/IconDescriptionDatabaseImpl+Database.swift index 6ad28fb0..b5180a81 100644 --- a/TwoFAS/opensource/IconDescriptionDatabaseImpl+Database.swift +++ b/TwoFAS/opensource/IconDescriptionDatabaseImpl+Database.swift @@ -20,56 +20,7 @@ import UIKit import Common -public protocol IconDescriptionDatabase: AnyObject { - func name(for iconTypeID: IconTypeID) -> String? - func iconDescription(for iconTypeID: IconTypeID) -> IconDescription? - func listAll() -> [IconDescription] - func grouppedList() -> [IconDescriptionGroup] -} - -public final class IconDescriptionDatabaseImpl { - public static var bundle: Bundle { - Bundle.module - } - private let database = IconDescriptionDatabaseGenerated() - public init() {} -} - -extension IconDescriptionDatabaseImpl: IconDescriptionDatabase { - public func name(for iconTypeID: IconTypeID) -> String? { - iconDescription(for: iconTypeID)?.name - } - - public func iconDescription(for iconTypeID: IconTypeID) -> IconDescription? { - database.icons.first(where: { $0.iconTypeID == iconTypeID }) - } - - public func listAll() -> [IconDescription] { - database.icons - } - - public func grouppedList() -> [IconDescriptionGroup] { - let all = listAll() - - let grouped: [IconDescriptionGroup] = Dictionary(grouping: all, by: { def -> String in - let first = def.name.first! - if first.isNumber { - return "0-9" - } else { - return String(first.uppercased()) - } - }) - .sorted(by: { $0.key < $1.key }) - .map { key, icons in - let sortedIcons = icons.sorted(by: { $0.name.lowercased() < $1.name.lowercased() }) - return IconDescriptionGroup(title: key, icons: sortedIcons) - } - - return grouped - } -} - -private final class IconDescriptionDatabaseGenerated { +final class IconDescriptionDatabaseGenerated { var icons: [IconDescription] { [] } diff --git a/TwoFAS/opensource/ServiceDefinitionDatabaseImpl+Database.swift b/TwoFAS/opensource/ServiceDefinitionDatabaseImpl+Database.swift index c13bb23f..f1282509 100644 --- a/TwoFAS/opensource/ServiceDefinitionDatabaseImpl+Database.swift +++ b/TwoFAS/opensource/ServiceDefinitionDatabaseImpl+Database.swift @@ -20,156 +20,7 @@ import UIKit import Common -public protocol ServiceDefinitionDatabase: AnyObject { - func listAll() -> [ServiceDefinition] - func service(using serviceTypeID: ServiceTypeID) -> ServiceDefinition? - func serviceName(for serviceTypeID: ServiceTypeID?) -> String? - - func findService(using issuer: String) -> ServiceDefinition? - func findServices(byTag searchText: String) -> [ServiceDefinition] - func findServicesByTagOrIssuer( - _ searchText: String, - exactMatch: Bool, - useTags: Bool - ) -> [ServiceDefinition] - func findServices(domain searchText: String) -> [ServiceDefinition] - - func findLegacyService(using string: String) -> ServiceTypeID? - func findLegacyIcon(using string: String) -> IconTypeID? -} - -public final class ServiceDefinitionDatabaseImpl { - private let db = ServiceDefinitionDatabaseGenerated() - private let legacyExchangeDb = LegacyExchangeDatabase() - private let legacyServiceDB: LegacyServiceDatabase = LegacyServiceDatabaseImpl() - - public init() {} -} - -extension ServiceDefinitionDatabaseImpl: ServiceDefinitionDatabase { - public func listAll() -> [ServiceDefinition] { - db.services - } - - public func service(using serviceTypeID: ServiceTypeID) -> ServiceDefinition? { - db.services.first(where: { $0.serviceTypeID == serviceTypeID }) - } - - public func serviceName(for serviceTypeID: ServiceTypeID?) -> String? { - guard let serviceTypeID else { return nil } - return service(using: serviceTypeID)?.name - } - - public func findLegacyService(using string: String) -> ServiceTypeID? { - guard let serviceType = legacyExchangeDb.looselyCheckImportType(for: string) else { return nil } - return legacyServiceDB.serviceTypeID(for: serviceType) - } - - public func findLegacyIcon(using string: String) -> IconTypeID? { - guard let serviceTypeID = findLegacyService(using: string), - let iconTypeID = service(using: serviceTypeID)?.iconTypeID - else { return nil } - - return iconTypeID - } - - public func findService(using issuer: String) -> ServiceDefinition? { - // TODO: Duplicated from New Code interactor - remove when migration is properly set up - let definitions = listAll() - for def in definitions { - if let issuerList = def.issuer { - for iss in issuerList { - if iss.lowercased() == issuer.lowercased() { - return def - } - } - } - - if let issuerRules = def.matchingRules?.filter({ $0.field == .issuer }), !issuerRules.isEmpty { - for rule in issuerRules { - if rule.isMatching(for: issuer) { - return def - } - } - } - } - return nil - } - - public func findServices(byTag searchText: String) -> [ServiceDefinition] { - let query = searchText.uppercased() - let definitions = listAll() - return definitions.filter({ service in - guard let tags = service.tags else { return false } - return tags.contains(where: { $0.contains(query) }) - }) - } - - public func findServicesByTagOrIssuer( - _ searchText: String, - exactMatch: Bool, - useTags: Bool - ) -> [ServiceDefinition] { - let query = searchText.uppercased() - let definitions = listAll() - return definitions.filter({ service in - let name = service.name.uppercased() - if exactMatch { - if name == query { - return true - } - } else { - if name.contains(query) { - return true - } - } - - if let issuerList = service.issuer { - for issuer in issuerList { - if exactMatch { - if issuer.uppercased() == query { - return true - } - } else { - if issuer.uppercased().contains(query) { - return true - } - } - } - } - - if let issuerRules = service.matchingRules?.filter({ $0.field == .issuer }), !issuerRules.isEmpty { - for rule in issuerRules { - if rule.isMatching(for: query) { - return true - } - } - } - - if useTags { - return service.tags?.contains(where: { - if exactMatch { - return $0.uppercased() == query - } else { - return $0.uppercased().contains(query) - } - }) ?? false - } - return false - }) - } - - public func findServices(domain searchText: String) -> [ServiceDefinition] { - let query = searchText.uppercased() - let definitions = listAll() - return definitions.filter({ service in - query.contains(service.name.uppercased()) || - service.issuer?.first(where: { query.contains($0.uppercased()) }) != nil - }) - } -} - -private final class ServiceDefinitionDatabaseGenerated { +final class ServiceDefinitionDatabaseGenerated { var services: [ServiceDefinition] { [] }