Esempio n. 1
0
 public function userUpdate($request, $match)
 {
     $user = Pluf_Shortcuts_GetObjectOr404('Pluf_User', $match[1]);
     $title = sprintf(__('Update %s'), $user->__toString());
     $params = array('user' => $user, 'request' => $request);
     // Check the rights.
     $url = Pluf_HTTP_URL_urlForView('IDF_Views_Admin::users');
     $error = __('You do not have the rights to update this user.');
     if ($user->administrator and $request->user->id != $user->id) {
         $request->user->setMessage($error);
         return new Pluf_HTTP_Response_Redirect($url);
     }
     if ($user->staff) {
         if (!$request->user->administrator and $request->user->id != $user->id) {
             $request->user->setMessage($error);
             return new Pluf_HTTP_Response_Redirect($url);
         }
     }
     if ($request->method == 'POST') {
         $form = new IDF_Form_Admin_UserUpdate(array_merge($request->POST, $request->FILES), $params);
         if ($form->isValid()) {
             $form->save();
             $request->user->setMessage(__('The user has been updated.'));
             return new Pluf_HTTP_Response_Redirect($url);
         }
     } else {
         $form = new IDF_Form_Admin_UserUpdate(null, $params);
     }
     return Pluf_Shortcuts_RenderToResponse('idf/gadmin/users/update.html', array('page_title' => $title, 'cuser' => $user, 'form' => $form), $request);
 }
Esempio n. 2
0
 public function deleteKey($request, $match)
 {
     $url = Pluf_HTTP_URL_urlForView('IDF_Views_User::myAccount');
     if ($request->method == 'POST') {
         $key = Pluf_Shortcuts_GetObjectOr404('IDF_Key', $match[1]);
         if ($key->user != $request->user->id) {
             return new Pluf_HTTP_Response_Forbidden($request);
         }
         $key->delete();
         $request->user->setMessage(__('The public key has been deleted.'));
     }
     return new Pluf_HTTP_Response_Redirect($url);
 }
Esempio n. 3
0
 public function star($request, $match)
 {
     $prj = $request->project;
     $issue = Pluf_Shortcuts_GetObjectOr404('IDF_Issue', $match[2]);
     $prj->inOr404($issue);
     if ($request->method == 'POST') {
         $starred = Pluf_Model_InArray($request->user, $issue->get_interested_list());
         if ($starred) {
             $issue->delAssoc($request->user);
             $request->user->setMessage(__('The issue has been removed from your watch list.'));
         } else {
             $issue->setAssoc($request->user);
             $request->user->setMessage(__('The issue has been added to your watch list.'));
         }
     }
     $url = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view', array($prj->shortname, $issue->id));
     return new Pluf_HTTP_Response_Redirect($url);
 }
Esempio n. 4
0
 /**
  * Delete an object (Part of the CRUD series).
  *
  * The minimal extra parameter is the model class name. The list
  * of extra parameters is:
  *
  * 'model' - Class name string, required.
  *
  * 'post_delete_redirect' - View to redirect after saving, required.
  *
  * 'id' - Index in the match to fin the id of the object to delete (1)
  * 
  * 'login_required' - Do we require login (false)
  *
  * 'template' - Template to use ('"model class"_confirm_delete.html')
  *
  * 'post_delete_redirect_keys' - Which keys of the model to pass to
  *                             the view (array())
  *
  * 'extra_context' - Array of key/values to be added to the
  *                   context (array())
  * 
  * @param Pluf_HTTP_Request Request object
  * @param array Match
  * @param array Extra parameters
  * @return Pluf_HTTP_Response Response object (can be a redirect)
  */
 public function deleteObject($request, $match, $p)
 {
     if (isset($p['login_required']) && true == $p['login_required']) {
         if ($request->user->isAnonymous()) {
             return new Pluf_HTTP_Response_RedirectToLogin($request);
         }
     }
     if (!isset($p['model'])) {
         throw new Exception('The model class was not provided in the parameters.');
     }
     // Set the default
     $id = isset($p['id']) ? $match[$p['id']] : $match[1];
     $model = $p['model'];
     $context = isset($p['extra_context']) ? $p['extra_context'] : array();
     $template = isset($p['template']) ? $p['template'] : strtolower($model) . '_confirm_delete.html';
     $post_delete_keys = isset($p['post_delete_redirect_keys']) ? $p['post_delete_redirect_keys'] : array();
     $object = Pluf_Shortcuts_GetObjectOr404($model, $id);
     if ($request->method == 'POST') {
         $object->delete();
         if (isset($p['post_delete_redirect'])) {
             $url = Pluf_HTTP_URL_urlForView($p['post_delete_redirect'], $post_delete_keys);
         } else {
             throw new Exception('No URL to redirect to from generic delete view.');
         }
         if (!$request->user->isAnonymous()) {
             $request->user->setMessage(sprintf(__('The %s was deleted successfully.'), $object->_a['verbose']));
         }
         return new Pluf_HTTP_Response_Redirect($url);
     }
     return Pluf_Shortcuts_RenderToResponse($template, array_merge($context, array('object' => $object)), $request);
 }
Esempio n. 5
0
 public function view($request, $match)
 {
     $prj = $request->project;
     $review = Pluf_Shortcuts_GetObjectOr404('IDF_Review', $match[2]);
     $prj->inOr404($review);
     $url = Pluf_HTTP_URL_urlForView('IDF_Views_Review::view', array($prj->shortname, $review->id));
     $title = Pluf_Template::markSafe(sprintf(__('Review <a href="%s">%d</a>: %s'), $url, $review->id, $review->summary));
     $patches = $review->get_patches_list();
     $patch = $patches[0];
     $diff = new IDF_Diff(file_get_contents(Pluf::f('upload_issue_path') . '/' . $patch->patch));
     $diff->parse();
     // The form to submit comments is based on the files in the
     // diff
     if ($request->method == 'POST' and !$request->user->isAnonymous()) {
         $form = new IDF_Form_ReviewFileComment($request->POST, array('files' => $diff->files, 'user' => $request->user, 'patch' => $patch, 'project' => $prj));
         if ($form->isValid()) {
             $review_comment = $form->save();
             $review = $patch->get_review();
             $urlr = Pluf_HTTP_URL_urlForView('IDF_Views_Review::view', array($prj->shortname, $review->id));
             $request->user->setMessage(sprintf(__('Your <a href="%s">code review %d</a> has been published.'), $urlr, $review->id));
             $url = Pluf_HTTP_URL_urlForView('IDF_Views_Review::index', array($prj->shortname));
             $review_comment->notify($request->conf);
             return new Pluf_HTTP_Response_Redirect($url);
         }
     } else {
         $form = new IDF_Form_ReviewFileComment(null, array('files' => $diff->files, 'user' => $request->user, 'project' => $prj, 'patch' => $patch));
     }
     $scm = IDF_Scm::get($request->project);
     $files = array();
     $reviewers = array();
     foreach ($diff->files as $filename => $def) {
         $fileinfo = $scm->getPathInfo($filename, $patch->get_commit()->scm_id);
         $sql = new Pluf_SQL('cfile=%s', array($filename));
         $cts = $patch->getFileComments(array('filter' => $sql->gen(), 'order' => 'creation_dtime ASC'));
         foreach ($cts as $ct) {
             $reviewers[] = $ct->get_comment()->get_submitter();
         }
         if (count($def['chunks'])) {
             $orig_file = $fileinfo ? $scm->getFile($fileinfo) : '';
             $files[$filename] = array($diff->fileCompare($orig_file, $def, $filename), $form->f->{md5($filename)}, $cts);
         } else {
             $files[$filename] = array('', $form->f->{md5($filename)}, $cts);
         }
     }
     $reviewers = Pluf_Model_RemoveDuplicates($reviewers);
     return Pluf_Shortcuts_RenderToResponse('idf/review/view.html', array_merge(array('page_title' => $title, 'review' => $review, 'files' => $files, 'diff' => $diff, 'patch' => $patch, 'comments' => $patch->get_comments_list(array('sort' => 'id ASC')), 'form' => $form, 'reviewers' => $reviewers), IDF_Views_Issue::autoCompleteArrays($prj)), $request);
 }
Esempio n. 6
0
 public function listLabel($request, $match)
 {
     $prj = $request->project;
     $tag = Pluf_Shortcuts_GetObjectOr404('IDF_Tag', $match[2]);
     $prj->inOr404($tag);
     $title = sprintf(__('%1$s Downloads with Label %2$s'), (string) $prj, (string) $tag);
     // Paginator to paginate the downloads
     $ptags = self::getDownloadTags($prj);
     $dtag = array_pop($ptags);
     // The last tag is the deprecated tag.
     $pag = new Pluf_Paginator(new IDF_Upload());
     $pag->model_view = 'join_tags';
     $pag->class = 'recent-issues';
     $pag->item_extra_props = array('project_m' => $prj, 'shortname' => $prj->shortname);
     $pag->summary = sprintf(__('This table shows the downloads with label %s.'), (string) $tag);
     $pag->forced_where = new Pluf_SQL('project=%s AND idf_tag_id=%s', array($prj->id, $tag->id));
     $pag->action = array('IDF_Views_Download::listLabel', array($prj->shortname, $tag->id));
     $pag->edit_action = array('IDF_Views_Download::view', 'shortname', 'id');
     $list_display = array('file' => __('File'), array('summary', 'IDF_Views_Download_SummaryAndLabels', __('Summary')), array('filesize', 'IDF_Views_Download_Size', __('Size')), array('creation_dtime', 'Pluf_Paginator_DateYMD', __('Uploaded')));
     $pag->configure($list_display, array(), array('file', 'filesize', 'creation_dtime'));
     $pag->items_per_page = 10;
     $pag->no_results_text = __('No downloads were found.');
     $pag->sort_order = array('creation_dtime', 'DESC');
     $pag->setFromRequest($request);
     $tags = $prj->getTagCloud('downloads');
     return Pluf_Shortcuts_RenderToResponse('idf/downloads/index.html', array('page_title' => $title, 'label' => $tag, 'downloads' => $pag, 'tags' => $tags, 'dlabel' => $dtag), $request);
 }
Esempio n. 7
0
 /**
  * Display the deleteList page of the application.
  *
  * @param Pluf_HTTP_Request Request object
  * @param array Matches against the regex of the dispatcher
  * @return Pluf_HTTP_Response or can throw Exception
  */
 public function deleteList($request, $match)
 {
     // Here we show how a list can be delete with the associated
     // Todo_Item.
     $list = Pluf_Shortcuts_GetObjectOr404('Todo_List', $match[1]);
     if ($request->method == 'POST') {
         // We need first to delete all the Todo_Item in the list.
         $items = $list->get_todo_item_list();
         foreach ($items as $item) {
             $item->delete();
         }
         // Then we can delete the list
         $list->delete();
         // You can also drop directly the list and the todo items
         // will be automatically dropped at the same time.
         $url = Pluf_HTTP_URL_urlForView('Todo_Views::main', array());
         return new Pluf_HTTP_Response_Redirect($url);
     }
     // Here we are with a GET request we show a form with a
     // confirmation button to delete the list.
     // To show the items to be deleted, we get them
     $items = $list->get_todo_item_list();
     return Pluf_Shortcuts_RenderToResponse('todo/list/delete.html', array('page_title' => 'Delete a Todo List', 'list' => $list, 'items' => $items));
 }
Esempio n. 8
0
 public function delete($request, $match)
 {
     $prj = $request->project;
     $page = Pluf_Shortcuts_GetObjectOr404('IDF_WikiPage', $match[2]);
     $prj->inOr404($page);
     $params = array('page' => $page);
     if ($request->method == 'POST') {
         $form = new IDF_Form_WikiDelete($request->POST, $params);
         if ($form->isValid()) {
             $form->save();
             $request->user->setMessage(__('The documentation page has been deleted.'));
             $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::index', array($prj->shortname));
             return new Pluf_HTTP_Response_Redirect($url);
         }
     } else {
         $form = new IDF_Form_WikiDelete(null, $params);
     }
     $title = sprintf(__('Delete Page %s'), $page->title);
     $revision = $page->get_current_revision();
     $false = Pluf_DB_BooleanToDb(false, $page->getDbConnection());
     $revs = $page->get_revisions_list(array('order' => 'creation_dtime DESC', 'filter' => 'is_head=' . $false));
     return Pluf_Shortcuts_RenderToResponse('idf/wiki/deletepage.html', array('page_title' => $title, 'page' => $page, 'form' => $form, 'rev' => $revision, 'revs' => $revs, 'tags' => $page->get_tags_list()), $request);
 }