jenkins-bot has submitted this change and it was merged. Change subject: Add review settings page for Admin ......................................................................
Add review settings page for Admin Bug: 64011 Co-Authored-By: Niharika <niharikakohl...@gmail.com> Change-Id: I22c509d4a44db95bf87c23122404bb4be19831ac --- M data/i18n/en.json M data/i18n/qqq.json A data/templates/admin/settings.html M data/templates/base_auth.html M src/Wikimania/Scholarship/App.php A src/Wikimania/Scholarship/Controllers/Admin/Settings.php M src/Wikimania/Scholarship/Dao/Settings.php 7 files changed, 215 insertions(+), 5 deletions(-) Approvals: BryanDavis: Looks good to me, approved jenkins-bot: Verified diff --git a/data/i18n/en.json b/data/i18n/en.json index 22cc683..9dd0be2 100644 --- a/data/i18n/en.json +++ b/data/i18n/en.json @@ -21,6 +21,7 @@ "nav-admin": "Admin", "nav-users": "Manage users", "nav-account": "My Account", + "nav-settings": "Settings", "mock": "This is a mock scholarship application site only, use it just for testing.", @@ -268,5 +269,10 @@ "csrf-heading": "Invalid request", "csrf-message": "The request that was submitted was missing the request forgery protection token. Please return to the form, reload the page and try again.", - "search-region": "Geographic region:" + "search-region": "Geographic region:", + "admin-settings-phase1pass": "Phase 1 pass score:", + "admin-settings-phase2pass": "Phase 2 pass score:", + "admin-settings-weightonwiki": "Weight of contributions to Wikimedia:", + "admin-settings-weightoffwiki": "Weight of contributions other than Wikimedia:", + "admin-settings-weightinterest": "Weight of Interest:" } diff --git a/data/i18n/qqq.json b/data/i18n/qqq.json index 80ab914..d7085f2 100644 --- a/data/i18n/qqq.json +++ b/data/i18n/qqq.json @@ -22,6 +22,7 @@ "nav-admin": "Navigation menu label for list of administrative pages.\n{{Identical|Admin}}", "nav-users": "Navigation menu label, links to user list page", "nav-account": "Navigation menu label for list of pages specific to the authenticated user's account.\n{{Identical|My account}}", + "nav-settings": "Navigation menu label, for settings page", "mock": "Disclaimer shown on scholarship request form when application is being used for testing and development", "not-open": "Content for site landing page before date that scholarship request will be accepted", "deadline-passed": "Content for site landing page after scholarship request period has closed", @@ -235,5 +236,10 @@ "no-results": "Content for report with no results", "csrf-heading": "Header for cross site request forgery (CSRF) error page", "csrf-message": "Cross site request forgery (CSRF) error page body", - "search-region": "Input label, followed by text box" + "search-region": "Input label, followed by text box", + "admin-settings-phase1pass": "Input label, for phase 1 pass score", + "admin-settings-phase2pass": "Input label, for [hase 2 pass score", + "admin-settings-weightonwiki": "Input label, for weight of contributions to Wikimedia", + "admin-settings-weightoffwiki": "Input label, for weight of contributions other than Wikimedia", + "admin-settings-weightinterest": "Input label, for weight of Interest" } \ No newline at end of file diff --git a/data/templates/admin/settings.html b/data/templates/admin/settings.html new file mode 100644 index 0000000..35b3b5e --- /dev/null +++ b/data/templates/admin/settings.html @@ -0,0 +1,68 @@ +{% extends "admin/base.html" %} + +{% set errors = flash.form_errors|default([]) %} +{% if flash.form_defaults|default(false) %} +{% set set = flash.form_defaults %} +{% endif %} + +{% block content %} +{% spaceless %} +<ol class="breadcrumb"> + <li>{{ wgLang.message( 'nav-admin' ) }}</li> + <li>{{ wgLang.message( 'nav-settings' ) }}</li> +</ol> + +<form class="form-horizontal" method="post" action="{{ urlFor( 'admin_settings_post' ) }}"> + <input type="hidden" name="{{ csrf_param }}" value="{{ csrf_token }}" /> + <div class="form-group"> + <label for="phase1pass" class="col-sm-2 control-label"> + {{ wgLang.message( 'admin-settings-phase1pass' ) }} + </label> + <div class="col-sm-5"> + <input type="text" class="form-control" id="phase1pass" name="phase1pass" value="{{ set.phase1pass }}" required="required"> + </div> + </div> + + <div class="form-group"> + <label for="phase2pass" class="col-sm-2 control-label"> + {{ wgLang.message( 'admin-settings-phase2pass' ) }} + </label> + <div class="col-sm-5"> + <input type="text" class="form-control" name="phase2pass" id="phase2pass" value="{{ set.phase2pass }}" required="required"> + </div> + </div> + + <div class="form-group"> + <label for="weightonwiki" class="col-sm-2 control-label"> + {{ wgLang.message( 'admin-settings-weightonwiki' ) }} + </label> + <div class="col-sm-5"> + <input type="text" class="form-control" name="weightonwiki" id="weightonwiki" value="{{ set.weightonwiki }}" required="required"> + </div> + </div> + + <div class="form-group"> + <label for="weightoffwiki" class="col-sm-2 control-label"> + {{ wgLang.message( 'admin-settings-weightoffwiki' ) }} + </label> + <div class="col-sm-5"> + <input type="text" class="form-control" name="weightoffwiki" id="weightoffwiki" value="{{ set.weightoffwiki }}" required="required"> + </div> + </div> + + <div class="form-group"> + <label for="weightinterest" class="col-sm-2 control-label"> + {{ wgLang.message( 'admin-settings-weightinterest' ) }} + </label> + <div class="col-sm-5"> + <input type="text" class="form-control" name="weightinterest" id="weightinterest" value="{{ set.weightinterest }}" required="required"> + </div> + </div> + + <div class="col-sm-10 col-sm-offset-2"> + <input type="submit" class="btn btn-default" id="save" name="save" value="{{ wgLang.message( 'review-view-save' ) }}"/> + </div> +</form> +{% endspaceless %} +{% endblock content %} + diff --git a/data/templates/base_auth.html b/data/templates/base_auth.html index 0538ed8..7fae97a 100644 --- a/data/templates/base_auth.html +++ b/data/templates/base_auth.html @@ -41,6 +41,7 @@ <ul class="dropdown-menu"> <li><a href="{{ urlFor( 'admin_users' ) }}">{{ wgLang.message( 'nav-users' ) }}</a></li> <li><a href="{{ urlFor( 'admin_user', { 'id':'new' } ) }}">{{ wgLang.message( 'admin-users-add' ) }}</a></li> + <li><a href="{{ urlFor( 'admin_settings' ) }}">{{ wgLang.message( 'nav-settings' ) }}</a></li> </ul> </li> {% endif %} diff --git a/src/Wikimania/Scholarship/App.php b/src/Wikimania/Scholarship/App.php index af4b18d..d721506 100644 --- a/src/Wikimania/Scholarship/App.php +++ b/src/Wikimania/Scholarship/App.php @@ -469,6 +469,18 @@ $page( $id ); })->name( 'admin_user' ); + $slim->get( 'settings', function () use ( $slim ) { + $page = new Controllers\Admin\Settings( $slim ); + $page->setDao( $slim->settingsDao ); + $page(); + })->name( 'admin_settings' ); + + $slim->post( 'settings.post', function () use ( $slim ) { + $page = new Controllers\Admin\Settings( $slim ); + $page->setDao( $slim->settingsDao ); + $page(); + })->name( 'admin_settings_post' ); + $slim->post( 'user.post', function () use ( $slim ) { $page = new Controllers\Admin\User( $slim ); $page->setDao( $slim->userDao ); diff --git a/src/Wikimania/Scholarship/Controllers/Admin/Settings.php b/src/Wikimania/Scholarship/Controllers/Admin/Settings.php new file mode 100644 index 0000000..78b686d --- /dev/null +++ b/src/Wikimania/Scholarship/Controllers/Admin/Settings.php @@ -0,0 +1,84 @@ +<?php +/** + * @section LICENSE + * This file is part of Wikimania Scholarship Application. + * + * Wikimania Scholarship Application is free software: you can redistribute it + * and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * Wikimania Scholarship Application 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 Wikimania Scholarship Application. If not, see + * <http://www.gnu.org/licenses/>. + * + * @file + */ + +namespace Wikimania\Scholarship\Controllers\Admin; + +use Wikimania\Scholarship\Controller; + +/** + * View/edit Review Settings + * + * @author Kushal Khandelwal <kushal...@wikimedia.org> + * @author Niharika Kohli <niharikakohl...@gmail.com> + * @copyright © 2014 Wikimedia Foundation and contributors. + */ +class Settings extends Controller { + + protected function handleGet() { + $settings = $this->dao->getSettings(); + $this->view->set( 'set', $settings ); + $this->render( 'admin/settings.html' ); + } + + + protected function handlePost() { + $this->form->expectInt( 'phase1pass', array( 'required' => true ) ); + $this->form->expectInt( 'phase2pass', array( 'required' => true ) ); + $this->form->expectFloat( 'weightonwiki', array( 'required' => true ) ); + $this->form->expectFloat( 'weightoffwiki', array( + 'required' => true, + ) ); + $this->form->expectFloat( 'weightinterest', array( + 'required' => true, + ) ); + + if ( $this->form->validate() ) { + $settings = array( + 'phase1pass' => $this->form->get( 'phase1pass' ), + 'phase2pass' => $this->form->get( 'phase2pass' ), + 'weightonwiki' => $this->form->get( 'weightonwiki' ), + 'weightoffwiki' => $this->form->get( 'weightoffwiki' ), + 'weightinterest' => $this->form->get( 'weightinterest' ), + ); + + if ( $settings['weightonwiki'] + + $settings['weightoffwiki'] + + $settings['weightinterest'] != 1 + ) { + $this->flash( 'error', 'Sum of weights must be one' ); + + } else { + if ( $this->dao->updateSettings( $settings ) ) { + $this->flash( 'info', 'Settings succesfully updated.' ); + } else { + $this->flash( 'error', 'Settings could not be updated. ' ); + } + } + } else { + //FIXME: actually pass form errors back to view + $this->flash( 'error', 'Invalid input.' ); + } + + $this->redirect( $this->urlFor( 'admin_settings' ) ); + } + +} diff --git a/src/Wikimania/Scholarship/Dao/Settings.php b/src/Wikimania/Scholarship/Dao/Settings.php index 4da3bdf..811a902 100644 --- a/src/Wikimania/Scholarship/Dao/Settings.php +++ b/src/Wikimania/Scholarship/Dao/Settings.php @@ -24,18 +24,51 @@ /** * Data access object for Admin Settings in scholarship applications. + * + * @author Kushal Khandelwal <kushal...@wikimedia.org> + * @author Niharika Kohli <niharikakohl...@gmail.com> + * @copyright © 2014 Wikimedia Foundation and contributors. */ class Settings extends AbstractDao { /** * @return array Settings from DB */ - public function getSettings(){ + public function getSettings() { $settings = array(); - $records = $this->fetchAll( 'SELECT setting_name,value FROM settings' ); + $records = $this->fetchAll( + 'SELECT setting_name, value FROM settings' + ); foreach ( $records as $idx => $row ) { - $settings[ $row[ 'setting_name' ] ] = $row[ 'value' ]; + $settings[$row['setting_name']] = $row['value']; } return $settings; } + /** + * @param array $settings Settings + * @return bool True on success, false otherwise + */ + public function updateSettings( array $settings ) { + // TODO: change schema to track user changing settings + $stmt = $this->dbh->prepare( self::concat( + 'REPLACE INTO settings (setting_name, value)', + 'VALUES (:name, :value)' + ) ); + try { + $this->dbh->beginTransaction(); + foreach ( $settings as $name => $value ) { + $stmt->execute( array( 'name' => $name, 'value' => $value ) ); + } + $this->dbh->commit(); + return true; + + } catch ( PDOException $e) { + $this->dbh->rollback(); + $this->logger->error( 'Failed to update settings', array( + 'method' => __METHOD__, + 'exception' => $e, + ) ); + return false; + } + } } -- To view, visit https://gerrit.wikimedia.org/r/126833 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I22c509d4a44db95bf87c23122404bb4be19831ac Gerrit-PatchSet: 12 Gerrit-Project: wikimedia/wikimania-scholarships Gerrit-Branch: master Gerrit-Owner: Kushal124 <kushal...@gmail.com> Gerrit-Reviewer: BryanDavis <bda...@wikimedia.org> Gerrit-Reviewer: Kushal124 <kushal...@gmail.com> Gerrit-Reviewer: Niharika29 <niharikakohl...@gmail.com> Gerrit-Reviewer: Siebrand <siebr...@kitano.nl> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits