diff --git a/src/IDF/Form/Admin/ProjectCreate.php b/src/IDF/Form/Admin/ProjectCreate.php index 0c7aec2..3af968b 100644 --- a/src/IDF/Form/Admin/ProjectCreate.php +++ b/src/IDF/Form/Admin/ProjectCreate.php @@ -133,6 +133,16 @@ class IDF_Form_Admin_ProjectCreate extends Pluf_Form 'IDF_Form_Admin_ProjectCreate', $params); } + public function clean_owners() + { + return IDF_Form_MembersConf::checkBadLogins($this->cleaned_data['owners']); + } + + public function clean_members() + { + return IDF_Form_MembersConf::checkBadLogins($this->cleaned_data['members']); + } + public function clean_svn_remote_url() { $this->cleaned_data['svn_remote_url'] = (!empty($this->cleaned_data['svn_remote_url'])) ? $this->cleaned_data['svn_remote_url'] : ''; diff --git a/src/IDF/Form/Admin/ProjectUpdate.php b/src/IDF/Form/Admin/ProjectUpdate.php index 30cc4cb..cd9995e 100644 --- a/src/IDF/Form/Admin/ProjectUpdate.php +++ b/src/IDF/Form/Admin/ProjectUpdate.php @@ -61,6 +61,16 @@ class IDF_Form_Admin_ProjectUpdate extends Pluf_Form )); } + public function clean_owners() + { + return IDF_Form_MembersConf::checkBadLogins($this->cleaned_data['owners']); + } + + public function clean_members() + { + return IDF_Form_MembersConf::checkBadLogins($this->cleaned_data['members']); + } + public function save($commit=true) { if (!$this->isValid()) { diff --git a/src/IDF/Form/MembersConf.php b/src/IDF/Form/MembersConf.php index 35c0413..69552b3 100644 --- a/src/IDF/Form/MembersConf.php +++ b/src/IDF/Form/MembersConf.php @@ -67,6 +67,46 @@ class IDF_Form_MembersConf extends Pluf_Form $this->project->membershipsUpdated(); } + public function clean_owners() + { + return self::checkBadLogins($this->cleaned_data['owners']); + } + + public function clean_members() + { + return self::checkBadLogins($this->cleaned_data['members']); + } + + /** + * From the input, find the bad logins. + * + * Throw a Pluf_Form_Invalid exception when bad logins are found. + * + * @param string Comma, new line delimited list of logins + * @return string Comma, new line delimited list of logins + */ + public static function checkBadLogins($logins) + { + $bad = array(); + foreach (preg_split("/\015\012|\015|\012|\,/", $logins, -1, PREG_SPLIT_NO_EMPTY) as $login) { + $sql = new Pluf_SQL('login=%s', array(trim($login))); + try { + $user = Pluf::factory('Pluf_User')->getOne(array('filter'=>$sql->gen())); + if (null == $user) { + $bad[] = $login; + } + } catch (Exception $e) { + $bad[] = $login; + } + } + $n = count($bad); + if ($n) { + $badlogins = Pluf_esc(implode(', ', $bad)); + throw new Pluf_Form_Invalid(sprintf(_n('The following login is invalid: %s.', 'The following login are invalids: %s.', $n), $badlogins)); + } + return $logins; + } + /** * The update of the memberships is done in different places. This * avoids duplicating code. diff --git a/src/IDF/Form/TabsConf.php b/src/IDF/Form/TabsConf.php index 9b4eb30..a9087c9 100644 --- a/src/IDF/Form/TabsConf.php +++ b/src/IDF/Form/TabsConf.php @@ -86,6 +86,11 @@ class IDF_Form_TabsConf extends Pluf_Form )); } + public function clean_authorized_users() + { + return IDF_Form_MembersConf::checkBadLogins($this->cleaned_data['authorized_users']); + } + public function save($commit=true) { if (!$this->isValid()) {