added a new configuration item 'email_sender'

enhanced the code review controller to send a email when a new review message is inserted
This commit is contained in:
hyung-hwan 2015-08-12 14:11:59 +00:00
parent 65d86d4ce6
commit 37da83d444
6 changed files with 70 additions and 7 deletions

View File

@ -252,6 +252,11 @@ cloc_command_path = "@CFGDIR@/cloc.pl"
;------------------------------------------------------------------------------
code_folder_readme = "README.wiki,README.txt,README"
;------------------------------------------------------------------------------
; Email address to use when sending notification emails
;------------------------------------------------------------------------------
email_sender = ""
;------------------------------------------------------------------------------
; Codepot sets this revision property to assign a tag to a specific revision.
;------------------------------------------------------------------------------
@ -287,3 +292,4 @@ svn_restriction_allowed_subdir_depth_max = "0"
; Set it to an empty string to allow all users.
;------------------------------------------------------------------------------
codepot_user_executor = "root"

View File

@ -553,7 +553,8 @@ class Code extends Controller
if ($this->form_validation->run())
{
$review_comment = $this->input->post('new_review_comment');
if ($this->code_review->insertReview ($projectid, $rev, $login['id'], $review_comment) === FALSE)
$review_sno = $this->code_review->insertReview ($projectid, $rev, $login['id'], $review_comment);
if ($review_sno === FALSE)
{
$data['popup_error_message'] = 'Cannot add code review comment';
}
@ -561,6 +562,13 @@ class Code extends Controller
{
// this is a hack to clear form data upon success
$this->form_validation->_field_data = array();
// TODO: message localization
$email_subject = sprintf ('New review message #%d by %s in %s', $review_sno, $login['id'], $projectid);
$email_message = 'See ' . current_url();
$this->projects->emailMessageToMembers (
$projectid, $this->login, $email_subject, $email_message
);
}
}
else

View File

@ -72,8 +72,7 @@ class DbLoginModel extends LoginModel
function changePassword ($userid, $passwd)
{
$this->db->trans_start ();
$this->db->trans_complete ();
$this->db->trans_begin ();
$this->db->where ('userid', $userid);
$this->db->set ('passwd', format_password($passwd,5));
@ -91,8 +90,28 @@ class DbLoginModel extends LoginModel
function queryUserInfo ($userid)
{
$this->db->trans_start ();
$this->db->select ('email');
$this->db->where ('userid', $userid);
$query = $this->db->get ('user_account');
if ($this->db->trans_status() == FALSE)
{
$this->db->trans_complete ();
return FALSE;
}
$result = $query->result ();
if (empty($result))
{
$this->db->trans_complete ();
return FALSE;
}
$user['id'] = $userid;
$user['email'] = '';
$user['email'] = $result[0]->email;
return $user;
}
}

View File

@ -110,8 +110,9 @@ class LdapLoginModel extends LoginModel
function queryUserInfo ($userid)
{
$ldap = @ldap_connect (
CODEPOT_LDAP_SERVER_HOST, CODEPOT_LDAP_SERVER_PORT);
//$ldap = @ldap_connect (
// CODEPOT_LDAP_SERVER_HOST, CODEPOT_LDAP_SERVER_PORT);
$ldap = @ldap_connect (CODEPOT_LDAP_SERVER_URI);
if ($ldap === FALSE)
{
$this->setErrorMessage ("Can't connect to LDAP server");

View File

@ -559,6 +559,34 @@ class ProjectModel extends Model
return $out;
}
function emailMessageToMembers ($projectid, $login_model, $subject, $message)
{
$this->db->trans_start ();
$this->db->select ('userid');
$this->db->where ('projectid', $projectid);
$query = $this->db->get ('project_membership');
$this->db->trans_complete ();
if ($this->db->trans_status() === FALSE) return FALSE;
$recipients = '';
foreach ($query->result() as $v)
{
$m = $login_model->queryUserInfo ($v->userid);
if ($m !== FALSE && $m['email'] != '')
{
if (!empty($recipients)) $recipients .= ', ';
$recipients .= $m['email'];
}
}
$additional_headers = '';
if (CODEPOT_EMAIL_SENDER != '') $additional_headers .= 'From: ' . CODEPOT_EMAIL_SENDER . "\r\n";
if (empty($recipients)) return FALSE;
mail ($recipients, $subject, wordwrap($message, 70, "\r\n"), $additional_headers);
return TRUE;
}
}
?>

View File

@ -84,8 +84,9 @@ function load_ini ($file)
array ('footer', 'string', ''),
array ('cloc_command_path', 'string', CODEPOT_CFG_DIR.'/cloc.pl'),
array ('code_folder_readme', 'string', 'README'),
array ('svn_tag_property', 'string', 'codepot:tag'),
array ('email_sender', 'string', ''),
array ('svn_tag_property', 'string', 'codepot:tag'),
// these items are not used by php but by subersion hooks written in perl.
array ('svn_read_access', 'string', 'member'),