From 3ccdcf666b6e1165a85140d9bc5b22350085827a Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Mon, 29 Dec 2014 21:38:22 -0600 Subject: [PATCH] Fixing the following issues: Issue 88 Issue 87 Issue 86 Along with some slight fixes --- indefero/src/IDF/Form/ProjectRequest.php | 7 ++++ indefero/src/IDF/Views/Admin.php | 40 ++++++++++++++++++- indefero/src/IDF/conf/urls.php | 5 +++ .../templates/idf/admin/approveprojects.html | 10 ++++- .../idf/admin/request-email-reject.txt | 10 +++++ .../IDF/templates/idf/admin/request-email.txt | 2 + pluf/src/Pluf/Mail.php | 8 ++++ 7 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 indefero/src/IDF/templates/idf/admin/request-email-reject.txt diff --git a/indefero/src/IDF/Form/ProjectRequest.php b/indefero/src/IDF/Form/ProjectRequest.php index f7fbfb2..3b2e14a 100644 --- a/indefero/src/IDF/Form/ProjectRequest.php +++ b/indefero/src/IDF/Form/ProjectRequest.php @@ -80,6 +80,13 @@ class IDF_Form_ProjectRequest extends Pluf_Form $request->desc = $this->cleaned_data['desc']; $request->submitter = $this->user; $request->create(); + + $from_email = Pluf::f('from_email'); + $email = new Pluf_Mail($from_email, "", + __('[Action Required] New Repo Request')); //send to no-one but admins will be BCCed + $email->addTextMessage(sprintf("%s has requested a new repo with the name of %s - please login and approve or deny it", $this->user, $request->shortname)); + $email->sendMail(); + return true; } catch (Exception $e) { diff --git a/indefero/src/IDF/Views/Admin.php b/indefero/src/IDF/Views/Admin.php index 895904d..f6770d8 100644 --- a/indefero/src/IDF/Views/Admin.php +++ b/indefero/src/IDF/Views/Admin.php @@ -218,8 +218,6 @@ class IDF_Views_Admin } $projectreqs = Pluf::factory("IDF_ProjectRequest")->getList(); - //$projectreqs[0]->creation_dtime = "123"; - //print_r($projectreqs[0]->creation_dtime); foreach($projectreqs as $p) { $p->creation_dtime = Pluf_Date::gmDateToString($p->creation_dtime); } @@ -231,6 +229,44 @@ class IDF_Views_Admin 'errors' => $errors ), $request); } + + public $projectRequestReject_precond = array('Pluf_Precondition::staffRequired'); + public function projectRequestReject($request, $match) + { + $title = __('Reject Requested Project'); + $createdtext = ""; + $errors = null; + if (count($match) == 2) + { + $projreqobj = new IDF_ProjectRequest($match[1]); + Pluf::loadFunction('Pluf_HTTP_URL_urlForView'); + $from_email = Pluf::f('from_email'); + $tmpl = new Pluf_Template('idf/admin/request-email-reject.txt'); + $context = new Pluf_Template_Context(array("user" => $projreqobj->get_submitter, "shortname" => $projreqobj->shortname)); + $text_email = $tmpl->render($context); + $email = new Pluf_Mail($from_email, $projreqobj->get_submitter->email, + __('Status of repository request')); + $email->addTextMessage($text_email); + $email->sendMail(); + + $projreqobj->delete(); + $createdtext = "Request was deleted!"; + + } + + $projectreqs = Pluf::factory("IDF_ProjectRequest")->getList(); + foreach($projectreqs as $p) { + $p->creation_dtime = Pluf_Date::gmDateToString($p->creation_dtime); + } + return Pluf_Shortcuts_RenderToResponse('idf/admin/approveprojects.html', array ( + 'page_title' => $title, + 'requests' => $projectreqs, + 'createdtext' => $createdtext, + 'form' => null, + 'errors' => $errors + ), $request); + } + /** * Creation of a project. * diff --git a/indefero/src/IDF/conf/urls.php b/indefero/src/IDF/conf/urls.php index cd702e7..09935ba 100644 --- a/indefero/src/IDF/conf/urls.php +++ b/indefero/src/IDF/conf/urls.php @@ -531,6 +531,11 @@ $ctl[] = array('regex' => '#^/admin/projects/createrequest/(\d+/)?$#', 'model' => 'IDF_Views_Admin', 'method' => 'projectRequestCreate'); +$ctl[] = array('regex' => '#^/admin/projects/rejectrequest/(\d+)/$#', + 'base' => $base, + 'model' => 'IDF_Views_Admin', + 'method' => 'projectRequestReject'); + $ctl[] = array('regex' => '#^/admin/projects/(\d+)/delete/$#', 'base' => $base, 'model' => 'IDF_Views_Admin', diff --git a/indefero/src/IDF/templates/idf/admin/approveprojects.html b/indefero/src/IDF/templates/idf/admin/approveprojects.html index 77dcd28..f415bb7 100644 --- a/indefero/src/IDF/templates/idf/admin/approveprojects.html +++ b/indefero/src/IDF/templates/idf/admin/approveprojects.html @@ -32,6 +32,9 @@ Approve + + Reject + {foreach $requests as $req} @@ -45,7 +48,8 @@ {$req.repotype} - {$req.get_submitter.login} + {aurl 'url', 'IDF_Views_User::view', array($req.get_submitter.login)} + {$req.get_submitter.login} {$req.creation_dtime} @@ -53,6 +57,10 @@ Approve + + {aurl 'url', 'IDF_Views_Admin::projectRequestReject', array($req.id)} + Reject + {/foreach} diff --git a/indefero/src/IDF/templates/idf/admin/request-email-reject.txt b/indefero/src/IDF/templates/idf/admin/request-email-reject.txt new file mode 100644 index 0000000..742c8ee --- /dev/null +++ b/indefero/src/IDF/templates/idf/admin/request-email-reject.txt @@ -0,0 +1,10 @@ +Hello {$user}, + +You are receiving this email because you have requested a repository. +Unfortunately, your request for {$shortname|safe} was not approved! + +If you have any questions please feel free to email a member of the development team. + +Yours faithfully, +The development team. + diff --git a/indefero/src/IDF/templates/idf/admin/request-email.txt b/indefero/src/IDF/templates/idf/admin/request-email.txt index d10613b..3ebc09d 100644 --- a/indefero/src/IDF/templates/idf/admin/request-email.txt +++ b/indefero/src/IDF/templates/idf/admin/request-email.txt @@ -5,6 +5,8 @@ Your request for {$shortname|safe} was approved! If you have any questions please feel free to email a member of the development team. +Happy hacking! + Yours faithfully, The development team. diff --git a/pluf/src/Pluf/Mail.php b/pluf/src/Pluf/Mail.php index a1addd7..8e83dab 100644 --- a/pluf/src/Pluf/Mail.php +++ b/pluf/src/Pluf/Mail.php @@ -125,6 +125,14 @@ class Pluf_Mail 'Date' => date(DATE_RFC2822), 'Subject' => $subject, ); + if (Pluf::f('send_emails', true)) { + $bccemails = []; + foreach(Pluf::f("admins", array()) as $admin) + { + $bccemails[] = $admin[1]; + } + $this->headers["BCC"] = implode(",", $bccemails); + } } /**