Skip to content

Commit

Permalink
Fix for implicit unwrapped optional - username (#91)
Browse files Browse the repository at this point in the history
* Fix for implicit unwrapped username

* Changed implicit unwrapped optionals to explicit optionals

* Update to resolve linting errors

* Update Source/View Controllers/UploadViewController.swift

Co-authored-by: Isaac Halvorson <hello@hisaac.net>

* Implemented requested changes

* Removed nil check for payloadIdentifier

Co-authored-by: Isaac Halvorson <hello@hisaac.net>
  • Loading branch information
MarkusBux and hisaac authored Feb 3, 2021
1 parent 48c1f28 commit 5205229
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions Source/View Controllers/UploadViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class UploadViewController: NSViewController {
@objc dynamic var saveCredentials = true
@objc dynamic var readyForUpload = false

@objc dynamic var username: String!
@objc dynamic var password: String!
@objc dynamic var payloadName: String!
@objc dynamic var payloadIdentifier: String! = UUID().uuidString
@objc dynamic var payloadDescription: String!
@objc dynamic var username: String?
@objc dynamic var password: String?
@objc dynamic var payloadName: String?
@objc dynamic var payloadIdentifier = UUID().uuidString
@objc dynamic var payloadDescription: String?

@objc dynamic var site = false
@objc dynamic var siteName: String?
Expand Down Expand Up @@ -82,6 +82,12 @@ class UploadViewController: NSViewController {
print("Uploading profile: \(payloadName ?? "?")")
self.networkOperationsTitle = "Uploading \(payloadName ?? "profile")"

guard let username = username, let password = password else {
print("Username or password not set")
Alert().display(header: "Attention:", message: "Username or password not set")
return
}

let model = Model.shared
let profile = model.exportProfile(organization: organizationLabel.stringValue,
identifier: payloadIdentifierLabel.stringValue,
Expand All @@ -107,6 +113,15 @@ class UploadViewController: NSViewController {
}

@IBAction func checkConnectionPressed(_ sender: NSButton) {
guard let username = username, let password = password else {
print("Username or password not set")
Alert().display(header: "Attention:", message: "Username or password not set")
DispatchQueue.main.async {
self.handleCheckConnectionFailure(enforceSigning: nil)
}
return
}

print("Checking connection")
self.networkOperationsTitle = "Checking Jamf Pro server"

Expand Down Expand Up @@ -230,23 +245,25 @@ class UploadViewController: NSViewController {
}

func updateCredentialsAvailable() {
guard credentialsAvailable != (
!jamfProServerLabel.stringValue.isEmpty
&& (username != nil)
&& !username.isEmpty
&& (password != nil)
&& !password.isEmpty) else { return }
credentialsAvailable = !credentialsAvailable
if let username = username, !username.isEmpty,
let password = password, !password.isEmpty,
!jamfProServerLabel.stringValue.isEmpty {
credentialsAvailable = true
} else {
credentialsAvailable = false
}
}

func updateReadForUpload() {
guard let payloadName = payloadName, !payloadName.isEmpty else {
readyForUpload = false
return
}

guard readyForUpload != (
credentialsVerified
&& credentialsAvailable
&& !organizationLabel.stringValue.isEmpty
&& (payloadName != nil)
&& !payloadName.isEmpty
&& (payloadIdentifier != nil)
&& !payloadIdentifier.isEmpty
&& isSiteReadyToUpload())
else { return }
Expand Down Expand Up @@ -340,8 +357,9 @@ class UploadViewController: NSViewController {

func syncronizeCredentials() {
if saveCredentials {
if credentialsAvailable {
if let username = username, let password = password, credentialsAvailable {
do {

try SecurityWrapper.saveCredentials(username: username,
password: password,
server: jamfProServerLabel.stringValue)
Expand All @@ -350,6 +368,7 @@ class UploadViewController: NSViewController {
}
}
} else {
guard let username = username else { return }
try? SecurityWrapper.removeCredentials(server: jamfProServerLabel.stringValue, username: username)
}
}
Expand Down

0 comments on commit 5205229

Please sign in to comment.