From 447dcbe9d19837724446a9b9f397ee89ccac212c Mon Sep 17 00:00:00 2001 From: anvmn Date: Mon, 26 Feb 2024 23:15:14 +0200 Subject: [PATCH 1/6] Delete proprietary CSV files post import [ci skip] --- .ddev/config.local.yaml.example | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.ddev/config.local.yaml.example b/.ddev/config.local.yaml.example index 112025895a..dcfcf5b00a 100644 --- a/.ddev/config.local.yaml.example +++ b/.ddev/config.local.yaml.example @@ -50,4 +50,7 @@ hooks: - exec: drush mi --group=default --user=1 - exec: drush mi --group=counseling --user=1 - exec: drush mi --group=forms --user=1 + - exec: "cd .. && rm -f hedley/modules/custom/hedley_migrate/csv/health_center.csv" + - exec: "cd .. && rm -f hedley/modules/custom/hedley_migrate/csv/person.csv" + - exec: "cd .. && rm -f hedley/modules/custom/hedley_migrate/csv/village.csv" - exec: drush uli From 61740d3b334f347d17513dd3c53b605af8224ab7 Mon Sep 17 00:00:00 2001 From: anvmn Date: Wed, 28 Feb 2024 11:12:30 +0200 Subject: [PATCH 2/6] Introduce 'Aggregated NCDA viewer' role [ci skip] --- server/hedley/hedley.install | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/server/hedley/hedley.install b/server/hedley/hedley.install index f2e600d9a3..4ca1f9b879 100644 --- a/server/hedley/hedley.install +++ b/server/hedley/hedley.install @@ -224,7 +224,7 @@ function hedley_standard_install() { // Set this as the administrator role. variable_set('user_admin_role', $admin_role->rid); - // Creating a E-ledger viewer role and add the permissions. + // Creating a E-ledger viewer role. $ledger_viewer_role = new stdClass(); $ledger_viewer_role->name = 'E-ledger viewer'; user_role_save($ledger_viewer_role); @@ -234,6 +234,11 @@ function hedley_standard_install() { $nurse_role->name = 'nurse'; user_role_save($nurse_role); + // Creating an Aggregated NCDA viewer role. + $aggregated_ncda_viewer_role = new stdClass(); + $aggregated_ncda_viewer_role->name = 'Aggregated NCDA viewer'; + user_role_save($aggregated_ncda_viewer_role); + $permissions = []; $nurse_permitted_types = [ 'attendance', @@ -678,3 +683,12 @@ function hedley_update_7039() { variable_set('hedley_general_site_name', 'rwanda'); } } + +/** + * Create 'Aggregated NCDA viewer' role. + */ +function hedley_update_7040() { + $aggregated_ncda_viewer_role = new stdClass(); + $aggregated_ncda_viewer_role->name = 'Aggregated NCDA viewer'; + user_role_save($aggregated_ncda_viewer_role); +} \ No newline at end of file From c480dde61bea29c24d75960bd64bb40dd752d2ad Mon Sep 17 00:00:00 2001 From: anvmn Date: Wed, 28 Feb 2024 11:13:34 +0200 Subject: [PATCH 3/6] Grant access by role for NCDA report [ci skip] --- .../custom/hedley_ncda/hedley_ncda.module | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/server/hedley/modules/custom/hedley_ncda/hedley_ncda.module b/server/hedley/modules/custom/hedley_ncda/hedley_ncda.module index d08797b63d..ee2f9c09df 100644 --- a/server/hedley/modules/custom/hedley_ncda/hedley_ncda.module +++ b/server/hedley/modules/custom/hedley_ncda/hedley_ncda.module @@ -22,7 +22,7 @@ function hedley_ncda_menu() { 'title' => 'Aggregated NCDA scoreboard', 'description' => 'View Aggregated NCDA scoreboard', 'page callback' => 'hedley_ncda_aggregated_callback_menu', - 'access callback' => 'hedley_admin_administrators_access', + 'access callback' => 'hedley_ncda_aggregated_ncda_report_access', ); $items['admin/reports/aggregated-ncda/%/%'] = array( @@ -30,7 +30,7 @@ function hedley_ncda_menu() { 'description' => 'View Aggregated NCDA scoreboard for district', 'page callback' => 'hedley_ncda_aggregated_callback_district', 'page arguments' => [3, 4], - 'access callback' => 'hedley_admin_administrators_access', + 'access callback' => 'hedley_ncda_aggregated_ncda_report_access', ); $items['admin/reports/aggregated-ncda/%/%/%'] = array( @@ -38,7 +38,7 @@ function hedley_ncda_menu() { 'description' => 'View Aggregated NCDA scoreboard for sector', 'page callback' => 'hedley_ncda_aggregated_callback_sector', 'page arguments' => [3, 4, 5], - 'access callback' => 'hedley_admin_administrators_access', + 'access callback' => 'hedley_ncda_aggregated_ncda_report_access', ); $items['admin/reports/aggregated-ncda/%/%/%/%'] = array( @@ -46,7 +46,7 @@ function hedley_ncda_menu() { 'description' => 'View Aggregated NCDA scoreboard for cell', 'page callback' => 'hedley_ncda_aggregated_callback_cell', 'page arguments' => [3, 4, 5, 6], - 'access callback' => 'hedley_admin_administrators_access', + 'access callback' => 'hedley_ncda_aggregated_ncda_report_access', ); $items['admin/reports/aggregated-ncda/%/%/%/%/%'] = array( @@ -54,12 +54,24 @@ function hedley_ncda_menu() { 'description' => 'View Aggregated NCDA scoreboard for village', 'page callback' => 'hedley_ncda_aggregated_callback_village', 'page arguments' => [3, 4, 5, 6, 7], - 'access callback' => 'hedley_admin_administrators_access', + 'access callback' => 'hedley_ncda_aggregated_ncda_report_access', ); return $items; } +/** + * Grants access to Aggregated NCDA viewers, superuser and administrators. + * + * @return bool + * TRUE if the user has access, FALSE otherwise. + */ +function hedley_ncda_aggregated_ncda_report_access() { + $aggregated_ncda_viewer_role = user_role_load_by_name('Aggregated NCDA viewer'); + + return user_has_role($aggregated_ncda_viewer_role->rid) || hedley_admin_administrators_access(); +} + /** * Implements hook_node_insert(). */ From aadf21c31f6931fbaaa25b14fa4f9d02e21685c1 Mon Sep 17 00:00:00 2001 From: anvmn Date: Wed, 28 Feb 2024 11:13:55 +0200 Subject: [PATCH 4/6] Do not show E-Heza admin block for non admin users [ci skip] --- .../hedley/modules/custom/hedley_admin/hedley_admin.module | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/hedley/modules/custom/hedley_admin/hedley_admin.module b/server/hedley/modules/custom/hedley_admin/hedley_admin.module index 994c61be38..1e108f6e2a 100644 --- a/server/hedley/modules/custom/hedley_admin/hedley_admin.module +++ b/server/hedley/modules/custom/hedley_admin/hedley_admin.module @@ -140,6 +140,11 @@ function hedley_admin_block_view($delta) { return; } + if (!hedley_admin_administrators_access()) { + // Only administrators can view the block. + return; + } + $query = db_select('menu_links', 'm'); $query->fields('m', ['link_path', 'link_title', 'options']); $query->condition('menu_name', 'menu-eheza-app-admin-menu'); From 0281859452cb46d04f435d2211b6fb6c9d34acca Mon Sep 17 00:00:00 2001 From: anvmn Date: Wed, 28 Feb 2024 11:14:50 +0200 Subject: [PATCH 5/6] When Aggregated NCDA viewer users log in, redirect them to Aggregated NCDA report page --- .../hedley_patient/hedley_patient.module | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/server/hedley/modules/custom/hedley_patient/hedley_patient.module b/server/hedley/modules/custom/hedley_patient/hedley_patient.module index 1acc841b20..4f020f0592 100644 --- a/server/hedley/modules/custom/hedley_patient/hedley_patient.module +++ b/server/hedley/modules/custom/hedley_patient/hedley_patient.module @@ -34,6 +34,31 @@ function hedley_patient_menu() { return $items; } +/** + * Implements hook_user_login(). + * + * When Aggregated NCDA viewer users log in, redirect them + * to Aggregated NCDA report page. + */ +function hedley_patient_user_login(&$edit, $account) { + $aggregated_ncda_viewer_role = user_role_load_by_name('Aggregated NCDA viewer'); + if (!user_has_role($aggregated_ncda_viewer_role->rid, $account)) { + return; + } + + // Path of Aggregated NCDA report page. + $path = 'admin/reports/aggregated-ncda'; + // The 'Location' HTTP header must be absolute. + $options['absolute'] = TRUE; + $url = url($path, $options); + + header('Location: ' . $url, TRUE, 302); + // The "Location" header sends a redirect status code to the HTTP daemon. In + // some cases this can be wrong, so we make sure none other + // gets executed upon redirection. + drupal_exit($url); +} + /** * Implements hook_node_insert(). */ From 2ffdbb868427eb2eece0b60cd8d993445fa18272 Mon Sep 17 00:00:00 2001 From: anvmn Date: Wed, 28 Feb 2024 11:26:32 +0200 Subject: [PATCH 6/6] Rename role --- server/hedley/hedley.install | 18 +++++++++--------- .../custom/hedley_ncda/hedley_ncda.module | 4 ++-- .../hedley_patient/hedley_patient.module | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/server/hedley/hedley.install b/server/hedley/hedley.install index 4ca1f9b879..d5f76ecf3c 100644 --- a/server/hedley/hedley.install +++ b/server/hedley/hedley.install @@ -229,16 +229,16 @@ function hedley_standard_install() { $ledger_viewer_role->name = 'E-ledger viewer'; user_role_save($ledger_viewer_role); + // Creating a Data Manager role. + $data_manager_role = new stdClass(); + $data_manager_role->name = 'Data Manager'; + user_role_save($data_manager_role); + // Creating a Nurse role and add the permissions. $nurse_role = new stdClass(); $nurse_role->name = 'nurse'; user_role_save($nurse_role); - // Creating an Aggregated NCDA viewer role. - $aggregated_ncda_viewer_role = new stdClass(); - $aggregated_ncda_viewer_role->name = 'Aggregated NCDA viewer'; - user_role_save($aggregated_ncda_viewer_role); - $permissions = []; $nurse_permitted_types = [ 'attendance', @@ -685,10 +685,10 @@ function hedley_update_7039() { } /** - * Create 'Aggregated NCDA viewer' role. + * Create 'Data Manager' role. */ function hedley_update_7040() { - $aggregated_ncda_viewer_role = new stdClass(); - $aggregated_ncda_viewer_role->name = 'Aggregated NCDA viewer'; - user_role_save($aggregated_ncda_viewer_role); + $data_manager_role = new stdClass(); + $data_manager_role->name = 'Data Manager'; + user_role_save($data_manager_role); } \ No newline at end of file diff --git a/server/hedley/modules/custom/hedley_ncda/hedley_ncda.module b/server/hedley/modules/custom/hedley_ncda/hedley_ncda.module index ee2f9c09df..755b96c35b 100644 --- a/server/hedley/modules/custom/hedley_ncda/hedley_ncda.module +++ b/server/hedley/modules/custom/hedley_ncda/hedley_ncda.module @@ -67,9 +67,9 @@ function hedley_ncda_menu() { * TRUE if the user has access, FALSE otherwise. */ function hedley_ncda_aggregated_ncda_report_access() { - $aggregated_ncda_viewer_role = user_role_load_by_name('Aggregated NCDA viewer'); + $data_mananger_role = user_role_load_by_name('Data Manager'); - return user_has_role($aggregated_ncda_viewer_role->rid) || hedley_admin_administrators_access(); + return user_has_role($data_mananger_role->rid) || hedley_admin_administrators_access(); } /** diff --git a/server/hedley/modules/custom/hedley_patient/hedley_patient.module b/server/hedley/modules/custom/hedley_patient/hedley_patient.module index 4f020f0592..a5cbfbea90 100644 --- a/server/hedley/modules/custom/hedley_patient/hedley_patient.module +++ b/server/hedley/modules/custom/hedley_patient/hedley_patient.module @@ -37,12 +37,12 @@ function hedley_patient_menu() { /** * Implements hook_user_login(). * - * When Aggregated NCDA viewer users log in, redirect them + * When Data Manager users log in, redirect them * to Aggregated NCDA report page. */ function hedley_patient_user_login(&$edit, $account) { - $aggregated_ncda_viewer_role = user_role_load_by_name('Aggregated NCDA viewer'); - if (!user_has_role($aggregated_ncda_viewer_role->rid, $account)) { + $data_mananger_role = user_role_load_by_name('Data Manager'); + if (!user_has_role($data_mananger_role->rid, $account)) { return; }