diff --git a/src/applications/project/controller/PhabricatorProjectArchiveController.php b/src/applications/project/controller/PhabricatorProjectArchiveController.php index fdd34a3ea6..d6470ca1eb 100644 --- a/src/applications/project/controller/PhabricatorProjectArchiveController.php +++ b/src/applications/project/controller/PhabricatorProjectArchiveController.php @@ -1,74 +1,68 @@ id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); $project = id(new PhabricatorProjectQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$project) { return new Aphront404Response(); } $edit_uri = $this->getApplicationURI('profile/'.$project->getID().'/'); if ($request->isFormPost()) { if ($project->isArchived()) { $new_status = PhabricatorProjectStatus::STATUS_ACTIVE; } else { $new_status = PhabricatorProjectStatus::STATUS_ARCHIVED; } $xactions = array(); $xactions[] = id(new PhabricatorProjectTransaction()) ->setTransactionType(PhabricatorProjectTransaction::TYPE_STATUS) ->setNewValue($new_status); id(new PhabricatorProjectTransactionEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true) ->setContinueOnMissingFields(true) ->applyTransactions($project, $xactions); return id(new AphrontRedirectResponse())->setURI($edit_uri); } if ($project->isArchived()) { $title = pht('Really activate project?'); $body = pht('This project will become active again.'); $button = pht('Activate Project'); } else { $title = pht('Really archive project?'); $body = pht('This project will be moved to the archive.'); $button = pht('Archive Project'); } $dialog = id(new AphrontDialogView()) ->setUser($viewer) ->setTitle($title) ->appendChild($body) ->addCancelButton($edit_uri) ->addSubmitButton($button); return id(new AphrontDialogResponse())->setDialog($dialog); } } diff --git a/src/applications/project/controller/PhabricatorProjectBoardImportController.php b/src/applications/project/controller/PhabricatorProjectBoardImportController.php index b11d6efe31..46877b9e14 100644 --- a/src/applications/project/controller/PhabricatorProjectBoardImportController.php +++ b/src/applications/project/controller/PhabricatorProjectBoardImportController.php @@ -1,87 +1,81 @@ projectID = $data['projectID']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $project_id = $request->getURIData('projectID'); $project = id(new PhabricatorProjectQuery()) ->setViewer($viewer) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) - ->withIDs(array($this->projectID)) + ->withIDs(array($project_id)) ->executeOne(); if (!$project) { return new Aphront404Response(); } $this->setProject($project); $columns = id(new PhabricatorProjectColumnQuery()) ->setViewer($viewer) ->withProjectPHIDs(array($project->getPHID())) ->execute(); if ($columns) { return new Aphront400Response(); } $project_id = $project->getID(); $board_uri = $this->getApplicationURI("board/{$project_id}/"); if ($request->isFormPost()) { $import_phid = $request->getArr('importProjectPHID'); $import_phid = reset($import_phid); $import_columns = id(new PhabricatorProjectColumnQuery()) ->setViewer($viewer) ->withProjectPHIDs(array($import_phid)) ->execute(); if (!$import_columns) { return new Aphront400Response(); } $table = id(new PhabricatorProjectColumn()) ->openTransaction(); foreach ($import_columns as $import_column) { if ($import_column->isHidden()) { continue; } $new_column = PhabricatorProjectColumn::initializeNewColumn($viewer) ->setSequence($import_column->getSequence()) ->setProjectPHID($project->getPHID()) ->setName($import_column->getName()) ->setProperties($import_column->getProperties()) ->save(); } $table->saveTransaction(); return id(new AphrontRedirectResponse())->setURI($board_uri); } $proj_selector = id(new AphrontFormTokenizerControl()) ->setName('importProjectPHID') ->setUser($viewer) ->setDatasource(id(new PhabricatorProjectDatasource()) ->setParameters(array('mustHaveColumns' => true)) ->setLimit(1)); return $this->newDialog() ->setTitle(pht('Import Columns')) ->setWidth(AphrontDialogView::WIDTH_FORM) ->appendParagraph(pht('Choose a project to import columns from:')) ->appendChild($proj_selector) ->addCancelButton($board_uri) ->addSubmitButton(pht('Import')); } } diff --git a/src/applications/project/controller/PhabricatorProjectBoardReorderController.php b/src/applications/project/controller/PhabricatorProjectBoardReorderController.php index 3bd1233909..425c27b5f0 100644 --- a/src/applications/project/controller/PhabricatorProjectBoardReorderController.php +++ b/src/applications/project/controller/PhabricatorProjectBoardReorderController.php @@ -1,146 +1,138 @@ projectID = $data['projectID']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $projectid = $request->getURIData('projectID'); $project = id(new PhabricatorProjectQuery()) ->setViewer($viewer) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) - ->withIDs(array($this->projectID)) + ->withIDs(array($projectid)) ->executeOne(); if (!$project) { return new Aphront404Response(); } $this->setProject($project); - - $project_id = $project->getID(); $board_uri = $this->getApplicationURI("board/{$project_id}/"); $reorder_uri = $this->getApplicationURI("board/{$project_id}/reorder/"); if ($request->isFormPost()) { // User clicked "Done", make sure the page reloads to show the new // column order. return id(new AphrontRedirectResponse())->setURI($board_uri); } $columns = id(new PhabricatorProjectColumnQuery()) ->setViewer($viewer) ->withProjectPHIDs(array($project->getPHID())) ->execute(); $columns = msort($columns, 'getSequence'); $column_phid = $request->getStr('columnPHID'); if ($column_phid && $request->validateCSRF()) { $columns = mpull($columns, null, 'getPHID'); if (empty($columns[$column_phid])) { return new Aphront404Response(); } $target_column = $columns[$column_phid]; $new_sequence = $request->getInt('sequence'); if ($new_sequence < 0) { return new Aphront404Response(); } // TODO: For now, we're not recording any transactions here. We probably // should, but this sort of edit is extremely trivial. // Resequence the columns so that the moved column has the correct // sequence number. Move columns after it up one place in the sequence. $new_map = array(); foreach ($columns as $phid => $column) { $value = $column->getSequence(); if ($column->getPHID() == $column_phid) { $value = $new_sequence; } else if ($column->getSequence() >= $new_sequence) { $value = $value + 1; } $new_map[$phid] = $value; } // Sort the columns into their new ordering. asort($new_map); // Now, compact the ordering and adjust any columns that need changes. $project->openTransaction(); $sequence = 0; foreach ($new_map as $phid => $ignored) { $new_value = $sequence++; $cur_value = $columns[$phid]->getSequence(); if ($new_value != $cur_value) { $columns[$phid]->setSequence($new_value)->save(); } } $project->saveTransaction(); return id(new AphrontAjaxResponse())->setContent( array( 'sequenceMap' => mpull($columns, 'getSequence', 'getPHID'), )); } $list_id = celerity_generate_unique_node_id(); $list = id(new PHUIObjectItemListView()) ->setUser($viewer) ->setID($list_id) ->setFlush(true); foreach ($columns as $column) { $item = id(new PHUIObjectItemView()) ->setHeader($column->getDisplayName()) ->addIcon('none', $column->getDisplayType()); if ($column->isHidden()) { $item->setDisabled(true); } $item->setGrippable(true); $item->addSigil('board-column'); $item->setMetadata( array( 'columnPHID' => $column->getPHID(), 'columnSequence' => $column->getSequence(), )); $list->addItem($item); } Javelin::initBehavior( 'reorder-columns', array( 'listID' => $list_id, 'reorderURI' => $reorder_uri, )); $note = id(new PHUIInfoView()) ->appendChild(pht('Drag and drop columns to reorder them.')) ->setSeverity(PHUIInfoView::SEVERITY_NOTICE); return $this->newDialog() ->setTitle(pht('Reorder Columns')) ->setWidth(AphrontDialogView::WIDTH_FORM) ->appendChild($note) ->appendChild($list) ->addSubmitButton(pht('Done')); } } diff --git a/src/applications/project/controller/PhabricatorProjectColumnDetailController.php b/src/applications/project/controller/PhabricatorProjectColumnDetailController.php index 3a91b55cbd..c44fb5b87c 100644 --- a/src/applications/project/controller/PhabricatorProjectColumnDetailController.php +++ b/src/applications/project/controller/PhabricatorProjectColumnDetailController.php @@ -1,140 +1,133 @@ projectID = $data['projectID']; - $this->id = idx($data, 'id'); - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); + $project_id = $request->getURIData('projectID'); $project = id(new PhabricatorProjectQuery()) ->setViewer($viewer) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, )) - ->withIDs(array($this->projectID)) + ->withIDs(array($project_id)) ->needImages(true) ->executeOne(); if (!$project) { return new Aphront404Response(); } $this->setProject($project); $column = id(new PhabricatorProjectColumnQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, )) ->executeOne(); if (!$column) { return new Aphront404Response(); } $timeline = $this->buildTransactionTimeline( $column, new PhabricatorProjectColumnTransactionQuery()); $timeline->setShouldTerminate(true); $title = pht('%s', $column->getDisplayName()); $header = $this->buildHeaderView($column); $actions = $this->buildActionView($column); $properties = $this->buildPropertyView($column, $actions); $box = id(new PHUIObjectBoxView()) ->setHeader($header) ->addPropertyList($properties); $nav = $this->buildIconNavView($project); $nav->appendChild($box); $nav->appendChild($timeline); return $this->buildApplicationPage( $nav, array( 'title' => $title, )); } private function buildHeaderView(PhabricatorProjectColumn $column) { $viewer = $this->getRequest()->getUser(); $header = id(new PHUIHeaderView()) ->setUser($viewer) ->setHeader($column->getDisplayName()) ->setPolicyObject($column); if ($column->isHidden()) { $header->setStatus('fa-ban', 'dark', pht('Hidden')); } return $header; } private function buildActionView(PhabricatorProjectColumn $column) { $viewer = $this->getRequest()->getUser(); $id = $column->getID(); $project_id = $this->getProject()->getID(); $base_uri = '/board/'.$project_id.'/'; $actions = id(new PhabricatorActionListView()) ->setObjectURI($this->getApplicationURI($base_uri.'column/'.$id.'/')) ->setUser($viewer); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $column, PhabricatorPolicyCapability::CAN_EDIT); $actions->addAction( id(new PhabricatorActionView()) ->setName(pht('Edit Column')) ->setIcon('fa-pencil') ->setHref($this->getApplicationURI($base_uri.'edit/'.$id.'/')) ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); return $actions; } private function buildPropertyView( PhabricatorProjectColumn $column, PhabricatorActionListView $actions) { $viewer = $this->getRequest()->getUser(); $properties = id(new PHUIPropertyListView()) ->setUser($viewer) ->setObject($column) ->setActionList($actions); $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( $viewer, $column); $properties->addProperty( pht('Editable By'), $descriptions[PhabricatorPolicyCapability::CAN_EDIT]); $limit = $column->getPointLimit(); $properties->addProperty( pht('Point Limit'), $limit ? $limit : pht('No Limit')); return $properties; } } diff --git a/src/applications/project/controller/PhabricatorProjectColumnEditController.php b/src/applications/project/controller/PhabricatorProjectColumnEditController.php index 28038f5d98..d59c3648fe 100644 --- a/src/applications/project/controller/PhabricatorProjectColumnEditController.php +++ b/src/applications/project/controller/PhabricatorProjectColumnEditController.php @@ -1,163 +1,156 @@ projectID = $data['projectID']; - $this->id = idx($data, 'id'); - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); + $project_id = $request->getURIData('projectID'); $project = id(new PhabricatorProjectQuery()) ->setViewer($viewer) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) - ->withIDs(array($this->projectID)) + ->withIDs(array($project_id)) ->needImages(true) ->executeOne(); if (!$project) { return new Aphront404Response(); } $this->setProject($project); - $is_new = ($this->id ? false : true); + $is_new = ($id ? false : true); if (!$is_new) { $column = id(new PhabricatorProjectColumnQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$column) { return new Aphront404Response(); } } else { $column = PhabricatorProjectColumn::initializeNewColumn($viewer); } $e_name = null; $e_limit = null; $v_limit = $column->getPointLimit(); $v_name = $column->getName(); $validation_exception = null; - $base_uri = '/board/'.$this->projectID.'/'; + $base_uri = '/board/'.$project_id.'/'; if ($is_new) { // we want to go back to the board $view_uri = $this->getApplicationURI($base_uri); } else { - $view_uri = $this->getApplicationURI($base_uri.'column/'.$this->id.'/'); + $view_uri = $this->getApplicationURI($base_uri.'column/'.$id.'/'); } if ($request->isFormPost()) { $v_name = $request->getStr('name'); $v_limit = $request->getStr('limit'); if ($is_new) { $column->setProjectPHID($project->getPHID()); $column->attachProject($project); $columns = id(new PhabricatorProjectColumnQuery()) ->setViewer($viewer) ->withProjectPHIDs(array($project->getPHID())) ->execute(); $new_sequence = 1; if ($columns) { $values = mpull($columns, 'getSequence'); $new_sequence = max($values) + 1; } $column->setSequence($new_sequence); } $xactions = array(); $type_name = PhabricatorProjectColumnTransaction::TYPE_NAME; $xactions[] = id(new PhabricatorProjectColumnTransaction()) ->setTransactionType($type_name) ->setNewValue($v_name); $type_limit = PhabricatorProjectColumnTransaction::TYPE_LIMIT; $xactions[] = id(new PhabricatorProjectColumnTransaction()) ->setTransactionType($type_limit) ->setNewValue($v_limit); try { $editor = id(new PhabricatorProjectColumnTransactionEditor()) ->setActor($viewer) ->setContinueOnNoEffect(true) ->setContentSourceFromRequest($request) ->applyTransactions($column, $xactions); return id(new AphrontRedirectResponse())->setURI($view_uri); } catch (PhabricatorApplicationTransactionValidationException $ex) { $e_name = $ex->getShortMessage($type_name); $e_limit = $ex->getShortMessage($type_limit); $validation_exception = $ex; } } $form = new AphrontFormView(); $form ->setUser($request->getUser()) ->appendChild( id(new AphrontFormTextControl()) ->setValue($v_name) ->setLabel(pht('Name')) ->setName('name') ->setError($e_name) ->setCaption( pht('This will be displayed as the header of the column.'))) ->appendChild( id(new AphrontFormTextControl()) ->setValue($v_limit) ->setLabel(pht('Point Limit')) ->setName('limit') ->setError($e_limit) ->setCaption( pht('Maximum number of points of tasks allowed in the column.'))); if ($is_new) { $title = pht('Create Column'); $submit = pht('Create Column'); } else { $title = pht('Edit %s', $column->getDisplayName()); $submit = pht('Save Column'); } $form->appendChild( id(new AphrontFormSubmitControl()) ->setValue($submit) ->addCancelButton($view_uri)); $form_box = id(new PHUIObjectBoxView()) ->setHeaderText($title) ->setValidationException($validation_exception) ->setForm($form); $nav = $this->buildIconNavView($project); $nav->appendChild($form_box); return $this->buildApplicationPage( $nav, array( 'title' => $title, )); } } diff --git a/src/applications/project/controller/PhabricatorProjectColumnHideController.php b/src/applications/project/controller/PhabricatorProjectColumnHideController.php index 2e613ee7da..167cbfbd2e 100644 --- a/src/applications/project/controller/PhabricatorProjectColumnHideController.php +++ b/src/applications/project/controller/PhabricatorProjectColumnHideController.php @@ -1,112 +1,106 @@ getViewer(); + $id = $request->getURIData('id'); + $project_id = $request->getURIData('projectID'); - public function willProcessRequest(array $data) { - $this->projectID = $data['projectID']; - $this->id = idx($data, 'id'); - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); $project = id(new PhabricatorProjectQuery()) ->setViewer($viewer) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) - ->withIDs(array($this->projectID)) + ->withIDs(array($project_id)) ->executeOne(); if (!$project) { return new Aphront404Response(); } $this->setProject($project); $column = id(new PhabricatorProjectColumnQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$column) { return new Aphront404Response(); } $column_phid = $column->getPHID(); - $view_uri = $this->getApplicationURI('/board/'.$this->projectID.'/'); + $view_uri = $this->getApplicationURI('/board/'.$project_id.'/'); $view_uri = new PhutilURI($view_uri); foreach ($request->getPassthroughRequestData() as $key => $value) { $view_uri->setQueryParam($key, $value); } if ($column->isDefaultColumn()) { return $this->newDialog() ->setTitle(pht('Can Not Hide Default Column')) ->appendParagraph( pht('You can not hide the default/backlog column on a board.')) ->addCancelButton($view_uri, pht('Okay')); } if ($request->isFormPost()) { if ($column->isHidden()) { $new_status = PhabricatorProjectColumn::STATUS_ACTIVE; } else { $new_status = PhabricatorProjectColumn::STATUS_HIDDEN; } $type_status = PhabricatorProjectColumnTransaction::TYPE_STATUS; $xactions = array(id(new PhabricatorProjectColumnTransaction()) ->setTransactionType($type_status) ->setNewValue($new_status), ); $editor = id(new PhabricatorProjectColumnTransactionEditor()) ->setActor($viewer) ->setContinueOnNoEffect(true) ->setContentSourceFromRequest($request) ->applyTransactions($column, $xactions); return id(new AphrontRedirectResponse())->setURI($view_uri); } if ($column->isHidden()) { $title = pht('Show Column'); } else { $title = pht('Hide Column'); } if ($column->isHidden()) { $body = pht( 'Are you sure you want to show this column?'); } else { $body = pht( 'Are you sure you want to hide this column? It will no longer '. 'appear on the workboard.'); } $dialog = $this->newDialog() ->setWidth(AphrontDialogView::WIDTH_FORM) ->setTitle($title) ->appendChild($body) ->setDisableWorkflowOnCancel(true) ->addCancelButton($view_uri) ->addSubmitButton($title); foreach ($request->getPassthroughRequestData() as $key => $value) { $dialog->addHiddenInput($key, $value); } return $dialog; } } diff --git a/src/applications/project/controller/PhabricatorProjectEditDetailsController.php b/src/applications/project/controller/PhabricatorProjectEditDetailsController.php index af92c60aea..48016845a8 100644 --- a/src/applications/project/controller/PhabricatorProjectEditDetailsController.php +++ b/src/applications/project/controller/PhabricatorProjectEditDetailsController.php @@ -1,318 +1,312 @@ getViewer(); + $id = $request->getURIData('id'); - public function willProcessRequest(array $data) { - $this->id = idx($data, 'id'); - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); - - if ($this->id) { + if ($id) { $id = $request->getURIData('id'); $is_new = false; $project = id(new PhabricatorProjectQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->needSlugs(true) ->needImages(true) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$project) { return new Aphront404Response(); } } else { $is_new = true; $this->requireApplicationCapability( ProjectCreateProjectsCapability::CAPABILITY); $project = PhabricatorProject::initializeNewProject($viewer); } $field_list = PhabricatorCustomField::getObjectFields( $project, PhabricatorCustomField::ROLE_EDIT); $field_list ->setViewer($viewer) ->readFieldsFromStorage($project); $e_name = true; $e_slugs = false; $e_edit = null; $v_name = $project->getName(); $project_slugs = $project->getSlugs(); $project_slugs = mpull($project_slugs, 'getSlug', 'getSlug'); $v_primary_slug = $project->getPrimarySlug(); unset($project_slugs[$v_primary_slug]); $v_slugs = $project_slugs; $v_color = $project->getColor(); $v_icon = $project->getIcon(); $v_locked = $project->getIsMembershipLocked(); $validation_exception = null; if ($request->isFormPost()) { $e_name = null; $e_slugs = null; $v_name = $request->getStr('name'); $v_slugs = $request->getStrList('slugs'); $v_view = $request->getStr('can_view'); $v_edit = $request->getStr('can_edit'); $v_join = $request->getStr('can_join'); $v_color = $request->getStr('color'); $v_icon = $request->getStr('icon'); $v_locked = $request->getInt('is_membership_locked', 0); $type_name = PhabricatorProjectTransaction::TYPE_NAME; $type_slugs = PhabricatorProjectTransaction::TYPE_SLUGS; $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY; $type_icon = PhabricatorProjectTransaction::TYPE_ICON; $type_color = PhabricatorProjectTransaction::TYPE_COLOR; $type_locked = PhabricatorProjectTransaction::TYPE_LOCKED; $xactions = array(); $xactions[] = id(new PhabricatorProjectTransaction()) ->setTransactionType($type_name) ->setNewValue($v_name); $xactions[] = id(new PhabricatorProjectTransaction()) ->setTransactionType($type_slugs) ->setNewValue($v_slugs); $xactions[] = id(new PhabricatorProjectTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) ->setNewValue($v_view); $xactions[] = id(new PhabricatorProjectTransaction()) ->setTransactionType($type_edit) ->setNewValue($v_edit); $xactions[] = id(new PhabricatorProjectTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_JOIN_POLICY) ->setNewValue($v_join); $xactions[] = id(new PhabricatorProjectTransaction()) ->setTransactionType($type_icon) ->setNewValue($v_icon); $xactions[] = id(new PhabricatorProjectTransaction()) ->setTransactionType($type_color) ->setNewValue($v_color); $xactions[] = id(new PhabricatorProjectTransaction()) ->setTransactionType($type_locked) ->setNewValue($v_locked); $xactions = array_merge( $xactions, $field_list->buildFieldTransactionsFromRequest( new PhabricatorProjectTransaction(), $request)); $editor = id(new PhabricatorProjectTransactionEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true); if ($is_new) { $xactions[] = id(new PhabricatorProjectTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) ->setMetadataValue( 'edge:type', PhabricatorProjectProjectHasMemberEdgeType::EDGECONST) ->setNewValue( array( '+' => array($viewer->getPHID() => $viewer->getPHID()), )); } try { $editor->applyTransactions($project, $xactions); if ($request->isAjax()) { return id(new AphrontAjaxResponse()) ->setContent(array( 'phid' => $project->getPHID(), 'name' => $project->getName(), )); } $redirect_uri = $this->getApplicationURI('profile/'.$project->getID().'/'); return id(new AphrontRedirectResponse())->setURI($redirect_uri); } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; $e_name = $ex->getShortMessage($type_name); $e_slugs = $ex->getShortMessage($type_slugs); $e_edit = $ex->getShortMessage($type_edit); $project->setViewPolicy($v_view); $project->setEditPolicy($v_edit); $project->setJoinPolicy($v_join); } } if ($is_new) { $header_name = pht('Create a New Project'); $title = pht('Create Project'); } else { $header_name = pht('Edit Project'); $title = pht('Edit Project'); } $policies = id(new PhabricatorPolicyQuery()) ->setViewer($viewer) ->setObject($project) ->execute(); $v_slugs = implode(', ', $v_slugs); $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('Name')) ->setName('name') ->setValue($v_name) ->setError($e_name)); $field_list->appendFieldsToForm($form); $shades = PhabricatorProjectIcon::getColorMap(); if ($is_new) { $icon_uri = $this->getApplicationURI('icon/'); } else { $icon_uri = $this->getApplicationURI('icon/'.$project->getID().'/'); } $icon_display = PhabricatorProjectIcon::renderIconForChooser($v_icon); list($can_lock, $lock_message) = $this->explainApplicationCapability( ProjectCanLockProjectsCapability::CAPABILITY, pht('You can update the Lock Project setting.'), pht('You can not update the Lock Project setting.')); $form ->appendChild( id(new AphrontFormChooseButtonControl()) ->setLabel(pht('Icon')) ->setName('icon') ->setDisplayValue($icon_display) ->setButtonText(pht('Choose Icon...')) ->setChooseURI($icon_uri) ->setValue($v_icon)) ->appendChild( id(new AphrontFormSelectControl()) ->setLabel(pht('Color')) ->setName('color') ->setValue($v_color) ->setOptions($shades)); if (!$is_new) { $form->appendChild( id(new AphrontFormStaticControl()) ->setLabel(pht('Primary Hashtag')) ->setCaption(pht('The primary hashtag is derived from the name.')) ->setValue($v_primary_slug)); } $form ->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('Additional Hashtags')) ->setCaption(pht( 'Specify a comma-separated list of additional hashtags.')) ->setName('slugs') ->setValue($v_slugs) ->setError($e_slugs)) ->appendChild( id(new AphrontFormPolicyControl()) ->setUser($viewer) ->setName('can_view') ->setPolicyObject($project) ->setPolicies($policies) ->setCapability(PhabricatorPolicyCapability::CAN_VIEW)) ->appendChild( id(new AphrontFormPolicyControl()) ->setUser($viewer) ->setName('can_edit') ->setPolicyObject($project) ->setPolicies($policies) ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) ->setError($e_edit)) ->appendChild( id(new AphrontFormPolicyControl()) ->setUser($viewer) ->setName('can_join') ->setCaption( pht('Users who can edit a project can always join a project.')) ->setPolicyObject($project) ->setPolicies($policies) ->setCapability(PhabricatorPolicyCapability::CAN_JOIN)) ->appendChild( id(new AphrontFormCheckboxControl()) ->setLabel(pht('Lock Project')) ->setDisabled(!$can_lock) ->addCheckbox( 'is_membership_locked', 1, pht('Prevent members from leaving this project.'), $v_locked) ->setCaption($lock_message)); if ($request->isAjax()) { $errors = array(); if ($validation_exception) { $errors = mpull($ex->getErrors(), 'getMessage'); } $dialog = id(new AphrontDialogView()) ->setUser($viewer) ->setWidth(AphrontDialogView::WIDTH_FULL) ->setTitle($header_name) ->setErrors($errors) ->appendForm($form) ->addSubmitButton($title) ->addCancelButton('/project/'); return id(new AphrontDialogResponse())->setDialog($dialog); } $form->appendChild( id(new AphrontFormSubmitControl()) ->addCancelButton($this->getApplicationURI()) ->setValue(pht('Save'))); $form_box = id(new PHUIObjectBoxView()) ->setHeaderText($title) ->setValidationException($validation_exception) ->setForm($form); if (!$is_new) { $nav = $this->buildIconNavView($project); $nav->selectFilter("details/{$id}/"); $nav->appendChild($form_box); } else { $nav = array($form_box); } return $this->buildApplicationPage( $nav, array( 'title' => $title, )); } } diff --git a/src/applications/project/controller/PhabricatorProjectEditIconController.php b/src/applications/project/controller/PhabricatorProjectEditIconController.php index c21080d595..fe7e28b4c2 100644 --- a/src/applications/project/controller/PhabricatorProjectEditIconController.php +++ b/src/applications/project/controller/PhabricatorProjectEditIconController.php @@ -1,106 +1,100 @@ getViewer(); + $id = $request->getURIData('id'); - public function willProcessRequest(array $data) { - $this->id = idx($data, 'id'); - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); - - if ($this->id) { + if ($id) { $project = id(new PhabricatorProjectQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$project) { return new Aphront404Response(); } $cancel_uri = $this->getApplicationURI('profile/'.$project->getID().'/'); $project_icon = $project->getIcon(); } else { $this->requireApplicationCapability( ProjectCreateProjectsCapability::CAPABILITY); $cancel_uri = '/project/'; $project_icon = $request->getStr('value'); } require_celerity_resource('project-icon-css'); Javelin::initBehavior('phabricator-tooltips'); $project_icons = PhabricatorProjectIcon::getIconMap(); if ($request->isFormPost()) { $v_icon = $request->getStr('icon'); return id(new AphrontAjaxResponse())->setContent( array( 'value' => $v_icon, 'display' => PhabricatorProjectIcon::renderIconForChooser($v_icon), )); } $ii = 0; $buttons = array(); foreach ($project_icons as $icon => $label) { $view = id(new PHUIIconView()) ->setIconFont($icon); $aural = javelin_tag( 'span', array( 'aural' => true, ), pht('Choose "%s" Icon', $label)); if ($icon == $project_icon) { $class_extra = ' selected'; } else { $class_extra = null; } $buttons[] = javelin_tag( 'button', array( 'class' => 'icon-button'.$class_extra, 'name' => 'icon', 'value' => $icon, 'type' => 'submit', 'sigil' => 'has-tooltip', 'meta' => array( 'tip' => $label, ), ), array( $aural, $view, )); if ((++$ii % 4) == 0) { $buttons[] = phutil_tag('br'); } } $buttons = phutil_tag( 'div', array( 'class' => 'icon-grid', ), $buttons); return $this->newDialog() ->setTitle(pht('Choose Project Icon')) ->appendChild($buttons) ->addCancelButton($cancel_uri); } } diff --git a/src/applications/project/controller/PhabricatorProjectEditPictureController.php b/src/applications/project/controller/PhabricatorProjectEditPictureController.php index ca99159718..6f5128eceb 100644 --- a/src/applications/project/controller/PhabricatorProjectEditPictureController.php +++ b/src/applications/project/controller/PhabricatorProjectEditPictureController.php @@ -1,301 +1,294 @@ id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); $id = $request->getURIData('id'); $project = id(new PhabricatorProjectQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->needImages(true) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$project) { return new Aphront404Response(); } $edit_uri = $this->getApplicationURI('profile/'.$project->getID().'/'); $view_uri = $this->getApplicationURI('profile/'.$project->getID().'/'); $supported_formats = PhabricatorFile::getTransformableImageFormats(); $e_file = true; $errors = array(); if ($request->isFormPost()) { $phid = $request->getStr('phid'); $is_default = false; if ($phid == PhabricatorPHIDConstants::PHID_VOID) { $phid = null; $is_default = true; } else if ($phid) { $file = id(new PhabricatorFileQuery()) ->setViewer($viewer) ->withPHIDs(array($phid)) ->executeOne(); } else { if ($request->getFileExists('picture')) { $file = PhabricatorFile::newFromPHPUpload( $_FILES['picture'], array( 'authorPHID' => $viewer->getPHID(), 'canCDN' => true, )); } else { $e_file = pht('Required'); $errors[] = pht( 'You must choose a file when uploading a new project picture.'); } } if (!$errors && !$is_default) { if (!$file->isTransformableImage()) { $e_file = pht('Not Supported'); $errors[] = pht( 'This server only supports these image formats: %s.', implode(', ', $supported_formats)); } else { $xform = PhabricatorFileTransform::getTransformByKey( PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); $xformed = $xform->executeTransform($file); } } if (!$errors) { if ($is_default) { $new_value = null; } else { $new_value = $xformed->getPHID(); } $xactions = array(); $xactions[] = id(new PhabricatorProjectTransaction()) ->setTransactionType(PhabricatorProjectTransaction::TYPE_IMAGE) ->setNewValue($new_value); $editor = id(new PhabricatorProjectTransactionEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnMissingFields(true) ->setContinueOnNoEffect(true); $editor->applyTransactions($project, $xactions); return id(new AphrontRedirectResponse())->setURI($edit_uri); } } $title = pht('Edit Project Picture'); $form = id(new PHUIFormLayoutView()) ->setUser($viewer); $default_image = PhabricatorFile::loadBuiltin($viewer, 'project.png'); $images = array(); $current = $project->getProfileImagePHID(); $has_current = false; if ($current) { $files = id(new PhabricatorFileQuery()) ->setViewer($viewer) ->withPHIDs(array($current)) ->execute(); if ($files) { $file = head($files); if ($file->isTransformableImage()) { $has_current = true; $images[$current] = array( 'uri' => $file->getBestURI(), 'tip' => pht('Current Picture'), ); } } } $images[PhabricatorPHIDConstants::PHID_VOID] = array( 'uri' => $default_image->getBestURI(), 'tip' => pht('Default Picture'), ); require_celerity_resource('people-profile-css'); Javelin::initBehavior('phabricator-tooltips', array()); $buttons = array(); foreach ($images as $phid => $spec) { $button = javelin_tag( 'button', array( 'class' => 'grey profile-image-button', 'sigil' => 'has-tooltip', 'meta' => array( 'tip' => $spec['tip'], 'size' => 300, ), ), phutil_tag( 'img', array( 'height' => 50, 'width' => 50, 'src' => $spec['uri'], ))); $button = array( phutil_tag( 'input', array( 'type' => 'hidden', 'name' => 'phid', 'value' => $phid, )), $button, ); $button = phabricator_form( $viewer, array( 'class' => 'profile-image-form', 'method' => 'POST', ), $button); $buttons[] = $button; } if ($has_current) { $form->appendChild( id(new AphrontFormMarkupControl()) ->setLabel(pht('Current Picture')) ->setValue(array_shift($buttons))); } $form->appendChild( id(new AphrontFormMarkupControl()) ->setLabel(pht('Use Picture')) ->setValue($buttons)); $launch_id = celerity_generate_unique_node_id(); $input_id = celerity_generate_unique_node_id(); Javelin::initBehavior( 'launch-icon-composer', array( 'launchID' => $launch_id, 'inputID' => $input_id, )); $compose_button = javelin_tag( 'button', array( 'class' => 'grey', 'id' => $launch_id, 'sigil' => 'icon-composer', ), pht('Choose Icon and Color...')); $compose_input = javelin_tag( 'input', array( 'type' => 'hidden', 'id' => $input_id, 'name' => 'phid', )); $compose_form = phabricator_form( $viewer, array( 'class' => 'profile-image-form', 'method' => 'POST', ), array( $compose_input, $compose_button, )); $form->appendChild( id(new AphrontFormMarkupControl()) ->setLabel(pht('Quick Create')) ->setValue($compose_form)); $default_button = javelin_tag( 'button', array( 'class' => 'grey', ), pht('Use Project Icon')); $default_input = javelin_tag( 'input', array( 'type' => 'hidden', 'name' => 'projectPHID', 'value' => $project->getPHID(), )); $default_form = phabricator_form( $viewer, array( 'class' => 'profile-image-form', 'method' => 'POST', 'action' => '/file/compose/', ), array( $default_input, $default_button, )); $form->appendChild( id(new AphrontFormMarkupControl()) ->setLabel(pht('Use Default')) ->setValue($default_form)); $upload_form = id(new AphrontFormView()) ->setUser($viewer) ->setEncType('multipart/form-data') ->appendChild( id(new AphrontFormFileControl()) ->setName('picture') ->setLabel(pht('Upload Picture')) ->setError($e_file) ->setCaption( pht('Supported formats: %s', implode(', ', $supported_formats)))) ->appendChild( id(new AphrontFormSubmitControl()) ->addCancelButton($edit_uri) ->setValue(pht('Upload Picture'))); $form_box = id(new PHUIObjectBoxView()) ->setHeaderText($title) ->setFormErrors($errors) ->setForm($form); $upload_box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Upload New Picture')) ->setForm($upload_form); $nav = $this->buildIconNavView($project); $nav->selectFilter("edit/{$id}/"); $nav->appendChild($form_box); $nav->appendChild($upload_box); return $this->buildApplicationPage( $nav, array( 'title' => $title, )); } } diff --git a/src/applications/project/controller/PhabricatorProjectListController.php b/src/applications/project/controller/PhabricatorProjectListController.php index 1852f43bfc..ea56036c7b 100644 --- a/src/applications/project/controller/PhabricatorProjectListController.php +++ b/src/applications/project/controller/PhabricatorProjectListController.php @@ -1,46 +1,43 @@ queryKey = idx($data, 'queryKey'); - } + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $query_key = $request->getURIData('queryKey'); - public function processRequest() { $controller = id(new PhabricatorApplicationSearchController()) - ->setQueryKey($this->queryKey) + ->setQueryKey($query_key) ->setSearchEngine(new PhabricatorProjectSearchEngine()) ->setNavigation($this->buildSideNavView()); return $this->delegateToController($controller); } public function buildApplicationMenu() { return $this->buildSideNavView(true)->getMenu(); } protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); $can_create = $this->hasApplicationCapability( ProjectCreateProjectsCapability::CAPABILITY); $crumbs->addAction( id(new PHUIListItemView()) ->setName(pht('Create Project')) ->setHref($this->getApplicationURI('create/')) ->setIcon('fa-plus-square') ->setWorkflow(!$can_create) ->setDisabled(!$can_create)); return $crumbs; } } diff --git a/src/applications/project/controller/PhabricatorProjectMembersEditController.php b/src/applications/project/controller/PhabricatorProjectMembersEditController.php index d033a87394..c7a9144188 100644 --- a/src/applications/project/controller/PhabricatorProjectMembersEditController.php +++ b/src/applications/project/controller/PhabricatorProjectMembersEditController.php @@ -1,161 +1,154 @@ id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); $id = $request->getURIData('id'); $project = id(new PhabricatorProjectQuery()) - ->setViewer($user) - ->withIDs(array($this->id)) + ->setViewer($viewer) + ->withIDs(array($id)) ->needMembers(true) ->needImages(true) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, )) ->executeOne(); if (!$project) { return new Aphront404Response(); } $member_phids = $project->getMemberPHIDs(); if ($request->isFormPost()) { $member_spec = array(); $remove = $request->getStr('remove'); if ($remove) { $member_spec['-'] = array_fuse(array($remove)); } $add_members = $request->getArr('phids'); if ($add_members) { $member_spec['+'] = array_fuse($add_members); } $type_member = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST; $xactions = array(); $xactions[] = id(new PhabricatorProjectTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) ->setMetadataValue('edge:type', $type_member) ->setNewValue($member_spec); $editor = id(new PhabricatorProjectTransactionEditor($project)) - ->setActor($user) + ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true) ->setContinueOnMissingFields(true) ->applyTransactions($project, $xactions); return id(new AphrontRedirectResponse()) ->setURI($request->getRequestURI()); } $member_phids = array_reverse($member_phids); $handles = $this->loadViewerHandles($member_phids); $state = array(); foreach ($handles as $handle) { $state[] = array( 'phid' => $handle->getPHID(), 'name' => $handle->getFullName(), ); } $can_edit = PhabricatorPolicyFilter::hasCapability( - $user, + $viewer, $project, PhabricatorPolicyCapability::CAN_EDIT); $form_box = null; $title = pht('Add Members'); if ($can_edit) { $header_name = pht('Edit Members'); $view_uri = $this->getApplicationURI('profile/'.$project->getID().'/'); $form = new AphrontFormView(); $form - ->setUser($user) + ->setUser($viewer) ->appendControl( id(new AphrontFormTokenizerControl()) ->setName('phids') ->setLabel(pht('Add Members')) ->setDatasource(new PhabricatorPeopleDatasource())) ->appendChild( id(new AphrontFormSubmitControl()) ->addCancelButton($view_uri) ->setValue(pht('Add Members'))); $form_box = id(new PHUIObjectBoxView()) ->setHeaderText($title) ->setForm($form); } $member_list = $this->renderMemberList($project, $handles); $nav = $this->buildIconNavView($project); $nav->selectFilter("members/{$id}/"); $nav->appendChild($form_box); $nav->appendChild($member_list); return $this->buildApplicationPage( $nav, array( 'title' => $title, )); } private function renderMemberList( PhabricatorProject $project, array $handles) { $request = $this->getRequest(); $viewer = $request->getUser(); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $project, PhabricatorPolicyCapability::CAN_EDIT); $list = id(new PHUIObjectItemListView()) ->setNoDataString(pht('This project does not have any members.')); foreach ($handles as $handle) { $remove_uri = $this->getApplicationURI( '/members/'.$project->getID().'/remove/?phid='.$handle->getPHID()); $item = id(new PHUIObjectItemView()) ->setHeader($handle->getFullName()) ->setHref($handle->getURI()) ->setImageURI($handle->getImageURI()); if ($can_edit) { $item->addAction( id(new PHUIListItemView()) ->setIcon('fa-times') ->setName(pht('Remove')) ->setHref($remove_uri) ->setWorkflow(true)); } $list->addItem($item); } $box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Members')) ->setObjectList($list); return $box; } } diff --git a/src/applications/project/controller/PhabricatorProjectMembersRemoveController.php b/src/applications/project/controller/PhabricatorProjectMembersRemoveController.php index 270dd9a022..cad3f35c05 100644 --- a/src/applications/project/controller/PhabricatorProjectMembersRemoveController.php +++ b/src/applications/project/controller/PhabricatorProjectMembersRemoveController.php @@ -1,82 +1,76 @@ id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); $project = id(new PhabricatorProjectQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->needMembers(true) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$project) { return new Aphront404Response(); } $member_phids = $project->getMemberPHIDs(); $remove_phid = $request->getStr('phid'); if (!in_array($remove_phid, $member_phids)) { return new Aphront404Response(); } $members_uri = $this->getApplicationURI('members/'.$project->getID().'/'); if ($request->isFormPost()) { $member_spec = array(); $member_spec['-'] = array($remove_phid => $remove_phid); $type_member = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST; $xactions = array(); $xactions[] = id(new PhabricatorProjectTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) ->setMetadataValue('edge:type', $type_member) ->setNewValue($member_spec); $editor = id(new PhabricatorProjectTransactionEditor($project)) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true) ->setContinueOnMissingFields(true) ->applyTransactions($project, $xactions); return id(new AphrontRedirectResponse()) ->setURI($members_uri); } $handle = id(new PhabricatorHandleQuery()) ->setViewer($viewer) ->withPHIDs(array($remove_phid)) ->executeOne(); $dialog = id(new AphrontDialogView()) ->setUser($viewer) ->setTitle(pht('Really Remove Member?')) ->appendParagraph( pht( 'Really remove %s from the project %s?', phutil_tag('strong', array(), $handle->getName()), phutil_tag('strong', array(), $project->getName()))) ->addCancelButton($members_uri) ->addSubmitButton(pht('Remove Project Member')); return id(new AphrontDialogResponse())->setDialog($dialog); } } diff --git a/src/applications/project/controller/PhabricatorProjectMoveController.php b/src/applications/project/controller/PhabricatorProjectMoveController.php index a22050ea77..1b2429917c 100644 --- a/src/applications/project/controller/PhabricatorProjectMoveController.php +++ b/src/applications/project/controller/PhabricatorProjectMoveController.php @@ -1,169 +1,163 @@ id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); $column_phid = $request->getStr('columnPHID'); $object_phid = $request->getStr('objectPHID'); $after_phid = $request->getStr('afterPHID'); $before_phid = $request->getStr('beforePHID'); $order = $request->getStr('order', PhabricatorProjectColumn::DEFAULT_ORDER); $project = id(new PhabricatorProjectQuery()) ->setViewer($viewer) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, )) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->executeOne(); if (!$project) { return new Aphront404Response(); } $object = id(new PhabricatorObjectQuery()) ->setViewer($viewer) ->withPHIDs(array($object_phid)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$object) { return new Aphront404Response(); } $columns = id(new PhabricatorProjectColumnQuery()) ->setViewer($viewer) ->withProjectPHIDs(array($project->getPHID())) ->execute(); $columns = mpull($columns, null, 'getPHID'); $column = idx($columns, $column_phid); if (!$column) { // User is trying to drop this object into a nonexistent column, just kick // them out. return new Aphront404Response(); } $positions = id(new PhabricatorProjectColumnPositionQuery()) ->setViewer($viewer) ->withColumns($columns) ->withObjectPHIDs(array($object_phid)) ->execute(); $xactions = array(); if ($order == PhabricatorProjectColumn::ORDER_NATURAL) { $order_params = array( 'afterPHID' => $after_phid, 'beforePHID' => $before_phid, ); } else { $order_params = array(); } $xactions[] = id(new ManiphestTransaction()) ->setTransactionType(ManiphestTransaction::TYPE_PROJECT_COLUMN) ->setNewValue( array( 'columnPHIDs' => array($column->getPHID()), 'projectPHID' => $column->getProjectPHID(), ) + $order_params) ->setOldValue( array( 'columnPHIDs' => mpull($positions, 'getColumnPHID'), 'projectPHID' => $column->getProjectPHID(), )); $task_phids = array(); if ($after_phid) { $task_phids[] = $after_phid; } if ($before_phid) { $task_phids[] = $before_phid; } if ($task_phids && ($order == PhabricatorProjectColumn::ORDER_PRIORITY)) { $tasks = id(new ManiphestTaskQuery()) ->setViewer($viewer) ->withPHIDs($task_phids) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->execute(); if (count($tasks) != count($task_phids)) { return new Aphront404Response(); } $tasks = mpull($tasks, null, 'getPHID'); $try = array( array($after_phid, true), array($before_phid, false), ); $pri = null; $sub = null; foreach ($try as $spec) { list($task_phid, $is_after) = $spec; $task = idx($tasks, $task_phid); if ($task) { list($pri, $sub) = ManiphestTransactionEditor::getAdjacentSubpriority( $task, $is_after); break; } } if ($pri !== null) { $xactions[] = id(new ManiphestTransaction()) ->setTransactionType(ManiphestTransaction::TYPE_PRIORITY) ->setNewValue($pri); $xactions[] = id(new ManiphestTransaction()) ->setTransactionType(ManiphestTransaction::TYPE_SUBPRIORITY) ->setNewValue($sub); } } $editor = id(new ManiphestTransactionEditor()) ->setActor($viewer) ->setContinueOnMissingFields(true) ->setContinueOnNoEffect(true) ->setContentSourceFromRequest($request); $editor->applyTransactions($object, $xactions); $owner = null; if ($object->getOwnerPHID()) { $owner = id(new PhabricatorHandleQuery()) ->setViewer($viewer) ->withPHIDs(array($object->getOwnerPHID())) ->executeOne(); } $card = id(new ProjectBoardTaskCard()) ->setViewer($viewer) ->setTask($object) ->setOwner($owner) ->setCanEdit(true) ->getItem(); return id(new AphrontAjaxResponse())->setContent( array('task' => $card)); } } diff --git a/src/applications/project/controller/PhabricatorProjectUpdateController.php b/src/applications/project/controller/PhabricatorProjectUpdateController.php index a484b2b670..cfdeb4fd09 100644 --- a/src/applications/project/controller/PhabricatorProjectUpdateController.php +++ b/src/applications/project/controller/PhabricatorProjectUpdateController.php @@ -1,119 +1,112 @@ id = $data['id']; - $this->action = $data['action']; - } - - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); + $action = $request->getURIData('action'); $capabilities = array( PhabricatorPolicyCapability::CAN_VIEW, ); $process_action = false; - switch ($this->action) { + switch ($action) { case 'join': $capabilities[] = PhabricatorPolicyCapability::CAN_JOIN; $process_action = $request->isFormPost(); break; case 'leave': $process_action = $request->isDialogFormPost(); break; default: return new Aphront404Response(); } $project = id(new PhabricatorProjectQuery()) - ->setViewer($user) - ->withIDs(array($this->id)) + ->setViewer($viewer) + ->withIDs(array($id)) ->needMembers(true) ->requireCapabilities($capabilities) ->executeOne(); if (!$project) { return new Aphront404Response(); } $project_uri = $this->getApplicationURI('profile/'.$project->getID().'/'); if ($process_action) { $edge_action = null; - switch ($this->action) { + switch ($action) { case 'join': $edge_action = '+'; break; case 'leave': $edge_action = '-'; break; } $type_member = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST; $member_spec = array( - $edge_action => array($user->getPHID() => $user->getPHID()), + $edge_action => array($viewer->getPHID() => $viewer->getPHID()), ); $xactions = array(); $xactions[] = id(new PhabricatorProjectTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) ->setMetadataValue('edge:type', $type_member) ->setNewValue($member_spec); $editor = id(new PhabricatorProjectTransactionEditor($project)) - ->setActor($user) + ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true) ->setContinueOnMissingFields(true) ->applyTransactions($project, $xactions); return id(new AphrontRedirectResponse())->setURI($project_uri); } $dialog = null; - switch ($this->action) { + switch ($action) { case 'leave': $dialog = new AphrontDialogView(); - $dialog->setUser($user); + $dialog->setUser($viewer); if ($this->userCannotLeave($project)) { $dialog->setTitle(pht('You can not leave this project.')); $body = pht('The membership is locked for this project.'); } else { $dialog->setTitle(pht('Really leave project?')); $body = pht( 'Your tremendous contributions to this project will be sorely '. 'missed. Are you sure you want to leave?'); $dialog->addSubmitButton(pht('Leave Project')); } $dialog->appendParagraph($body); $dialog->addCancelButton($project_uri); break; default: return new Aphront404Response(); } return id(new AphrontDialogResponse())->setDialog($dialog); } /** * This is enforced in @{class:PhabricatorProjectTransactionEditor}. We use * this logic to render a better form for users hitting this case. */ private function userCannotLeave(PhabricatorProject $project) { - $user = $this->getRequest()->getUser(); + $viewer = $this->getViewer(); return $project->getIsMembershipLocked() && !PhabricatorPolicyFilter::hasCapability( - $user, + $viewer, $project, PhabricatorPolicyCapability::CAN_EDIT); } } diff --git a/src/applications/project/controller/PhabricatorProjectViewController.php b/src/applications/project/controller/PhabricatorProjectViewController.php index a974010bc0..45329285df 100644 --- a/src/applications/project/controller/PhabricatorProjectViewController.php +++ b/src/applications/project/controller/PhabricatorProjectViewController.php @@ -1,56 +1,56 @@ getRequest(); - $user = $request->getUser(); + $viewer = $request->getViewer(); $query = id(new PhabricatorProjectQuery()) - ->setViewer($user) + ->setViewer($viewer) ->needMembers(true) ->needWatchers(true) ->needImages(true) ->needSlugs(true); $id = $request->getURIData('id'); $slug = $request->getURIData('slug'); if ($slug) { $query->withSlugs(array($slug)); } else { $query->withIDs(array($id)); } $project = $query->executeOne(); if (!$project) { return new Aphront404Response(); } $columns = id(new PhabricatorProjectColumnQuery()) - ->setViewer($user) + ->setViewer($viewer) ->withProjectPHIDs(array($project->getPHID())) ->execute(); if ($columns) { $controller = 'board'; } else { $controller = 'profile'; } switch ($controller) { case 'board': $controller_object = new PhabricatorProjectBoardViewController(); break; case 'profile': default: $controller_object = new PhabricatorProjectProfileController(); break; } return $this->delegateToController($controller_object); } } diff --git a/src/applications/project/controller/PhabricatorProjectWatchController.php b/src/applications/project/controller/PhabricatorProjectWatchController.php index b1c52e7870..53538f8393 100644 --- a/src/applications/project/controller/PhabricatorProjectWatchController.php +++ b/src/applications/project/controller/PhabricatorProjectWatchController.php @@ -1,97 +1,90 @@ id = $data['id']; - $this->action = $data['action']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); + $action = $request->getURIData('action'); $project = id(new PhabricatorProjectQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->needMembers(true) ->needWatchers(true) ->executeOne(); if (!$project) { return new Aphront404Response(); } $project_uri = $this->getApplicationURI('profile/'.$project->getID().'/'); // You must be a member of a project to if (!$project->isUserMember($viewer->getPHID())) { return new Aphront400Response(); } if ($request->isDialogFormPost()) { $edge_action = null; - switch ($this->action) { + switch ($action) { case 'watch': $edge_action = '+'; $force_subscribe = true; break; case 'unwatch': $edge_action = '-'; $force_subscribe = false; break; } $type_member = PhabricatorObjectHasWatcherEdgeType::EDGECONST; $member_spec = array( $edge_action => array($viewer->getPHID() => $viewer->getPHID()), ); $xactions = array(); $xactions[] = id(new PhabricatorProjectTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) ->setMetadataValue('edge:type', $type_member) ->setNewValue($member_spec); $editor = id(new PhabricatorProjectTransactionEditor($project)) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true) ->setContinueOnMissingFields(true) ->applyTransactions($project, $xactions); return id(new AphrontRedirectResponse())->setURI($project_uri); } $dialog = null; - switch ($this->action) { + switch ($action) { case 'watch': $title = pht('Watch Project?'); $body = pht( 'Watching a project will let you monitor it closely. You will '. 'receive email and notifications about changes to every object '. 'associated with projects you watch.'); $submit = pht('Watch Project'); break; case 'unwatch': $title = pht('Unwatch Project?'); $body = pht( 'You will no longer receive email or notifications about every '. 'object associated with this project.'); $submit = pht('Unwatch Project'); break; default: return new Aphront404Response(); } return $this->newDialog() ->setTitle($title) ->appendParagraph($body) ->addCancelButton($project_uri) ->addSubmitButton($submit); } }