1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-15 11:22:40 +01:00
phorge-phorge/src/applications/herald/controller/HeraldTestConsoleController.php

129 lines
3.9 KiB
PHP
Raw Normal View History

2011-03-24 21:49:21 +01:00
<?php
final class HeraldTestConsoleController extends HeraldController {
2011-03-24 21:49:21 +01:00
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$request = $this->getRequest();
$object_name = trim($request->getStr('object_name'));
$e_name = true;
$errors = array();
if ($request->isFormPost()) {
if (!$object_name) {
$e_name = pht('Required');
$errors[] = pht('An object name is required.');
2011-03-24 21:49:21 +01:00
}
if (!$errors) {
$object = id(new PhabricatorObjectQuery())
->setViewer($user)
->withNames(array($object_name))
->executeOne();
if (!$object) {
$e_name = pht('Invalid');
$errors[] = pht('No object exists with that name.');
2011-03-24 21:49:21 +01:00
}
if (!$errors) {
// TODO: Let the adapters claim objects instead.
2011-03-24 21:49:21 +01:00
if ($object instanceof DifferentialRevision) {
$adapter = HeraldDifferentialRevisionAdapter::newLegacyAdapter(
$object,
$object->loadActiveDiff());
2011-03-24 21:49:21 +01:00
} else if ($object instanceof PhabricatorRepositoryCommit) {
$data = id(new PhabricatorRepositoryCommitData())->loadOneWhere(
'commitID = %d',
$object->getID());
$adapter = HeraldCommitAdapter::newLegacyAdapter(
$object->getRepository(),
$object,
$data);
} else if ($object instanceof ManiphestTask) {
$adapter = id(new HeraldManiphestTaskAdapter())
->setTask($object);
} else if ($object instanceof PholioMock) {
$adapter = id(new HeraldPholioMockAdapter())
->setMock($object);
2011-03-24 21:49:21 +01:00
} else {
throw new Exception("Can not build adapter for object!");
}
$rules = id(new HeraldRuleQuery())
->setViewer($user)
->withContentTypes(array($adapter->getAdapterContentType()))
->withDisabled(false)
->needConditionsAndActions(true)
->needAppliedToPHIDs(array($object->getPHID()))
->needValidateAuthors(true)
->execute();
2011-03-24 21:49:21 +01:00
$engine = id(new HeraldEngine())
->setDryRun(true);
2011-03-24 21:49:21 +01:00
$effects = $engine->applyRules($rules, $adapter);
$engine->applyEffects($effects, $adapter, $rules);
2011-03-24 21:49:21 +01:00
$xscript = $engine->getTranscript();
return id(new AphrontRedirectResponse())
->setURI('/herald/transcript/'.$xscript->getID().'/');
}
}
}
if ($errors) {
$error_view = new AphrontErrorView();
$error_view->setTitle(pht('Form Errors'));
2011-03-24 21:49:21 +01:00
$error_view->setErrors($errors);
} else {
$error_view = null;
}
$text = pht(
'Enter an object to test rules for, like a Diffusion commit (e.g., '.
'rX123) or a Differential revision (e.g., D123). You will be shown '.
'the results of a dry run on the object.');
2011-03-24 21:49:21 +01:00
$form = id(new AphrontFormView())
->setUser($user)
->appendChild(
phutil_tag('p', array('class' => 'aphront-form-instructions'), $text))
2011-03-24 21:49:21 +01:00
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Object Name'))
2011-03-24 21:49:21 +01:00
->setName('object_name')
->setError($e_name)
->setValue($object_name))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Test Rules')));
2011-03-24 21:49:21 +01:00
$box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Herald Test Console'))
->setFormError($error_view)
->setForm($form);
General Herald refactoring pass Summary: **Who can delete global rules?**: I discussed this with @jungejason. The current behavior is that the rule author or any administrator can delete a global rule, but this isn't consistent with who can edit a rule (anyone) and doesn't really make much sense (it's an artifact of the global/personal split). I proposed that anyone can delete a rule but we don't actually delete them, and log the deletion. However, when it came time to actually write the code for this I backed off a bit and continued actually deleting the rules -- I think this does a reasonable job of balancing accountability with complexity. So the new impelmentation is: - Personal rules can be deleted only by their owners. - Global rules can be deleted by any user. - All deletes are logged. - Logs are more detailed. - All logged actions can be viewed in aggregate. **Minor Cleanup** - Merged `HomeController` and `AllController`. - Moved most queries to Query classes. - Use AphrontFormSelectControl::renderSelectTag() where appropriate (this is a fairly recent addition). - Use an AphrontErrorView to render the dry run notice (this didn't exist when I ported). - Reenable some transaction code (this works again now). - Removed the ability for admins to change rule authors (this was a little buggy, messy, and doesn't make tons of sense after the personal/global rule split). - Rules which depend on other rules now display the right options (all global rules, all your personal rules for personal rules). - Fix a bug in AphrontTableView where the "no data" cell would be rendered too wide if some columns are not visible. - Allow selectFilter() in AphrontNavFilterView to be called without a 'default' argument. Test Plan: - Browsed, created, edited, deleted personal and gules. - Verified generated logs. - Did some dry runs. - Verified transcript list and transcript details. - Created/edited all/any rules; created/edited once/every time rules. - Filtered admin views by users. Reviewers: jungejason, btrahan Reviewed By: btrahan CC: aran, epriestley Differential Revision: https://secure.phabricator.com/D2040
2012-03-30 19:49:55 +02:00
$crumbs = id($this->buildApplicationCrumbs())
->addTextCrumb(
pht('Transcripts'),
$this->getApplicationURI('/transcript/'))
->addTextCrumb(pht('Test Console'));
return $this->buildApplicationPage(
$box,
2011-03-24 21:49:21 +01:00
array(
'title' => pht('Test Console'),
'device' => true,
2011-03-24 21:49:21 +01:00
));
}
}