diff --git a/codepot/etc/codepot.ini.in b/codepot/etc/codepot.ini.in index d19f75db..09f4b845 100644 --- a/codepot/etc/codepot.ini.in +++ b/codepot/etc/codepot.ini.in @@ -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" + diff --git a/codepot/src/codepot/controllers/code.php b/codepot/src/codepot/controllers/code.php index 9b71172e..5d5f0821 100644 --- a/codepot/src/codepot/controllers/code.php +++ b/codepot/src/codepot/controllers/code.php @@ -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 diff --git a/codepot/src/codepot/models/dbloginmodel.php b/codepot/src/codepot/models/dbloginmodel.php index 465eb445..8d5837a6 100644 --- a/codepot/src/codepot/models/dbloginmodel.php +++ b/codepot/src/codepot/models/dbloginmodel.php @@ -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; } } diff --git a/codepot/src/codepot/models/ldaploginmodel.php b/codepot/src/codepot/models/ldaploginmodel.php index c5f875a9..898fb0f5 100644 --- a/codepot/src/codepot/models/ldaploginmodel.php +++ b/codepot/src/codepot/models/ldaploginmodel.php @@ -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"); diff --git a/codepot/src/codepot/models/projectmodel.php b/codepot/src/codepot/models/projectmodel.php index db95fcc0..17401377 100644 --- a/codepot/src/codepot/models/projectmodel.php +++ b/codepot/src/codepot/models/projectmodel.php @@ -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; + } } ?> diff --git a/codepot/src/config.php.in b/codepot/src/config.php.in index b92329c7..af4d2c88 100644 --- a/codepot/src/config.php.in +++ b/codepot/src/config.php.in @@ -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'),