Skip to content

Commit

Permalink
Merge pull request #474 from PermanentOrg/bugfix/VSP-1524-Share-link-…
Browse files Browse the repository at this point in the history
…from-email-notification-opens-error-page

VSP-1524 iOS share link from email notification opens error page
  • Loading branch information
flaviuvsp authored Jan 16, 2025
2 parents 1daad8c + 4a1ac83 commit 3a7f39b
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 6 deletions.
116 changes: 112 additions & 4 deletions Permanent/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,119 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

switch url.pathComponents[1] {
case "share":
if rootViewController.isDrawerRootActive {
return navigateFromUniversalLink(url: url)
if url.absoluteString.contains("targetArchiveNbr")
{
let pathComponents = url.pathComponents
let queryItems = URLComponents(string: url.absoluteString)?.queryItems

let shareIdOpt = pathComponents.count > 3 ? pathComponents[3] : nil
let folderLinkIdOpt = pathComponents.count > 4 ? pathComponents[4] : nil

let targetArchiveNbrOpt = queryItems?.first(where: { $0.name == "targetArchiveNbr" })?.value

guard let shareId: Int = Int(shareIdOpt ?? ""),
let folderLinkId: Int = Int(folderLinkIdOpt ?? "") else {
return true
}

// Add API request here
let apiOperation = APIOperation(ShareEndpoint.getShareForPreview(shareId: shareId, folder_linkId: folderLinkId))
apiOperation.execute(in: APIRequestDispatcher()) { [weak self] result in
switch result {
case .json(let response, _):

guard let model: APIResults<ShareVO> = JSONHelper.decoding( from: response, with: APIResults<ShareVO>.decoder),
let data = model.results.first?.data,
let shareVO = data.first?.shareVO
else {
return
}
guard
let toArchiveId: Int = shareVO.archiveID else {
return
}
let accessRole: String = AccessRole.roleForValue(shareVO.accessRole ?? "").groupName
let toArchiveNbr: String = targetArchiveNbrOpt ?? ""
let toArchiveName: String = ""

if let name: String = shareVO.recordVO?.displayName as? String,
let recordId: Int = shareVO.recordVO?.recordID {
DispatchQueue.main.async {
guard
let archiveNbrInt = shareVO.recordVO?.archiveID else {
return
}
let archiveNbr: String = String(archiveNbrInt)

let shareNotifPayload = ShareNotificationPayload(name: name, recordId: recordId, folderLinkId: folderLinkId, archiveNbr: archiveNbr, type: FileType.miscellaneous.rawValue, toArchiveId: toArchiveId, toArchiveNbr: toArchiveNbr, toArchiveName: toArchiveName, accessRole: accessRole)
try? PreferencesManager.shared.setNonPlistObject(shareNotifPayload, forKey: Constants.Keys.StorageKeys.sharedFileKey)

if let drawerVC = self?.rootViewController.current as? DrawerViewController {
drawerVC.dismiss(animated: false) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
if let sharesVC = drawerVC.rootViewController.visibleViewController as? SharesViewController {
sharesVC.segmentedControl.selectedSegmentIndex = 1
sharesVC.segmentedControlValueChanged(sharesVC.segmentedControl)

_ = sharesVC.checkSavedFile()
} else {
let sharesVC = UIViewController.create(withIdentifier: .shares, from: .share) as! SharesViewController
sharesVC.selectedIndex = ShareListType.sharedWithMe.rawValue

drawerVC.leftSideMenuController.selectedMenuOption = TableViewData.drawerData[DrawerSection.navigationScreens]![0]

self?.rootViewController.changeDrawerRoot(viewController: sharesVC)
}
}
}
}
}
} else if let sharedFolderName: String = shareVO.folderVO?.displayName as? String {
DispatchQueue.main.async {
guard
let archiveNbrInt = shareVO.folderVO?.archiveID else {
return
}
let archiveNbr: String = String(archiveNbrInt)

let shareNotifPayload = ShareNotificationPayload(name: sharedFolderName, recordId: 0, folderLinkId: folderLinkId, archiveNbr: archiveNbr, type: FileType.miscellaneous.rawValue, toArchiveId: toArchiveId, toArchiveNbr: toArchiveNbr, toArchiveName: toArchiveName, accessRole: accessRole)
try? PreferencesManager.shared.setNonPlistObject(shareNotifPayload, forKey: Constants.Keys.StorageKeys.sharedFolderKey)

if let drawerVC = self?.rootViewController.current as? DrawerViewController {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
if drawerVC.rootViewController.visibleViewController is SharesViewController == false {
let sharesVC: SharesViewController = UIViewController.create(withIdentifier: .shares, from: .share) as! SharesViewController

drawerVC.leftSideMenuController.selectedMenuOption = TableViewData.drawerData[DrawerSection.navigationScreens]![0]

self?.rootViewController.changeDrawerRoot(viewController: sharesVC)
} else {
let sharesVC = drawerVC.rootViewController.visibleViewController as! SharesViewController
sharesVC.segmentedControl.selectedSegmentIndex = 1
sharesVC.segmentedControlValueChanged(sharesVC.segmentedControl)

_ = sharesVC.checkSavedFolder()
}
}
}
}
}

case .error(let error, _):
break

default:
break
}
}
return true
} else {
saveUnivesalLinkToken(url.lastPathComponent)
return false
if rootViewController.isDrawerRootActive {
return navigateFromUniversalLink(url: url)
} else {
saveUnivesalLinkToken(url.lastPathComponent)
return false
}
}

case "p":
Expand Down
2 changes: 1 addition & 1 deletion Permanent/Common/Network/APIErrors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ enum MembersOperationsError: String {
return "There is already a pending owner for this Permanent Archive".localized()

case .emailNotValid:
return "No account found for the inserted email".localized()
return "No account found for this email address".localized()

case .duplicateAccount:
return "This account already has access to the Permanent Archive".localized()
Expand Down
30 changes: 29 additions & 1 deletion Permanent/Common/Network/ShareEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ enum ShareEndpoint {

case requestShareAccess(token: String)

case getShareForPreview(shareId: Int, folder_linkId: Int)

}

extension ShareEndpoint: RequestProtocol {
Expand All @@ -35,12 +37,20 @@ extension ShareEndpoint: RequestProtocol {
case .getShares: return "/share/getShares"
case .checkLink: return "/share/checkShareLink"
case .requestShareAccess: return "/share/requestShareAccess"
case .getShareForPreview: return "/share/getShareForPreview"
}
}

var method: RequestMethod { .post }

var parameters: RequestParameters? { nil }
var parameters: RequestParameters? {
switch self {
case .getShareForPreview(let shareId, let folder_linkId):
return getShareForPreview(shareId: shareId, folder_linkId: folder_linkId)
default :
return nil
}
}

var requestType: RequestType { .data }

Expand Down Expand Up @@ -97,3 +107,21 @@ extension ShareEndpoint: RequestProtocol {

var customURL: String? { nil }
}

extension ShareEndpoint {
func getShareForPreview(shareId: Int, folder_linkId: Int) -> RequestParameters {
return [
"RequestVO":
[
"data": [
[
"ShareVO": [
"shareId": "\(shareId)",
"folder_linkId": "\(folder_linkId)"
]
]
]
]
]
}
}

0 comments on commit 3a7f39b

Please sign in to comment.