Commit 283827c9436899ab9aa9b66b4027a69acc359310

Authored by Brad Shuttleworth
1 parent 8fa23506

Bryn Divey <brynmor@jamwarehouse.com> 2006-01-19 Changed DB name in config (fo…

…r Brad's merging consum...
    Bryn Divey <brynmor@jamwarehouse.com> 2006-01-19 Fixed KTS-150 (validation on adding fieldsets to a...
    Bryn Divey <brynmor@jamwarehouse.com> 2006-01-19 Fixed more of workflow transitioning - added texta...
    Bryn Divey <brynmor@jamwarehouse.com> 2006-01-19 Fixed KTS-154 (validate workflow name). Added vali...
    Bryn Divey <brynmor@jamwarehouse.com> 2006-01-19 Fixed KTS-143 (validation on fieldsets). Added val...
    Bryn Divey <brynmor@jamwarehouse.com> 2006-01-18 Validation for blanks and dupes in workflow, state...
    Bryn Divey <brynmor@jamwarehouse.com> 2006-01-18 Fixed KTS-155 (duplicate workflow name)
    Bryn Divey <brynmor@jamwarehouse.com> 2006-01-18 Fixed KTS-149 (DocumentType creation - duplicate n...
    Bryn Divey <brynmor@jamwarehouse.com> 2006-01-18 Fixed KTS-156 (Checkout validation)
    Bryn Divey <brynmor@jamwarehouse.com> 2006-01-18 Fixed KTS-157 (validation on state transition)
    Bryn Divey <brynmor@jamwarehouse.com> 2006-01-18 Merge, and KTS-126 (validation on user edit)


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4613 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/validation/dispatchervalidation.inc.php
... ... @@ -292,6 +292,29 @@ class KTDispatcherValidation {
292 292 }
293 293 return $sEmailAddress;
294 294 }
  295 +
  296 +
  297 + /* assuming something has a 'getList' static method, this may work */
  298 + function validateDuplicateName($sEntityTypeName, $sHumanEntityTypeName, $sName, $aOptions) {
  299 + $aMethod = array($sEntityTypeName, 'getList');
  300 +
  301 + $aList =& call_user_func($aMethod, "name = '$sName'");
  302 + if(count($aList)) {
  303 + $aOptions['message'] = KTUtil::arrayGet($aOptions, 'message', _("A $sHumanEntityTypeName with that name already exists"));
  304 + $this->handleError($aOptions);
  305 + }
  306 + return $sName;
  307 + }
  308 +
  309 + /* just does an empty string validation with an appropriate message, and then a duplicate name validation */
  310 + function validateEntityName($sEntityTypeName, $sHumanEntityTypeName, $sName, $aOptions) {
  311 + $aNewOptions = $aOptions;
  312 + $aNewOptions['message'] = KTUtil::arrayGet($aOptions, 'message', _("No name was given for the $sHumanEntityTypeName"));
  313 +
  314 + $this->validateString($sName, $aNewOptions);
  315 + $this->validateDuplicateName($sEntityTypeName, $sHumanEntityTypeName, $sName, $aOptions);
  316 + }
  317 +
295 318  
296 319 }
297 320  
... ...
plugins/ktcore/KTDocumentActions.php
... ... @@ -89,9 +89,14 @@ class KTDocumentCheckOutAction extends KTDocumentAction {
89 89 }
90 90  
91 91 function do_checkout() {
92   - $sReason = KTUtil::arrayGet($_REQUEST, 'reason');
93   - $this->oValidator->notEmpty($sReason);
  92 + $aErrorOptions = array(
  93 + 'redirect_to' => array('','fDocumentId=' . $this->oDocument->getId()),
  94 + 'message' => "You must provide a reason"
  95 + );
  96 +
94 97 $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkout_final');
  98 + $sReason = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'reason'), $aErrorOptions);
  99 +
95 100 $oTemplate->setData(array(
96 101 'context' => &$this,
97 102 'reason' => $sReason,
... ... @@ -623,7 +628,11 @@ class KTDocumentWorkflowAction extends KTDocumentAction {
623 628 }
624 629 $fieldOptions = array("vocab" => $aVocab);
625 630 $transition_fields[] = new KTLookupWidget(_('Transition to perform'), 'FIXME', 'fTransitionId', null, $this->oPage, true, null, $fieldErrors, $fieldOptions);
626   - $transition_fields[] = new KTStringWidget(_('Reason for transition'), _('Describe the changes made to the document.'), 'fComments', "", $this->oPage, true);
  631 + $transition_fields[] = new KTTextWidget(
  632 + _('Reason for transition'), _('Describe the changes made to the document.'),
  633 + 'fComments', "",
  634 + $this->oPage, true, null, null,
  635 + array('cols' => 80, 'rows' => 4));
627 636 }
628 637 $aTemplateData = array(
629 638 'oDocument' => $oDocument,
... ... @@ -650,8 +659,15 @@ class KTDocumentWorkflowAction extends KTDocumentAction {
650 659  
651 660 function do_performTransition() {
652 661 $oDocument =& $this->oValidator->validateDocument($_REQUEST['fDocumentId']);
653   - $oTransition =& $this->oValidator->validateWorkflowTransition($_REQUEST['fTransitionId']);
654   - $sComments =& $this->oValidator->notEmpty($_REQUEST['fComments']);
  662 + $oTransition =& $this->oValidator->validateWorkflowTransition($_REQUEST['fTransitionId']);
  663 +
  664 + $aErrorOptions = array(
  665 + 'redirect_to' => array('main', sprintf('fDocumentId=%d', $_REQUEST['fDocumentId'])),
  666 + 'message' => 'You must provide a reason for the transition'
  667 + );
  668 +
  669 + $sComments =& $this->oValidator->validateString($_REQUEST['fComments'], $aErrorOptions);
  670 +
655 671 $oUser =& User::get($_SESSION['userID']);
656 672 $res = KTWorkflowUtil::performTransitionOnDocument($oTransition, $oDocument, $oUser, $sComments);
657 673 $this->successRedirectToMain(_('Transition performed'),
... ...
plugins/ktcore/admin/documentFields.php
... ... @@ -106,6 +106,10 @@ class KTDocumentFieldDispatcher extends KTStandardDispatcher {
106 106  
107 107 // {{{ do_new
108 108 function do_new() {
  109 + $aErrorOptions = array(
  110 + 'redirect_to' => array('main'),
  111 + );
  112 +
109 113 $bIsGeneric = false;
110 114 $bIsSystem = false;
111 115  
... ... @@ -118,14 +122,19 @@ class KTDocumentFieldDispatcher extends KTStandardDispatcher {
118 122 // Can't be a system fieldset and a generic fieldset...
119 123 $bIsGeneric = false;
120 124 }
121   - $sName = KTUtil::arrayGet($_REQUEST, 'name');
122   - $sName = $this->oValidator->notEmpty($sName);
  125 +
  126 + // basic validation
  127 + $sName = $this->oValidator->validateEntityName("KTFieldset", "fieldset", KTUtil::arrayGet($_REQUEST, 'name'), $aErrorOptions);
  128 +
  129 + $sDescription = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'description'),
  130 + KTUtil::meldOptions($aErrorOptions, array('message' => "You must provide a description")));
  131 +
123 132 $sNamespace = KTUtil::arrayGet($_REQUEST, 'namespace');
124   - $sDescription = KTUtil::arrayGet($_REQUEST, 'description');
125   - $sDescription = $this->oValidator->notEmpty($sDescription);
  133 +
126 134 if (empty($sNamespace)) {
127 135 $sNamespace = KTUtil::nameToLocalNamespace('fieldsets', $sName);
128 136 }
  137 +
129 138 $res = KTFieldset::createFromArray(array(
130 139 'name' => $sName,
131 140 'namespace' => $sNamespace,
... ... @@ -207,6 +216,7 @@ class KTDocumentFieldDispatcher extends KTStandardDispatcher {
207 216 function do_editFieldObject() {
208 217 $oTemplating =& KTTemplating::getSingleton();
209 218 $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/editField');
  219 +
210 220 $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']);
211 221 $oField =& DocumentField::get($_REQUEST['fFieldId']);
212 222  
... ...
plugins/ktcore/admin/documentTypes.php
... ... @@ -32,13 +32,12 @@ class KTDocumentTypeDispatcher extends KTAdminDispatcher {
32 32 }
33 33  
34 34 function do_new() {
  35 + $sName = $this->oValidator->validateEntityName('DocumentType', 'document type', $_REQUEST['name'], array("redirect_to" => array("main")));
35 36  
36   -
37   -
38   - $sName = $_REQUEST['name'];
39 37 $oDocumentType =& DocumentType::createFromArray(array(
40 38 'name' => $sName,
41 39 ));
  40 +
42 41 if (PEAR::isError($oDocumentType)) {
43 42 $this->errorRedirectToMain(_('Could not create document type'));
44 43 exit(0);
... ... @@ -85,7 +84,7 @@ class KTDocumentTypeDispatcher extends KTAdminDispatcher {
85 84 $aOptions['vocab'] = $vocab;
86 85 $aOptions['multi'] = true;
87 86 $aOptions['size'] = 5;
88   - $availableTypesWidget =& new KTLookupWidget(_('Available Fieldsets'),_('Select the fieldsets which you wish to associate with this document type'), 'fieldsetid', null, $this->oPage, true,
  87 + $availableTypesWidget =& new KTLookupWidget(_('Available Fieldsets'),_('Select the fieldsets which you wish to associate with this document type'), 'fieldsetid[]', null, $this->oPage, true,
89 88 null, null, $aOptions);
90 89  
91 90 $this->aBreadcrumbs[] = array(
... ... @@ -102,9 +101,16 @@ class KTDocumentTypeDispatcher extends KTAdminDispatcher {
102 101 return $oTemplate;
103 102 }
104 103  
105   - function do_editobject() {
106   - $oDocumentType =& DocumentType::get($_REQUEST['fDocumentTypeId']);
107   - $oDocumentType->setName($_REQUEST['name']);
  104 + function do_editobject() {
  105 + $iDocumentTypeId = (int)$_REQUEST['fDocumentTypeId'];
  106 + $oDocumentType =& DocumentType::get($iDocumentTypeId);
  107 +
  108 + $aErrorOptions = array(
  109 + 'redirect_to' => array('edit', sprintf('fDocumentTypeId=%d', $iDocumentTypeId)),
  110 + );
  111 +
  112 + $sName = $this->oValidator->validateEntityName('DocumentType', 'document type', $_REQUEST['name'], $aErrorOptions);
  113 +
108 114 $res = $oDocumentType->update();
109 115 if (PEAR::isError($res) || ($res === false)) {
110 116 $this->errorRedirectTo('edit', _('Could not save document type changes'), 'fDocumentTypeId=' . $oDocumentType->getId());
... ... @@ -128,7 +134,14 @@ class KTDocumentTypeDispatcher extends KTAdminDispatcher {
128 134  
129 135 function do_addfieldsets() {
130 136 $oDocumentType =& DocumentType::get($_REQUEST['fDocumentTypeId']);
131   - $res = KTMetadataUtil::addSetsToDocumentType($oDocumentType, $_REQUEST['fieldsetid']);
  137 + $aFieldsetId = $_REQUEST['fieldsetid'];
  138 +
  139 + if(!count($aFieldsetId)) {
  140 + $this->errorRedirectTo('edit', _('You must select at least one fieldset'), 'fDocumentTypeId=' . $oDocumentType->getId());
  141 + exit(0);
  142 + }
  143 +
  144 + $res = KTMetadataUtil::addSetsToDocumentType($oDocumentType, $aFieldsetId);
132 145 if (PEAR::isError($res)) {
133 146 var_dump($res);
134 147 $this->errorRedirectTo('edit', _('Changes not saved'), 'fDocumentTypeId=' . $oDocumentType->getId());
... ...
plugins/ktcore/admin/userManagement.php
... ... @@ -285,14 +285,33 @@ class KTUserAdminDispatcher extends KTAdminDispatcher {
285 285  
286 286 function do_saveUser() {
287 287 $user_id = KTUtil::arrayGet($_REQUEST, 'user_id');
  288 +
  289 + $aErrorOptions = array(
  290 + 'redirect_to' => array('editUser', sprintf('user_id=%d', $user_id))
  291 + );
  292 +
  293 + $name = $this->oValidator->validateString(
  294 + KTUtil::arrayGet($_REQUEST, 'name'),
  295 + KTUtil::meldOptions($aErrorOptions, array('message' => _("You must provide a name")))
  296 + );
  297 +
  298 + $username = $this->oValidator->validateString(
  299 + KTUtil::arrayGet($_REQUEST, 'username'),
  300 + KTUtil::meldOptions($aErrorOptions, array('message' => _("You must provide a username")))
  301 + );
288 302  
289   - $name = KTUtil::arrayGet($_REQUEST, 'name');
290   - $username = KTUtil::arrayGet($_REQUEST, 'username');
291 303 $email_address = KTUtil::arrayGet($_REQUEST, 'email_address');
  304 + if(strlen(trim($email_address))) {
  305 + $email_address = $this->oValidator->validateEmailAddress($email_address, $aErrorOptions);
  306 + }
  307 +
292 308 $email_notifications = KTUtil::arrayGet($_REQUEST, 'email_notifications', false);
293 309 if ($email_notifications !== false) $email_notifications = true;
  310 +
294 311 $mobile_number = KTUtil::arrayGet($_REQUEST, 'mobile_number');
  312 +
295 313 $max_sessions = KTUtil::arrayGet($_REQUEST, 'max_sessions', '3');
  314 +
296 315 // FIXME more validation would be useful.
297 316 // validated and ready..
298 317 $this->startTransaction();
... ...
plugins/ktcore/admin/workflows.php
... ... @@ -68,7 +68,7 @@ class KTWorkflowDispatcher extends KTAdminDispatcher {
68 68  
69 69  
70 70 $add_transition_fields = array();
71   - $add_transition_fields[] = new KTStringWidget(_('Name'), _('A human-readable name for the state.'), 'fName', null, $this->oPage, true);
  71 + $add_transition_fields[] = new KTStringWidget(_('Name'), _('A human-readable name for the transition.'), 'fName', null, $this->oPage, true);
72 72 $aOptions = array();
73 73 $vocab = array();
74 74 foreach($aStates as $state) {
... ... @@ -113,21 +113,29 @@ class KTWorkflowDispatcher extends KTAdminDispatcher {
113 113 // {{{ do_saveWorkflow
114 114 function do_saveWorkflow() {
115 115 $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']);
  116 +
116 117 $aOptions = array(
117 118 'redirect_to' => array('editWorkflow', 'fWorkflowId=' . $oWorkflow->getId()),
118 119 );
119   - $oWorkflow->setName($_REQUEST['fName']);
120   - $oWorkflow->setHumanName($_REQUEST['fName']);
  120 +
  121 + $sName = $this->oValidator->validateString($_REQUEST['fName'], $aOptions);
  122 +
  123 + $oWorkflow->setName($sName);
  124 + $oWorkflow->setHumanName($sName);
  125 +
121 126 if (!empty($_REQUEST['fStartStateId'])) {
122 127 $oWorkflow->setStartStateId($_REQUEST['fStartStateId']);
123 128 } else {
124 129 $oWorkflow->setStartStateId(null);
125 130 }
  131 +
126 132 $res = $oWorkflow->update();
  133 +
127 134 $this->oValidator->notErrorFalse($res, array(
128 135 'redirect_to' => array('editWorkflow', 'fWorkflowId=' . $oWorkflow->getId()),
129 136 'message' => _('Error saving workflow'),
130 137 ));
  138 +
131 139 $this->successRedirectTo('editWorkflow', _('Changes saved'), 'fWorkflowId=' . $oWorkflow->getId());
132 140 exit(0);
133 141 }
... ... @@ -137,11 +145,16 @@ class KTWorkflowDispatcher extends KTAdminDispatcher {
137 145 function do_newWorkflow() {
138 146 $aErrorOptions = array(
139 147 'redirect_to' => array('main'),
140   - 'message' => 'No name given',
141 148 );
  149 +
142 150 $sName = KTUtil::arrayGet($_REQUEST, 'fName');
143   - $sName = $this->oValidator->validateString($sName,
144   - $aErrorOptions);
  151 + $sName = $this->oValidator->validateEntityName('KTWorkflow', 'workflow', $sName, $aErrorOptions);
  152 +
  153 +
  154 +/* if(!PEAR::isError(KTWorkflow::getByName($sName))) {
  155 + $this->errorRedirectToMain(_("A state with that name already exists"));
  156 + }*/
  157 +
145 158 $res = KTWorkflow::createFromArray(array(
146 159 'name' => $sName,
147 160 'humanname' => $sName,
... ... @@ -174,16 +187,34 @@ class KTWorkflowDispatcher extends KTAdminDispatcher {
174 187 //
175 188 // {{{ do_newState
176 189 function do_newState() {
177   - $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']);
  190 + $iWorkflowId = (int) $_REQUEST['fWorkflowId'];
  191 +
  192 + $aErrorOptions = array(
  193 + 'redirect_to' => array('editWorkflow', sprintf('fWorkflowId=%d', $iWorkflowId)),
  194 + );
  195 +
  196 + $oWorkflow =& $this->oValidator->validateWorkflow($iWorkflowId);
  197 +
  198 + // validate name
  199 + $sName = $this->oValidator->validateString($_REQUEST['fName'], $aErrorOptions);
  200 +
  201 + // check there are no other states by that name in this workflow
  202 + $aStates = KTWorkflowState::getList(sprintf("workflow_id = %d and name = '%s'", $iWorkflowId, $sName));
  203 + if(count($aStates)) {
  204 + $this->errorRedirectTo(implode('&', $aErrorOptions['redirect_to']), _("A state by that name already exists"));
  205 + }
  206 +
178 207 $oState = KTWorkflowState::createFromArray(array(
179 208 'workflowid' => $oWorkflow->getId(),
180   - 'name' => $_REQUEST['fName'],
181   - 'humanname' => $_REQUEST['fName'],
  209 + 'name' => $sName,
  210 + 'humanname' => $sName,
182 211 ));
  212 +
183 213 $this->oValidator->notError($oState, array(
184 214 'redirect_to' => array('editWorkflow', 'fWorkflowId=' . $oWorkflow->getId()),
185 215 'message' => _('Could not create workflow state'),
186 216 ));
  217 +
187 218 $this->successRedirectTo('editState', _('Workflow state created'), 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId());
188 219 exit(0);
189 220 }
... ... @@ -326,9 +357,28 @@ class KTWorkflowDispatcher extends KTAdminDispatcher {
326 357 function do_newTransition() {
327 358 $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']);
328 359 $oState =& $this->oValidator->validateWorkflowState($_REQUEST['fTargetStateId']);
  360 +
  361 + // setup error options for later
  362 + $aErrorOptions = array(
  363 + 'redirect_to' => array('editWorkflow', sprintf('fWorkflowId=%d', $oWorkflow->getId())),
  364 + );
  365 +
329 366 $iPermissionId = KTUtil::arrayGet($_REQUEST, 'fPermissionId');
330 367 $iGroupId = KTUtil::arrayGet($_REQUEST, 'fGroupId');
331 368 $iRoleId = KTUtil::arrayGet($_REQUEST, 'fRoleId');
  369 +
  370 + // validate name
  371 + $sName = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'fName'), $aErrorOptions);
  372 +
  373 +
  374 + // check there are no other transitions by that name in this workflow
  375 + $aTransitions = KTWorkflowTransition::getList(sprintf("workflow_id = %d and name = '%s'", $oWorkflow->getId(), $sName));
  376 + if(count($aTransitions)) {
  377 + $this->errorRedirectTo(implode('&', $aErrorOptions['redirect_to']), _("A transition by that name already exists"));
  378 + }
  379 +
  380 +
  381 + // validate permissions, roles, and group
332 382 if ($iPermissionId) {
333 383 $this->oValidator->validatePermission($_REQUEST['fPermissionId']);
334 384 }
... ... @@ -338,6 +388,7 @@ class KTWorkflowDispatcher extends KTAdminDispatcher {
338 388 if ($iRoleId) {
339 389 $this->oValidator->validateRole($_REQUEST['fRoleId']);
340 390 }
  391 +
341 392 $res = KTWorkflowTransition::createFromArray(array(
342 393 'workflowid' => $oWorkflow->getId(),
343 394 'name' => $_REQUEST['fName'],
... ...
preferences.php
... ... @@ -72,9 +72,9 @@ class PreferencesDispatcher extends KTStandardDispatcher {
72 72 $confirm_password = KTUtil::arrayGet($_REQUEST, 'confirm_password');
73 73  
74 74 if (empty($password)) {
75   - $this->errorRedirectToMain(_("You must specify a password for the user."));
  75 + $this->errorRedirect("setPassword", _("You must specify a password."));
76 76 } else if ($password !== $confirm_password) {
77   - $this->errorRedirectToMain(_("The passwords you specified do not match."));
  77 + $this->errorRedirect("setPassword", _("The passwords you specified do not match."));
78 78 }
79 79  
80 80 $KTConfig =& KTConfig::getSingleton();
... ...
templates/ktcore/principals/password.smarty
... ... @@ -14,8 +14,10 @@
14 14  
15 15 <div class="form_actions">
16 16 <input type="submit" value="{i18n}Change your password{/i18n}" />
  17 +
17 18 <!-- FIXME add CSS for secondary actions. -->
18   - <p><a href="?action=setPassword">{i18n}Change your password.{/i18n}</a></p>
  19 + <!-- Commenting this out due to redundancy. Why is it here?
  20 + <p><a href="?action=setPassword">{i18n}Change your password.{/i18n}</a></p> -->
19 21 </div>
20 22 </fieldset>
21 23  
... ...
templates/ktcore/workflow/editWorkflow.smarty
... ... @@ -52,6 +52,8 @@ title=&quot;State {$oState-&gt;getId()}&quot;&gt;{$oState-&gt;getName()|escape}&lt;/a&gt;&lt;/li&gt;
52 52  
53 53  
54 54  
  55 +{* check that there are states, and, if not, don't show transitions *}
  56 +{if $aStates}
55 57  
56 58 <h3>{i18n}Transitions{/i18n}</h3>
57 59  
... ... @@ -87,6 +89,7 @@ title=&quot;Transition {$oTransition-&gt;getId()}&quot;&gt;{$oTransition-&gt;getName()|escape}&lt;/a&gt;&lt;
87 89 </ul>
88 90 {/if}
89 91  
  92 +{/if}
90 93  
91 94  
92 95  
... ...