From 00c0eea9e880019ab8d775584dfc9588df46604e Mon Sep 17 00:00:00 2001 From: Tristan Olive Date: Thu, 2 Jul 2015 02:12:50 -0400 Subject: [PATCH] Added support for team_email_list.php RPC (uses info from Drupal and BOINC databases, but no pass-through to BOINC RPC) (DBOINCP-184) --- .../boinc/modules/boinccore/boinccore.module | 83 +++++++++++++++++++ .../boinc/modules/boincuser/boincuser.module | 2 + 2 files changed, 85 insertions(+) diff --git a/drupal/sites/default/boinc/modules/boinccore/boinccore.module b/drupal/sites/default/boinc/modules/boinccore/boinccore.module index 8e976d1b1d..4ca1a54e72 100644 --- a/drupal/sites/default/boinc/modules/boinccore/boinccore.module +++ b/drupal/sites/default/boinc/modules/boinccore/boinccore.module @@ -106,6 +106,13 @@ function boinccore_menu() { 'access callback' => TRUE, 'type' => MENU_CALLBACK ); + $items['team_email_list.php'] = array( + 'title' => 'Get team member list RPC', + 'description' => 'RPC for getting a list of members of a given team.', + 'page callback' => 'boinccore_team_email_list', + 'access callback' => TRUE, + 'type' => MENU_CALLBACK + ); $items['forum_get_data.php'] = array( 'title' => 'Forum get data RPC', 'description' => 'RPC for getting recent forum activity for a given user.', @@ -623,6 +630,82 @@ function boinccore_pending_credit() { include_boinc('user/pending.php'); } +/** + * Page callback for the team email list RPC (team_email_list.php). + * Get members of a given team + */ +function boinccore_team_email_list() { + // See if the account has an approved profile in Drupal + $boincteam_id = !empty($_POST['teamid']) ? $_POST['teamid'] : $_GET['teamid']; + $account_key = !empty($_POST['account_key']) ? $_POST['account_key'] : $_GET['account_key']; + $show_xml = !empty($_POST['xml']) ? $_POST['xml'] : $_GET['xml']; + $admin_request = FALSE; + if ($boincteam_id) { + if ($account_key) { + // See if this is a team admin + db_set_active('boinc'); + $boincuser_id = db_result(db_query(" + SELECT + u.id + FROM {user} u + WHERE u.authenticator = '%s' + LIMIT 1", + $account_key + )); + db_set_active('default'); + require_boinc('team'); + $boincuser = boincuser_load(boincuser_lookup_uid($boincuser_id), TRUE); + $boincteam = boincteam_load($boincteam_id); + $admin_request = is_team_admin($boincuser, $boincteam) OR is_team_founder($boincuser, $boincteam); + } + $members = array(); + db_set_active('boinc'); + $result = db_query(" + SELECT + u.name, u.email_addr + FROM {user} u + WHERE u.teamid = %d + ORDER BY u.email_addr ASC", + $boincteam_id + ); + db_set_active('default'); + + while ($member = db_fetch_object($result)) { + $members[] = user_load(array('mail' => $member->email_addr)); + } + + $xml = array('users' => array()); + foreach ($members as $member) { + $content_profile = content_profile_load('profile', $member->uid); + $team_member = array( + 'id' => $member->boincuser_id, + 'cpid' => $member->boincuser_cpid, + 'create_time' => $member->created, + 'name' => $member->boincuser_name, + 'country' => $content_profile->field_country[0]['value'], + 'total_credit' => $member->boincuser_total_credit, + 'expavg_credit' => $member->boincuser_expavg_credit, + 'expavg_time' => $member->boincuser_expavg_time, + 'url' => $content_profile->field_url[0]['value'], + 'has_profile' => ($content_profile->status AND !$content_profile->moderate) ? 1 : 0, + ); + if ($admin_request) { + $team_member['email_addr'] = $member->mail; + } + $xml['users']['user'][] = $team_member; + } + } + else { + $xml = array( + 'error' => array( + 'error_num' => -136, + 'error_msg' => 'Not found', + ), + ); + } + print xml_to_text(array_to_xml($xml), TRUE, TRUE); +} + /** * Page callback for the user forum activity RPC (forum_get_data.php). * Get the last comments OR threads made by a given user diff --git a/drupal/sites/default/boinc/modules/boincuser/boincuser.module b/drupal/sites/default/boinc/modules/boincuser/boincuser.module index 644a821a70..874b87bbf4 100644 --- a/drupal/sites/default/boinc/modules/boincuser/boincuser.module +++ b/drupal/sites/default/boinc/modules/boincuser/boincuser.module @@ -189,6 +189,7 @@ function boincuser_user($op, &$edit, &$account, $category = NULL) { passwd_hash, total_credit, expavg_credit, + expavg_time, cross_project_id, teamid, venue @@ -201,6 +202,7 @@ function boincuser_user($op, &$edit, &$account, $category = NULL) { $account->boincuser_weak_auth = md5($boinc_user->authenticator . $boinc_user->passwd_hash); $account->boincuser_total_credit = round($boinc_user->total_credit); $account->boincuser_expavg_credit = round($boinc_user->expavg_credit); + $account->boincuser_expavg_time = round($boinc_user->expavg_time); $account->boincuser_cpid = md5($boinc_user->cross_project_id . $account->mail); $account->boincuser_default_pref_set = $boinc_user->venue; $account->boincteam_id = $boinc_user->teamid;