public function processRequest()
 {
     $can_edit = $this->requireApplicationCapability(NuanceSourceManageCapability::CAPABILITY);
     $request = $this->getRequest();
     $user = $request->getUser();
     $source_id = $this->getSourceID();
     $is_new = !$source_id;
     if ($is_new) {
         $source = NuanceSource::initializeNewSource($user);
     } else {
         $source = id(new NuanceSourceQuery())->setViewer($user)->withIDs(array($source_id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     }
     if (!$source) {
         return new Aphront404Response();
     }
     $definition = NuanceSourceDefinition::getDefinitionForSource($source);
     $definition->setActor($user);
     $response = $definition->buildEditLayout($request);
     if ($response instanceof AphrontResponse) {
         return $response;
     }
     $layout = $response;
     $crumbs = $this->buildApplicationCrumbs();
     return $this->buildApplicationPage(array($crumbs, $layout), array('title' => $definition->getEditTitle()));
 }
Ejemplo n.º 2
0
 public static function initializeNewSource(PhabricatorUser $actor)
 {
     $app = id(new PhabricatorApplicationQuery())->setViewer($actor)->withClasses(array('PhabricatorNuanceApplication'))->executeOne();
     $view_policy = $app->getPolicy(NuanceSourceDefaultViewCapability::CAPABILITY);
     $edit_policy = $app->getPolicy(NuanceSourceDefaultEditCapability::CAPABILITY);
     $definitions = NuanceSourceDefinition::getAllDefinitions();
     $lucky_definition = head($definitions);
     return id(new NuanceSource())->setViewPolicy($view_policy)->setEditPolicy($edit_policy)->setType($lucky_definition->getSourceTypeConstant());
 }
 private function buildPropertyView(NuanceSource $source, PhabricatorActionListView $actions)
 {
     $viewer = $this->getRequest()->getUser();
     $properties = id(new PHUIPropertyListView())->setUser($viewer)->setObject($source)->setActionList($actions);
     $definition = NuanceSourceDefinition::getDefinitionForSource($source);
     $properties->addProperty(pht('Source Type'), $definition->getName());
     $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions($viewer, $source);
     $properties->addProperty(pht('Editable By'), $descriptions[PhabricatorPolicyCapability::CAN_EDIT]);
     return $properties;
 }
Ejemplo n.º 4
0
 public function getDefinition()
 {
     if ($this->definition === null) {
         $definitions = NuanceSourceDefinition::getAllDefinitions();
         if (isset($definitions[$this->getType()])) {
             $definition = clone $definitions[$this->getType()];
             $definition->setSourceObject($this);
             $this->definition = $definition;
         }
     }
     return $this->definition;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $source = id(new NuanceSourceQuery())->setViewer($viewer)->withIDs(array($request->getURIData('id')))->executeOne();
     if (!$source) {
         return new Aphront404Response();
     }
     $def = NuanceSourceDefinition::getDefinitionForSource($source);
     $def->setActor($viewer);
     $response = $def->handleActionRequest($request);
     if ($response instanceof AphrontResponse) {
         return $response;
     }
     $title = $source->getName();
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb($title);
     return $this->buildApplicationPage(array($crumbs, $response), array('title' => $title));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $can_edit = $this->requireApplicationCapability(NuanceSourceManageCapability::CAPABILITY);
     $viewer = $this->getViewer();
     $sources_uri = $this->getApplicationURI('source/');
     $source_id = $request->getURIData('id');
     $is_new = !$source_id;
     if ($is_new) {
         $source = NuanceSource::initializeNewSource($viewer);
         $type = $request->getURIData('type');
         $map = NuanceSourceDefinition::getAllDefinitions();
         if (empty($map[$type])) {
             return new Aphront404Response();
         }
         $source->setType($type);
         $cancel_uri = $sources_uri;
     } else {
         $source = id(new NuanceSourceQuery())->setViewer($viewer)->withIDs(array($source_id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
         if (!$source) {
             return new Aphront404Response();
         }
         $cancel_uri = $source->getURI();
     }
     $definition = NuanceSourceDefinition::getDefinitionForSource($source);
     $definition->setActor($viewer);
     $response = $definition->buildEditLayout($request);
     if ($response instanceof AphrontResponse) {
         return $response;
     }
     $layout = $response;
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Sources'), $sources_uri);
     if ($is_new) {
         $crumbs->addTextCrumb(pht('New'));
     } else {
         $crumbs->addTextCrumb($source->getName(), $cancel_uri);
         $crumbs->addTextCrumb(pht('Edit'));
     }
     return $this->buildApplicationPage(array($crumbs, $layout), array('title' => $definition->getEditTitle()));
 }
Ejemplo n.º 7
0
 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn)
 {
     $where = parent::buildWhereClauseParts($conn);
     if ($this->types !== null) {
         $where[] = qsprintf($conn, 'source.type IN (%Ls)', $this->types);
     }
     if ($this->ids !== null) {
         $where[] = qsprintf($conn, 'source.id IN (%Ld)', $this->ids);
     }
     if ($this->phids !== null) {
         $where[] = qsprintf($conn, 'source.phid IN (%Ls)', $this->phids);
     }
     if ($this->isDisabled !== null) {
         $where[] = qsprintf($conn, 'source.isDisabled = %d', (int) $this->isDisabled);
     }
     if ($this->hasCursors !== null) {
         $cursor_types = array();
         $definitions = NuanceSourceDefinition::getAllDefinitions();
         foreach ($definitions as $key => $definition) {
             if ($definition->hasImportCursors()) {
                 $cursor_types[] = $key;
             }
         }
         if ($this->hasCursors) {
             if (!$cursor_types) {
                 throw new PhabricatorEmptyQueryException();
             } else {
                 $where[] = qsprintf($conn, 'source.type IN (%Ls)', $cursor_types);
             }
         } else {
             if (!$cursor_types) {
                 // Apply no constraint.
             } else {
                 $where[] = qsprintf($conn, 'source.type NOT IN (%Ls)', $cursor_types);
             }
         }
     }
     return $where;
 }
 private function buildSourceTypeResponse($cancel_uri)
 {
     $viewer = $this->getViewer();
     $request = $this->getRequest();
     $map = NuanceSourceDefinition::getAllDefinitions();
     $errors = array();
     $e_source = null;
     if ($request->isFormPost()) {
         $errors[] = pht('You must choose a source type.');
         $e_source = pht('Required');
     }
     $source_types = id(new AphrontFormRadioButtonControl())->setName('sourceType')->setLabel(pht('Source Type'));
     foreach ($map as $type => $definition) {
         $source_types->addButton($type, $definition->getName(), $definition->getSourceDescription());
     }
     $form = id(new AphrontFormView())->setUser($viewer)->appendChild($source_types)->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Continue'))->addCancelButton($cancel_uri));
     $box = id(new PHUIObjectBoxView())->setFormErrors($errors)->setHeaderText(pht('Choose Source Type'))->appendChild($form);
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Sources'), $cancel_uri);
     $crumbs->addTextCrumb(pht('New'));
     return $this->newPage()->setTitle(pht('Choose Source Type'))->setCrumbs($crumbs)->appendChild($box);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $can_edit = $this->requireApplicationCapability(NuanceSourceManageCapability::CAPABILITY);
     $viewer = $this->getViewer();
     $map = NuanceSourceDefinition::getAllDefinitions();
     $cancel_uri = $this->getApplicationURI('source/');
     if ($request->isFormPost()) {
         $type = $request->getStr('type');
         if (isset($map[$type])) {
             $uri = $this->getApplicationURI('source/new/' . $type . '/');
             return id(new AphrontRedirectResponse())->setURI($uri);
         }
     }
     $source_types = id(new AphrontFormRadioButtonControl())->setName('type')->setLabel(pht('Source Type'));
     foreach ($map as $type => $definition) {
         $source_types->addButton($type, $definition->getName(), $definition->getSourceDescription());
     }
     $form = id(new AphrontFormView())->setUser($viewer)->appendChild($source_types)->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Continue'))->addCancelButton($cancel_uri));
     $box = id(new PHUIObjectBoxView())->setHeaderText(pht('Choose Source Type'))->appendChild($form);
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Sources'), $cancel_uri);
     $crumbs->addTextCrumb(pht('New'));
     return $this->buildApplicationPage(array($crumbs, $box), array('title' => pht('Choose Source Type')));
 }
 protected function buildTransactions(AphrontRequest $request)
 {
     $transactions = parent::buildTransactions($request);
     // TODO -- as above
     return $transactions;
 }
 public function testGetAllTypes()
 {
     NuanceSourceDefinition::getAllDefinitions();
     $this->assertTrue(true);
 }