From 8fd97f4352354cf2ab538c04d8d72b2e337feada Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 16 Jul 2012 09:40:10 -0700 Subject: [PATCH] When users submit a no-op edit in Phriction, don't update the document Summary: See T1501. When users mash "save", stop them if they didn't change anything. Also, don't default-fill the "edit notes" field with the previous notes. This is meant to be more like a commit message for your changes. Test Plan: Edited a document with no changes, got a dialog. Edited a document with a title change only and a description change only, things worked. Edited a document with a previous "Edit notes", got a blank default fill. Reviewers: alanh, btrahan, vrana Reviewed By: vrana CC: aran Maniphest Tasks: T1501 Differential Revision: https://secure.phabricator.com/D2978 --- .../controller/PhrictionEditController.php | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/applications/phriction/controller/PhrictionEditController.php b/src/applications/phriction/controller/PhrictionEditController.php index d896169b0a..935fff78db 100644 --- a/src/applications/phriction/controller/PhrictionEditController.php +++ b/src/applications/phriction/controller/PhrictionEditController.php @@ -103,10 +103,12 @@ final class PhrictionEditController require_celerity_resource('phriction-document-css'); $e_title = true; + $notes = null; $errors = array(); if ($request->isFormPost()) { $title = $request->getStr('title'); + $notes = $request->getStr('description'); if (!strlen($title)) { $e_title = 'Required'; @@ -115,12 +117,27 @@ final class PhrictionEditController $e_title = null; } + if ($document->getID()) { + if ($content->getTitle() == $title && + $content->getContent() == $request->getStr('content')) { + + $dialog = new AphrontDialogView(); + $dialog->setUser($user); + $dialog->setTitle('No Edits'); + $dialog->appendChild( + '

You did not make any changes to the document.

'); + $dialog->addCancelButton($request->getRequestURI()); + + return id(new AphrontDialogResponse())->setDialog($dialog); + } + } + if (!count($errors)) { $editor = id(PhrictionDocumentEditor::newForSlug($document->getSlug())) ->setUser($user) ->setTitle($title) ->setContent($request->getStr('content')) - ->setDescription($request->getStr('description')); + ->setDescription($notes); $editor->save(); @@ -195,6 +212,7 @@ final class PhrictionEditController $form = id(new AphrontFormView()) ->setUser($user) + ->setWorkflow(true) ->setAction($request->getRequestURI()->getPath()) ->addHiddenInput('slug', $document->getSlug()) ->addHiddenInput('nodraft', $request->getBool('nodraft')) @@ -220,7 +238,7 @@ final class PhrictionEditController ->appendChild( id(new AphrontFormTextControl()) ->setLabel('Edit Notes') - ->setValue($content->getDescription()) + ->setValue($notes) ->setError(null) ->setName('description')) ->appendChild(