Permalink
Browse files

Cursus responsables can now validate their contents.

Fixes #260.
  • Loading branch information...
1 parent 27d4229 commit 3e17140b81f6f3ba0f030c92802cfc258597e058 @bfontaine bfontaine committed Aug 17, 2013
Showing with 58 additions and 38 deletions.
  1. +1 −1 config.php
  2. +5 −32 controllers/content.php
  3. +50 −4 controllers/cursus.php
  4. +1 −0 routes.php
  5. +1 −1 views/templates/cursus/dashboard.html
View
@@ -81,7 +81,7 @@ private static function tpl_init() {
$loader = new Twig_Loader_Filesystem(self::$app_dir.'/views/templates');
self::$default_twig_env = array(
- 'cache' => self::$app_dir.'/cache/templates',
+ 'cache' => null, // self::$app_dir.'/cache/templates',
'charset' => 'utf-8',
'strict_variables' => true,
'autoescape' => true
View
@@ -97,7 +97,9 @@ function display_course_content() {
}
if (!$content->getValidated()) {
- if (!is_connected() || (user()->getId() != $user->getId() && !user()->isAdmin())) {
+ if (!is_connected() || (!user()->isResponsibleFor($cursus)
+ && user()->getId() != $user->getId()
+ && !user()->isAdmin())) {
halt(NOT_FOUND);
}
$msg_str = 'Ce contenu est en attente de validation.';
@@ -107,47 +109,19 @@ function display_course_content() {
$tpl_proposed = null;
- if (user()->isAdmin()) {
+ if (user()->isAdmin() || user()->isResponsibleFor($cursus)) {
$post_token = generate_post_token(user());
FormData::create($post_token)->store('proposed', $content);
$tpl_proposed = array(
'form' => array(
- 'action' => Config::$root_uri. 'admin/content/proposed',
+ 'action' => cursus_url($cursus).'/dash',
'post_token' => $post_token
)
);
}
}
- else if (is_connected() && user()->isAdmin()) {
- $report = ReportQuery::create()->findOneByContent($content);
-
- if ($report && is_connected() && user()->isAdmin()) {
-
- $post_token = generate_post_token(user());
-
- FormData::create($post_token)->store('report', $report);
-
- $r_author = $report->getAuthor();
-
- $tpl_report = array(
- 'author' => array(
- 'name' => $r_author->getPublicName(),
- 'href' => user_url($r_author)
- ),
- 'date' => array(
- 'text' => Lang\date_fr($report->getDate()),
- 'datetime' => datetime_attr($report->getDate())
- ),
- 'form' => array(
- 'action' => Config::$root_uri.'admin/reports',
- 'post_token' => $post_token
- ),
- 'explication' => $report->getText()
- );
- }
- }
if (is_connected() && (user()->isModerator() || user()->isResponsibleFor($cursus))) {
$js = 'editable-content';
@@ -287,7 +261,6 @@ function display_course_content() {
'breadcrumbs' => $breadcrumbs,
'proposed' => $tpl_proposed,
- 'report' => $tpl_report,
'content' => $tpl_content,
'message' => $msg_str,
View
@@ -145,7 +145,7 @@ function display_cursus() {
return tpl_render('cursus/base.html', $tpl_cursus);
}
-function display_cursus_dashboard() {
+function display_cursus_dashboard($has_msg=false, $msg_str='', $msg_type='') {
$name = params('name');
$cursus = CursusQuery::create()->findOneByShortName($name);
@@ -160,6 +160,8 @@ function display_cursus_dashboard() {
halt(HTTP_FORBIDDEN);
}
+ $has_msg &= ($msg_str && $msg_type);
+
$base_uri = Config::$root_uri.'cursus/'.strtoupper($cursus->getShortName()).'/';
$breadcrumbs = array(
@@ -213,13 +215,57 @@ function display_cursus_dashboard() {
return tpl_render('cursus/dashboard.html', array(
'page' => array(
- 'title' => $cursus->getName().' - Administration',
- 'breadcrumbs' => $breadcrumbs,
- 'contents' => $tpl_contents
+ 'title' => $cursus->getName().' - Administration',
+ 'breadcrumbs' => $breadcrumbs,
+ 'contents' => $tpl_contents,
+ 'message' => ($has_msg === true) ? $msg_str : null,
+ 'message_type' => ($has_msg === true) ? $msg_type : null
)
));
}
+function post_cursus_dashboard() {
+ $name = params('name');
+ $cursus = CursusQuery::create()->findOneByShortName($name);
+
+ if ($cursus == null) { halt(NOT_FOUND); }
+
+ if (!is_connected() || !(user()->isAdmin() || user()->isResponsibleFor($cursus))) {
+ halt(HTTP_FORBIDDEN);
+ }
+
+ $msg_str = null;
+
+ if (!has_post('t')) { halt(HTTP_BAD_REQUEST); }
+
+ $token = $_POST['t'];
+
+ $fd = FormData::create($token);
+
+ if ((!use_token($token, 'POST')) || (!$fd->exists())) {
+ halt(HTTP_FORBIDDEN, 'Le jeton d\'authentification est invalide ou a expiré.');
+ }
+
+ $content = $fd->get('proposed');
+
+ if ( !has_post('validate') && !has_post('delete') )
+ return display_cursus_dashboard(true,
+ 'Erreur interne (nopost:validate,delete)', 'error');
+
+ if ( has_post('validate') ) {
+ $content->setValidated(1);
+ $content->save();
+ $msg_str = 'Le contenu a bien été validé.';
+ }
+
+ if ( has_post('delete') ){
+ $content->delete();
+ $msg_str = 'Le contenu a bien été supprimé.';
+ }
+
+ return display_cursus_dashboard(true, $msg_str, 'success');
+}
+
function display_cursus_with_multiple_educational_paths($cursus, $msg_str, $msg_type, $base_uri, $breadcrumb) {
$paths = $cursus->getEducationalPaths();
View
@@ -72,6 +72,7 @@ function redirect_profile_init() { redirect_to('/profil/créer'); }
## cursus admin
dispatch('/cursus/:name/dash', 'display_cursus_dashboard');
+ dispatch_post('/cursus/:name/dash', 'post_cursus_dashboard');
## educational paths
dispatch('/cursus/:cursus/parcours/:path', 'display_educational_path');
@@ -5,7 +5,7 @@
<h1>{{ page.title }}</h1>
<h2>Contenus non validés</h2>
{% if page.contents is defined and page.contents %}
-<table>
+<table id="proposedList" border="1">
<tr><th>Titre</th><th>Cursus</th><th>Cours</th><th>Auteur</th><th>Date</th><th class="empty"</th></tr>
{% for c in page.contents %}

0 comments on commit 3e17140

Please sign in to comment.