Skip to content

Commit

Permalink
Merge pull request #164 from decentralised-dataexchange/feature/157-E…
Browse files Browse the repository at this point in the history
…xpose-show-data-agreement-policy-screen

Feature/157 expose show data agreement policy screen
  • Loading branch information
georgepadayatti authored Nov 15, 2023
2 parents f9f7054 + 4dcddda commit 3d5fea7
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 15 deletions.
3 changes: 2 additions & 1 deletion PrivacyDashboardiOS/Classes/Constatnts/Constant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ struct Constant {
static let readIndividual = BBConsentPrivacyDashboardiOS.shared.baseUrl + "/service/individual/"
static let updateIndividual = BBConsentPrivacyDashboardiOS.shared.baseUrl + "/service/individual/"
static let fetchAllIndividuals = BBConsentPrivacyDashboardiOS.shared.baseUrl + "/service/individuals"
static let fetchDataAgreement = BBConsentPrivacyDashboardiOS.shared.baseUrl + "/service/individual/record/data-agreement/"
static let fetchDataAgreementRecord = BBConsentPrivacyDashboardiOS.shared.baseUrl + "/service/individual/record/data-agreement/"
static let fetchDataAgreement = BBConsentPrivacyDashboardiOS.shared.baseUrl + "/service/data-agreement/"
}
}
116 changes: 116 additions & 0 deletions PrivacyDashboardiOS/Classes/Model/Organisation/DAPolicy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//
// DAPolicy.swift
// PrivacyDashboardiOS
//
// Created by Mumthasir mohammed on 15/11/23.
//

import Foundation
// MARK: - DataAgreementPolicy
class DAPolicy: Codable {
var forgettable: Bool?
var policy: Policy?
var purpose, lifecycle, purposeDescription: String?
var dataAttributes: [DataAttributeInPolicy]?
var compatibleWithVersionID, controllerName: String?
var signature: Signature?
var id, controllerID, lawfulBasis, version: String?
var methodOfUse, dpiaDate: String?
var active: Bool?
var dpiaSummaryURL: String?
var controllerURL: String?

enum CodingKeys: String, CodingKey {
case forgettable, policy, purpose, lifecycle, purposeDescription, dataAttributes
case compatibleWithVersionID
case controllerName, signature, id
case controllerID
case lawfulBasis, version, methodOfUse, dpiaDate, active
case dpiaSummaryURL
case controllerURL
}

init(forgettable: Bool?, policy: Policy?, purpose: String?, lifecycle: String?, purposeDescription: String?, dataAttributes: [DataAttributeInPolicy]?, compatibleWithVersionID: String?, controllerName: String?, signature: Signature?, id: String?, controllerID: String?, lawfulBasis: String?, version: String?, methodOfUse: String?, dpiaDate: String?, active: Bool?, dpiaSummaryURL: String?, controllerURL: String?) {
self.forgettable = forgettable
self.policy = policy
self.purpose = purpose
self.lifecycle = lifecycle
self.purposeDescription = purposeDescription
self.dataAttributes = dataAttributes
self.compatibleWithVersionID = compatibleWithVersionID
self.controllerName = controllerName
self.signature = signature
self.id = id
self.controllerID = controllerID
self.lawfulBasis = lawfulBasis
self.version = version
self.methodOfUse = methodOfUse
self.dpiaDate = dpiaDate
self.active = active
self.dpiaSummaryURL = dpiaSummaryURL
self.controllerURL = controllerURL
}
}

// MARK: - DataAttribute
class DataAttributeInPolicy: Codable {
var category, id, description: String?
var sensitivity: Bool?
var name: String?

init(category: String?, id: String?, description: String?, sensitivity: Bool?, name: String?) {
self.category = category
self.id = id
self.description = description
self.sensitivity = sensitivity
self.name = name
}
}

// MARK: - Policy
class Policy: Codable {
var url: String?
var dataRetentionPeriodDays: Int?
var version, id, industrySector, geographicRestriction: String?
var thirdPartyDataSharing: Bool?
var jurisdiction, storageLocation, name: String?

init(url: String?, dataRetentionPeriodDays: Int?, version: String?, id: String?, industrySector: String?, geographicRestriction: String?, thirdPartyDataSharing: Bool?, jurisdiction: String?, storageLocation: String?, name: String?) {
self.url = url
self.dataRetentionPeriodDays = dataRetentionPeriodDays
self.version = version
self.id = id
self.industrySector = industrySector
self.geographicRestriction = geographicRestriction
self.thirdPartyDataSharing = thirdPartyDataSharing
self.jurisdiction = jurisdiction
self.storageLocation = storageLocation
self.name = name
}
}

// MARK: - Signature
class Signature: Codable {
var id: String?
var signedWithoutObjectReference: Bool?
var verificationMethod, verificationPayload, payload, timestamp: String?
var objectType, verificationPayloadHash, objectReference, signature: String?
var verificationJwsHeader, verificationSignedAs, verificationSignedBy, verificationArtifact: String?

init(id: String?, signedWithoutObjectReference: Bool?, verificationMethod: String?, verificationPayload: String?, payload: String?, timestamp: String?, objectType: String?, verificationPayloadHash: String?, objectReference: String?, signature: String?, verificationJwsHeader: String?, verificationSignedAs: String?, verificationSignedBy: String?, verificationArtifact: String?) {
self.id = id
self.signedWithoutObjectReference = signedWithoutObjectReference
self.verificationMethod = verificationMethod
self.verificationPayload = verificationPayload
self.payload = payload
self.timestamp = timestamp
self.objectType = objectType
self.verificationPayloadHash = verificationPayloadHash
self.objectReference = objectReference
self.signature = signature
self.verificationJwsHeader = verificationJwsHeader
self.verificationSignedAs = verificationSignedAs
self.verificationSignedBy = verificationSignedBy
self.verificationArtifact = verificationArtifact
}
}
22 changes: 17 additions & 5 deletions PrivacyDashboardiOS/Classes/PrivacyDashboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class PrivacyDashboard {
self.receiveDataBackFromPrivacyDashboard?(data)
}

readDataAgreementApi(dataAgreementId: dataAgreementId) { success, resultVal in
readDataAgreementRecordApi(dataAgreementId: dataAgreementId) { success, resultVal in
if resultVal["errorCode"] as? Int != 500 && !(resultVal["consentRecord"] is NSNull) {
// If existing record found for the data agreement ID
// Return the records reponse
Expand Down Expand Up @@ -85,7 +85,7 @@ public class PrivacyDashboard {
}

public static func updateDataAgreementStatus(dataAgreementId: String, status: Bool) {
readDataAgreementApi(dataAgreementId: dataAgreementId) { success, resultVal in
readDataAgreementRecordApi(dataAgreementId: dataAgreementId) { success, resultVal in
if resultVal["errorCode"] as? Int != 500 && !(resultVal["consentRecord"] is NSNull) {
// If existing record found for the data agreement ID
let resultDict = resultVal["consentRecord"] as? [String: Any]
Expand All @@ -105,7 +105,7 @@ public class PrivacyDashboard {
}

private static func createRecordApiCall(dataAgreementId: String, completion: @escaping (_ resultVal: [String: Any]) -> Void) {
BBConsentBaseWebService.shared.makeAPICall(urlString: Constant.URLStrings.fetchDataAgreement + (dataAgreementId), parameters: [:], method: .post) { success, resultVal in
BBConsentBaseWebService.shared.makeAPICall(urlString: Constant.URLStrings.fetchDataAgreementRecord + (dataAgreementId), parameters: [:], method: .post) { success, resultVal in
if success {
debugPrint(resultVal)
completion(resultVal)
Expand All @@ -130,6 +130,19 @@ public class PrivacyDashboard {
}
}

// MARK: - Read data agreement record api call
public static func readDataAgreementRecordApi(dataAgreementId: String, completionBlock:@escaping (_ success: Bool, _ resultVal: [String: Any]) -> Void){
BBConsentBaseWebService.shared.makeAPICall(urlString: Constant.URLStrings.fetchDataAgreementRecord + dataAgreementId, parameters: [:], method: .get) { success, resultVal in
if success {
debugPrint(resultVal)
completionBlock(true, resultVal)
} else {
debugPrint(resultVal)
completionBlock(false, resultVal)
}
}
}

// MARK: - Read data agreement api call
public static func readDataAgreementApi(dataAgreementId: String, completionBlock:@escaping (_ success: Bool, _ resultVal: [String: Any]) -> Void){
BBConsentBaseWebService.shared.makeAPICall(urlString: Constant.URLStrings.fetchDataAgreement + dataAgreementId, parameters: [:], method: .get) { success, resultVal in
Expand All @@ -155,8 +168,7 @@ public class PrivacyDashboard {
}
let dataAgreementVC = storyboard.instantiateViewController(withIdentifier: "BBConsentDataAgreementVC") as! BBConsentDataAgreementVC
dataAgreementVC.dataAgreementDic = [dataAgreementDic]
let navVC = UINavigationController.init(rootViewController: dataAgreementVC)
UIApplication.topViewController()?.present(navVC, animated: true, completion: nil)
UIApplication.topViewController()?.navigationController?.pushViewController(dataAgreementVC, animated: true)
}

// MARK: - 'Individual' related api calls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ class BBConsentDataAgreementVC: UITableViewController {
var policySectionDict = [String:Any]()
var DPIASectionDic = [String:Any]()
var dataAgreementDic = [[String: Any]]()
var instance: DAPolicy?

override func viewDidLoad() {
do {
let jsonData = try JSONSerialization.data(withJSONObject: dataAgreementDic[0])
instance = try JSONDecoder().decode(DAPolicy.self, from: jsonData)
} catch {
debugPrint(error)
}
setUI()
setData()
}
Expand All @@ -34,11 +41,17 @@ class BBConsentDataAgreementVC: UITableViewController {
}

func setData() {
if dataAgreementDic.count < 1 {
if dataAgreement?.count ?? 0 > 0 {
purposeSectionDic = ["Purpose": dataAgreement?[0].name ?? "", "Purpose Description": dataAgreement?[0].descriptionField ?? "", "Lawful basis of processing": dataAgreement?[0].lawfulBasis ?? ""]
policySectionDict = ["Policy URL": dataAgreement?[0].policyURL ?? "", "Jurisdiction": dataAgreement?[0].jurisdiction ?? "", "Third party data sharing": dataAgreement?[0].thirdPartyDisclosure ?? "", "Industry scope": dataAgreement?[0].industryScope ?? "", "Geographic restriction": dataAgreement?[0].geaographicRestriction ?? "", "Retention period": dataAgreement?[0].retentionPeriod ?? "", "Storage Location": dataAgreement?[0].storageLocation ?? ""]
DPIASectionDic = ["DPIA Date": dataAgreement?[0].DPIAdate ?? "", "DPIA Summary": dataAgreement?[0].DPIASummary ?? ""]
dataAgreementDic = [purposeSectionDic, policySectionDict, DPIASectionDic]

} else {
purposeSectionDic = ["Purpose": instance?.purpose ?? "", "Purpose Description": instance?.purposeDescription ?? "", "Lawful basis of processing": instance?.lawfulBasis ?? ""]
policySectionDict = ["Policy URL": instance?.policy?.url ?? "", "Jurisdiction": instance?.policy?.jurisdiction ?? "", "Third party data sharing": instance?.policy?.thirdPartyDataSharing ?? "", "Industry scope": instance?.policy?.industrySector ?? "", "Geographic restriction": instance?.policy?.geographicRestriction ?? "", "Retention period": instance?.policy?.dataRetentionPeriodDays ?? "", "Storage Location": instance?.policy?.storageLocation ?? ""]
DPIASectionDic = ["DPIA Date":instance?.dpiaDate ?? "", "DPIA Summary": instance?.dpiaSummaryURL ?? ""]
dataAgreementDic = [purposeSectionDic, policySectionDict, DPIASectionDic]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class BBConsentDataSharingVC: BBConsentBaseViewController, WebServiceTaskManager
// MARK: API Calls
func createRecordApiCall() {
self.addLoadingIndicator()
BBConsentBaseWebService.shared.makeAPICall(urlString: Constant.URLStrings.fetchDataAgreement + (dataAgreementId ?? ""), parameters: [:], method: .post) { success, resultVal in
BBConsentBaseWebService.shared.makeAPICall(urlString: Constant.URLStrings.fetchDataAgreementRecord + (dataAgreementId ?? ""), parameters: [:], method: .post) { success, resultVal in
if success {
debugPrint(resultVal)
self.sendDataBack?(resultVal)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class ViewController: UIViewController {

override func viewDidAppear(_ animated: Bool) {
// 1. For showing Privacy Dashboard
PrivacyDashboard.showPrivacyDashboard(withApiKey: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTY29wZXMiOlsic2VydmljZSJdLCJPcmdhbmlzYXRpb25JZCI6IjY1MjY1Nzk2OTM4MGYzNWZhMWMzMDI0NSIsIk9yZ2FuaXNhdGlvbkFkbWluSWQiOiI2NTI2NTc5NjkzODBmMzVmYTFjMzAyNDMiLCJleHAiOjE3MDA3MjkxOTF9.2rkHNiLDjQi8WOy4CWn96sMBx8KkvFCUMU0Xe6oXNbY",
withUserId: "65378403b3f442eb9381b38d",
withOrgId: "64f09f778e5f3800014a879a",
withBaseUrl: "https://staging-consent-bb-api.igrant.io/v2",
turnOnAskme: false,
turnOnUserRequest: false,
turnOnAttributeDetail: false)
// PrivacyDashboard.showPrivacyDashboard(withApiKey: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTY29wZXMiOlsic2VydmljZSJdLCJPcmdhbmlzYXRpb25JZCI6IjY1MjY1Nzk2OTM4MGYzNWZhMWMzMDI0NSIsIk9yZ2FuaXNhdGlvbkFkbWluSWQiOiI2NTI2NTc5NjkzODBmMzVmYTFjMzAyNDMiLCJleHAiOjE3MDA3MjkxOTF9.2rkHNiLDjQi8WOy4CWn96sMBx8KkvFCUMU0Xe6oXNbY",
// withUserId: "65378403b3f442eb9381b38d",
// withOrgId: "64f09f778e5f3800014a879a",
// withBaseUrl: "https://staging-consent-bb-api.igrant.io/v2",
// turnOnAskme: false,
// turnOnUserRequest: false,
// turnOnAttributeDetail: false)

// 2. For showing Data sharing UI
// PrivacyDashboard.showDataSharingUI(apiKey:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTY29wZXMiOlsic2VydmljZSJdLCJPcmdhbmlzYXRpb25JZCI6IjY1MjY1Nzk2OTM4MGYzNWZhMWMzMDI0NSIsIk9yZ2FuaXNhdGlvbkFkbWluSWQiOiI2NTI2NTc5NjkzODBmMzVmYTFjMzAyNDMiLCJleHAiOjE3MDA3MjkxOTF9.2rkHNiLDjQi8WOy4CWn96sMBx8KkvFCUMU0Xe6oXNbY",
Expand Down Expand Up @@ -58,6 +58,20 @@ class ViewController: UIViewController {
// 7. Open Data agreement policy UI
// PrivacyDashboard.showDataAgreementPolicy(dataAgreementRecord: dict)

// 8. Read data agreement
PrivacyDashboard.readDataAgreementApi(dataAgreementId: "65539173ed8be121fe2a59af") { success, resultVal in
print(resultVal)
let dict = resultVal["dataAgreement"] as? [String: Any]
if let theJSONData = try? JSONSerialization.data(withJSONObject: dict ?? [:], options: .prettyPrinted),
let theJSONText = String(data: theJSONData, encoding: String.Encoding.ascii) {
if let json = theJSONText.data(using: String.Encoding.utf8) {
if let jsonData = try? JSONSerialization.jsonObject(with: json, options: .allowFragments) as? [String:AnyObject] {
PrivacyDashboard.showDataAgreementPolicy(dataAgreementDic: jsonData)
}
}
}
}

// 8. Read data agreement
// PrivacyDashboard.readDataAgreementApi(dataAgreementId: "65535cad70eaa866249023d4") { success, resultVal in
// print(resultVal)
Expand Down

0 comments on commit 3d5fea7

Please sign in to comment.