Author: sevein
Date: Mon Jan 30 17:03:34 2012
New Revision: 10779

Log:
Add security section in the settings page

Added:
   trunk/lib/form/SettingsSecurityForm.class.php
Modified:
   trunk/apps/qubit/modules/settings/actions/listAction.class.php
   trunk/apps/qubit/modules/settings/templates/listSuccess.php
   trunk/lib/form/SettingsGlobalForm.class.php
   trunk/lib/form/SettingsJobSchedulingForm.class.php

Modified: trunk/apps/qubit/modules/settings/actions/listAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/settings/actions/listAction.class.php      Mon Jan 
30 16:15:48 2012        (r10778)
+++ trunk/apps/qubit/modules/settings/actions/listAction.class.php      Mon Jan 
30 17:03:34 2012        (r10779)
@@ -65,6 +65,8 @@
       'settings' => QubitSetting::getByScope('ui_label'), 'scope'=>'ui_label', 
'fieldsRequired' => false));
     $this->oaiRepositoryForm = new SettingsOaiRepositoryForm;
     $this->jobSchedulingForm = new SettingsJobSchedulingForm;
+    $this->securityForm = new SettingsSecurityForm;
+
     $this->initializeDefaultPageElementsForm();
 
     // Handle POST data (form submit)
@@ -151,6 +153,18 @@
         }
       }
 
+      // Handle security form submission
+      if (null !== $request->security)
+      {
+        $this->securityForm->bind($request->security);
+        if ($this->securityForm->isValid())
+        {
+          // Do update and redirect to avoid repeat submit wackiness
+          $this->updateSecuritySettings($this->securityForm);
+          $this->redirect('settings/list');
+        }
+      }
+
       if (null !== $languageCode = $request->languageCode)
       {
         try
@@ -182,6 +196,7 @@
     $this->populateUiLabelForm($this->uiLabelForm);
     $this->populateOaiRepositoryForm($this->oaiRepositoryForm);
     $this->populateJobSchedulingForm($this->jobSchedulingForm);
+    $this->populateSecurityForm($this->securityForm);
 
     // Last symfony 1.0 forms holdout
     $this->i18nLanguages = QubitSetting::getByScope('i18n_languages');
@@ -219,8 +234,6 @@
     $showTooltips = QubitSetting::getSettingByName('show_tooltips');
     $defaultPubStatus = QubitSetting::getSettingByName('defaultPubStatus');
     $swordDepositDir = QubitSetting::getSettingByName('sword_deposit_dir');
-    $requireSslAdmin = QubitSetting::getSettingByName('require_ssl_admin');
-    $requireStrongPasswords = 
QubitSetting::getSettingByName('require_strong_passwords');
 
     // Set defaults for global form
     $this->globalForm->setDefaults(array(
@@ -238,9 +251,7 @@
       'explode_multipage_files' => (isset($explodeMultipageFiles)) ? 
intval($explodeMultipageFiles->getValue(array('sourceCulture'=>true))) : 1,
       'show_tooltips' => (isset($showTooltips)) ? 
intval($showTooltips->getValue(array('sourceCulture'=>true))) : 1,
       'defaultPubStatus' => (isset($defaultPubStatus)) ? 
$defaultPubStatus->getValue(array('sourceCulture'=>true)) : 
QubitTerm::PUBLICATION_STATUS_DRAFT_ID,
-      'sword_deposit_dir' => (isset($swordDepositDir)) ? 
$swordDepositDir->getValue(array('sourceCulture'=>true)) : null,
-      'require_ssl_admin' => (isset($requireSslAdmin)) ? 
intval($requireSslAdmin->getValue(array('sourceCulture'=>true))) : 1,
-      'require_strong_passwords' => (isset($requireStrongPasswords)) ? 
intval($requireStrongPasswords->getValue(array('sourceCulture'=>true))) : 1
+      'sword_deposit_dir' => (isset($swordDepositDir)) ? 
$swordDepositDir->getValue(array('sourceCulture'=>true)) : null
     ));
   }
 
@@ -414,26 +425,6 @@
       $setting->save();
     }
 
-    // Require SSL for admin funcionality
-    if (null !== $requireSslAdmin = $thisForm->getValue('require_ssl_admin'))
-    {
-      $setting = QubitSetting::getSettingByName('require_ssl_admin');
-
-      // Force sourceCulture update to prevent discrepency in settings between 
cultures
-      $setting->setValue($requireSslAdmin, array('sourceCulture' => true));
-      $setting->save();
-    }
-
-    // Require strong passwords
-    if (null !== $requireStrongPasswords = 
$thisForm->getValue('require_strong_passwords'))
-    {
-      $setting = QubitSetting::getSettingByName('require_strong_passwords');
-
-      // Force sourceCulture update to prevent discrepency in settings between 
cultures
-      $setting->setValue($requireStrongPasswords, array('sourceCulture' => 
true));
-      $setting->save();
-    }
-
     return $this;
   }
 
@@ -622,8 +613,6 @@
       if (intval($resumptionTokenLimit) && $resumptionTokenLimit > 0)
       {
         $setting = QubitSetting::getSettingByName('resumption_token_limit');
-
-        // Force sourceCulture update to prevent discrepency in settings 
between cultures
         $setting->setValue($resumptionTokenLimit, 
array('sourceCulture'=>true));
         $setting->save();
       }
@@ -637,10 +626,8 @@
    */
   protected function populateJobSchedulingForm()
   {
-    // Get OAI Repository settings
     $useJobScheduler = QubitSetting::getSettingByName('use_job_scheduler');
 
-    // Set defaults for global form
     $this->jobSchedulingForm->setDefaults(array(
       'use_job_scheduler' => (isset($useJobScheduler)) ? 
intval($useJobScheduler->getValue(array('sourceCulture' => true))) : 1
     ));
@@ -653,13 +640,54 @@
   {
     $thisForm = $this->jobSchedulingForm;
 
-    // Job scheduler radio button
     if (null !== $useJobSchedulerValue = 
$thisForm->getValue('use_job_scheduler'))
     {
       $setting = QubitSetting::getSettingByName('use_job_scheduler');
+      $setting->setValue($useJobSchedulerValue, array('sourceCulture' => 
true));
+      $setting->save();
+    }
+
+    return $this;
+  }
+
+  /**
+   * Populate the security form
+   */
+  protected function populateSecurityForm()
+  {
+    $requireSslAdmin = QubitSetting::getSettingByName('require_ssl_admin');
+    $requireStrongPasswords = 
QubitSetting::getSettingByName('require_strong_passwords');
+
+    $this->securityForm->setDefaults(array(
+      'require_ssl_admin' => (isset($requireSslAdmin)) ? 
intval($requireSslAdmin->getValue(array('sourceCulture'=>true))) : 1,
+      'require_strong_passwords' => (isset($requireStrongPasswords)) ? 
intval($requireStrongPasswords->getValue(array('sourceCulture'=>true))) : 1
+    ));
+  }
+
+  /**
+   * Update the security settings
+   */
+  protected function updateSecuritySettings()
+  {
+    $thisForm = $this->securityForm;
+
+    // Require SSL for admin funcionality
+    if (null !== $requireSslAdmin = $thisForm->getValue('require_ssl_admin'))
+    {
+      $setting = QubitSetting::getSettingByName('require_ssl_admin');
 
       // Force sourceCulture update to prevent discrepency in settings between 
cultures
-      $setting->setValue($useJobSchedulerValue, array('sourceCulture' => 
true));
+      $setting->setValue($requireSslAdmin, array('sourceCulture' => true));
+      $setting->save();
+    }
+
+    // Require strong passwords
+    if (null !== $requireStrongPasswords = 
$thisForm->getValue('require_strong_passwords'))
+    {
+      $setting = QubitSetting::getSettingByName('require_strong_passwords');
+
+      // Force sourceCulture update to prevent discrepency in settings between 
cultures
+      $setting->setValue($requireStrongPasswords, array('sourceCulture' => 
true));
       $setting->save();
     }
 

Modified: trunk/apps/qubit/modules/settings/templates/listSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/settings/templates/listSuccess.php Mon Jan 30 
16:15:48 2012        (r10778)
+++ trunk/apps/qubit/modules/settings/templates/listSuccess.php Mon Jan 30 
17:03:34 2012        (r10779)
@@ -80,11 +80,7 @@
   <legend><?php echo __('Default page elements') ?></legend>
   <?php echo $defaultPageElementsForm->renderFormTag(url_for(array('module' => 
'sfThemePlugin')), array('style' => 'float: left;')) ?>
     <?php echo $defaultPageElementsForm->renderGlobalErrors() ?>
-    <div class="description">
-      <p>
-        <?php echo __('Enable or disable the display of certain page elements. 
Unless they have been overridden by a specific theme, these settings will be 
used site wide.') ?>
-      </p>
-    </div>
+    <p><?php echo __('Enable or disable the display of certain page elements. 
Unless they have been overridden by a specific theme, these settings will be 
used site wide.') ?></p>
     <table class="list">
 
       <thead>
@@ -286,3 +282,29 @@
   </table>
   </form>
 </fieldset>
+
+<!-- Security settings -->
+<fieldset class="collapsible collapsed">
+  <legend><?php echo __('Security') ?></legend>
+  <form action="<?php echo url_for('settings/list') ?>" method="post">
+  <table class="list">
+  <thead>
+    <tr>
+      <th width="30%"><?php echo __('Name')?></th>
+      <th><?php echo __('Value')?></th>
+    </tr>
+  </thead>
+  <tbody>
+    <?php echo $securityForm ?>
+    <tr>
+      <td>&nbsp;</td>
+      <td>
+        <div style="float: right; margin: 3px 8px 0 0;">
+          <input class="form-submit" type="submit" value="<?php echo 
__('Save') ?>"/>
+        </div>
+      </td>
+    </tr>
+  </tbody>
+  </table>
+  </form>
+</fieldset>

Modified: trunk/lib/form/SettingsGlobalForm.class.php
==============================================================================
--- trunk/lib/form/SettingsGlobalForm.class.php Mon Jan 30 16:15:48 2012        
(r10778)
+++ trunk/lib/form/SettingsGlobalForm.class.php Mon Jan 30 17:03:34 2012        
(r10779)
@@ -53,9 +53,7 @@
       'explode_multipage_files' => new 
sfWidgetFormSelectRadio(array('choices'=>array(1=>'yes', 0=>'no')), 
array('class'=>'radio')),
       'show_tooltips' => new 
sfWidgetFormSelectRadio(array('choices'=>array(1=>'yes', 0=>'no')), 
array('class'=>'radio')),
       'defaultPubStatus' => new 
sfWidgetFormSelectRadio(array('choices'=>array(QubitTerm::PUBLICATION_STATUS_DRAFT_ID=>__('Draft'),
 QubitTerm::PUBLICATION_STATUS_PUBLISHED_ID=>__('Published'))), 
array('class'=>'radio')),
-      'sword_deposit_dir' => new sfWidgetFormInput,
-      'require_ssl_admin' => new 
sfWidgetFormSelectRadio(array('choices'=>array(1=>'yes', 0=>'no')), 
array('class'=>'radio')),
-      'require_strong_passwords' => new 
sfWidgetFormSelectRadio(array('choices'=>array(1=>'yes', 0=>'no')), 
array('class'=>'radio'))
+      'sword_deposit_dir' => new sfWidgetFormInput
     ));
 
     // Add labels
@@ -96,8 +94,6 @@
       // 'explode_multipage_files' => __('')
       // 'show_tooltips' => __('')
       // 'sword_deposit_dir' => __('')
-      // 'require_ssl_admin' => __('')
-      // 'require_strong_passwords' => __('')
     ));
 
     // Reference image max. width validator
@@ -143,8 +139,6 @@
     $this->validatorSchema['show_tooltips'] = new 
sfValidatorInteger(array('required' => false));
     $this->validatorSchema['defaultPubStatus'] = new 
sfValidatorChoice(array('choices' => 
array(QubitTerm::PUBLICATION_STATUS_DRAFT_ID, 
QubitTerm::PUBLICATION_STATUS_PUBLISHED_ID)));
     $this->validatorSchema['sword_deposit_dir'] = new 
sfValidatorString(array('required' => false));
-    $this->validatorSchema['require_ssl_admin'] = new 
sfValidatorInteger(array('required' => false));
-    $this->validatorSchema['require_strong_passwords'] = new 
sfValidatorInteger(array('required' => false));
 
     // Set decorator
     $decorator = new QubitWidgetFormSchemaFormatterList($this->widgetSchema);

Modified: trunk/lib/form/SettingsJobSchedulingForm.class.php
==============================================================================
--- trunk/lib/form/SettingsJobSchedulingForm.class.php  Mon Jan 30 16:15:48 
2012        (r10778)
+++ trunk/lib/form/SettingsJobSchedulingForm.class.php  Mon Jan 30 17:03:34 
2012        (r10779)
@@ -52,7 +52,7 @@
     $this->widgetSchema->addFormFormatter('list', $decorator);
     $this->widgetSchema->setFormFormatterName('list');
 
-    // Set wrapper text for OAI Harvesting form settings
+    // Set wrapper text for job scheduling settings
     $this->widgetSchema->setNameFormat('job_scheduling[%s]');
   }
 }

Added: trunk/lib/form/SettingsSecurityForm.class.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/lib/form/SettingsSecurityForm.class.php       Mon Jan 30 17:03:34 
2012        (r10779)
@@ -0,0 +1,62 @@
+<?php
+
+/*
+ * This file is part of Qubit Toolkit.
+ *
+ * Qubit Toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Qubit Toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+ProjectConfiguration::getActive()->loadHelpers('I18N');
+
+/**
+ * Global form definition for settings module - with validation.
+ *
+ * @package    qubit
+ * @subpackage settings
+ * @version    svn: $Id$
+ */
+class SettingsSecurityForm extends sfForm
+{
+  public function configure()
+  {
+    // Build widgets
+    $this->setWidgets(array(
+      'require_ssl_admin' => new 
sfWidgetFormSelectRadio(array('choices'=>array(1=>'yes', 0=>'no')), 
array('class'=>'radio')),
+      'require_strong_passwords' => new 
sfWidgetFormSelectRadio(array('choices'=>array(1=>'yes', 0=>'no')), 
array('class'=>'radio'))
+    ));
+
+    // Add labels
+    $this->widgetSchema->setLabels(array(
+      'require_ssl_admin' => __('Require SSL for all administrator 
funcionality'),
+      'require_strong_passwords' => __('Require strong passwords')
+    ));
+
+    // Add helper text
+    $this->widgetSchema->setHelps(array(
+      // 'require_ssl_admin' => __('')
+      // 'require_strong_passwords' => __('')
+    ));
+
+    $this->validatorSchema['require_ssl_admin'] = new 
sfValidatorInteger(array('required' => false));
+    $this->validatorSchema['require_strong_passwords'] = new 
sfValidatorInteger(array('required' => false));
+
+    // Set decorator
+    $decorator = new QubitWidgetFormSchemaFormatterList($this->widgetSchema);
+    $this->widgetSchema->addFormFormatter('list', $decorator);
+    $this->widgetSchema->setFormFormatterName('list');
+
+    // Set wrapper text for security settings
+    $this->widgetSchema->setNameFormat('security[%s]');
+  }
+}

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to