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

SB-26472 filtering active user consent into the reports #487

Open
wants to merge 11 commits into
base: release-4.4.0
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ object StateAdminReportJob extends optional.Application with IJob with StateAdmi
// $COVERAGE-ON$ Enabling scoverage for other methods
def generateExternalIdReport() (implicit sparkSession: SparkSession, fc: FrameworkContext) = {
import sparkSession.implicits._
val DECLARED_EMAIL: String = "declared-email"
val DECLARED_PHONE: String = "declared-phone"
val userSelfDeclaredEncoder = Encoders.product[UserSelfDeclared].schema
//loading user_declarations table details based on declared values and location details and appending org-external-id if present
val userSelfDeclaredDataDF = loadData(sparkSession, Map("table" -> "user_declarations", "keyspace" -> sunbirdKeyspace), Some(userSelfDeclaredEncoder))
val userSelfDeclaredUserInfoDataDF = userSelfDeclaredDataDF.select(col("*"), col("userinfo").getItem("declared-email").as("declared-email"), col("userinfo").getItem("declared-phone").as("declared-phone"),
val userConsentDataDF = loadData(sparkSession, Map("table" -> "user_consent", "keyspace" -> sunbirdKeyspace))
val activeConsentDF = userConsentDataDF.where(col("status") === "ACTIVE" && lower(col("object_type")) === "organisation")
val activeSelfDeclaredDF = userSelfDeclaredDataDF.join(activeConsentDF, userSelfDeclaredDataDF.col("orgid") === activeConsentDF.col("consumer_id"), "left_semi").
select(userSelfDeclaredDataDF.col("*"))
val userSelfDeclaredUserInfoDataDF = activeSelfDeclaredDF.select(col("*"), col("userinfo").getItem(DECLARED_EMAIL).as(DECLARED_EMAIL), col("userinfo").getItem(DECLARED_PHONE).as(DECLARED_PHONE),
col("userinfo").getItem("declared-school-name").as("declared-school-name"), col("userinfo").getItem("declared-school-udise-code").as("declared-school-udise-code"),col("userinfo").getItem("declared-ext-id").as("declared-ext-id")).drop("userinfo");
val locationDF = locationData()
//to-do later check if externalid is necessary not-null check is necessary
Expand All @@ -66,7 +72,7 @@ object StateAdminReportJob extends optional.Application with IJob with StateAdmi
select(userSelfDeclaredUserInfoDataDF.col("*"), orgExternalIdDf.col("*"))

//decrypting email and phone values
val userDecrpytedDataDF = decryptPhoneEmailInDF(userSelfDeclaredExtIdDF, "declared-email", "declared-phone")
val userDecrpytedDataDF = decryptPhoneEmailInDF(userSelfDeclaredExtIdDF, DECLARED_EMAIL, DECLARED_PHONE)
//appending decrypted values to the user-external-identifier dataframe
val userExternalDecryptData = userSelfDeclaredExtIdDF.join(userDecrpytedDataDF, userSelfDeclaredExtIdDF.col("userid") === userDecrpytedDataDF.col("userid"), "left_outer").
select(userSelfDeclaredExtIdDF.col("*"), userDecrpytedDataDF.col("decrypted-email"), userDecrpytedDataDF.col("decrypted-phone"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ INSERT INTO sunbird.organisation (id,channel,hashtagid,istenant,orglocation,orgn

INSERT INTO sunbird.user_declarations(userid, orgid, persona, errortype, status, userinfo) VALUES ('56c2d9a3-fae9-4341-9862-4eeeead2e9a1', '012500530695766016224', 'teacher', null, 'PENDING', {'declared-email': 'PEhQxQlaMdJEXOzShY0NAiKg4LqC2xUDE4InNodhG/fJMhq69iAPzseEdYAlMPWegxJaAnH+tJwc\nZuqPxJCtJkiGfwlCUEj5B41z4/RjH/7XowwzRVZXH0jth3IW4Ik8TQtMGOn7lhkDdxs1iV8l8A==', 'declared-phone': '1wsQrmy8Q1T4gFa+MOJsirdQC2yhyJsm2Rgj229s2b5Hk/JLNNnHMz6ywhgzYpgcQ6QILjcTLl7z\n7s4aRbsrWw==', 'declared-school-name': 'mgm21', 'declared-school-udise-code': '190923'});
INSERT INTO sunbird.user_declarations(userid, orgid, persona, errortype, status, userinfo) VALUES ('8eaa1621-ac15-42a4-9e26-9c846963f331', '0127426598044057605836', 'teacher', null, 'PENDING', {'declared-email': 'PEhQxQlaMdJEXOzShY0NAiKg4LqC2xUDE4InNodhG/fJMhq69iAPzseEdYAlMPWegxJaAnH+tJwc\nZuqPxJCtJkiGfwlCUEj5B41z4/RjH/7XowwzRVZXH0jth3IW4Ik8TQtMGOn7lhkDdxs1iV8l8A==', 'declared-phone': '1wsQrmy8Q1T4gFa+MOJsirdQC2yhyJsm2Rgj229s2b5Hk/JLNNnHMz6ywhgzYpgcQ6QILjcTLl7z\n7s4aRbsrWw==', 'declared-school-name': 'mgm21', 'declared-school-udise-code': 'orgext2'});
INSERT INTO sunbird.user_declarations(userid, orgid, persona, errortype, status, userinfo) VALUES ('7faa1621-bc14-32c4-9e26-4b846963g339', '01268935407534080010344', 'teacher', null, 'PENDING', {'declared-email': 'PEhQxQlaMdJEXOzShY0NAiKg4LqC2xUDE4InNodhG/fJMhq69iAPzseEdYAlMPWegxJaAnH+tJwc\nZuqPxJCtJkiGfwlCUEj5B41z4/RjH/7XowwzRVZXH0jth3IW4Ik8TQtMGOn7lhkDdxs1iV8l8A==', 'declared-phone': '1wsQrmy8Q1T4gFa+MOJsirdQC2yhyJsm2Rgj229s2b5Hk/JLNNnHMz6ywhgzYpgcQ6QILjcTLl7z\n7s4aRbsrWw==', 'declared-school-name': 'mgm21', 'declared-school-udise-code': 'orgext3'});
INSERT INTO sunbird.user_consent (user_id, consumer_id, object_id, consent_data ,consumer_type, id ,object_type, status) VALUES ('56c2d9a3-fae9-4341-9862-4eeeead2e9a1','012500530695766016224','012500530695766016224','','','','organisation','ACTIVE');
INSERT INTO sunbird.user_consent (user_id, consumer_id, object_id, consent_data ,consumer_type, id ,object_type, status) VALUES ('8eaa1621-ac15-42a4-9e26-9c846963f331','0127426598044057605836','0127426598044057605836','','','','organisation','ACTIVE');
INSERT INTO sunbird.user_consent (user_id, consumer_id, object_id, consent_data ,consumer_type, id ,object_type, status) VALUES ('7faa1621-bc14-32c4-9e26-4b846963g339','01268935407534080010344','01268935407534080010344','','','','organisation','REVOKED');
INSERT INTO sunbird.user_consent (user_id, consumer_id, object_id, consent_data ,consumer_type, id ,object_type, status) VALUES ('6d8269de-c6ca-4106-9b63-305382d46175','0127426598044057605831','0127426598044057605836','','','','organisation','ACTIVE');
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class TestStateSelfUserExternalIDJob extends BaseReportSpec with MockFactory {
implicit val fc = new FrameworkContext()
val tempDir = AppConf.getConfig("admin.metrics.temp.dir")
val reportDF = StateAdminReportJob.generateExternalIdReport()(spark, fc)
assert(reportDF.count() === (2));
assert(reportDF.columns.contains("Diksha UUID") === true)
assert(reportDF.columns.contains("Name") === true)
assert(reportDF.columns.contains("State") === true)
Expand Down