diff --git a/CHANGELOG.md b/CHANGELOG.md index 302cc11..19c74df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ Todas las modificaciones importantes del proyecto se documentarán en este archivo. +## [2.0.5] — 2026-07-28 + +### Cambiado +- El bloque muestra un lanzador compacto del panel administrativo a los usuarios autorizados, sin estadísticas ni resultados en la página del curso. +- Se unificaron las plantillas de administración y de resultados individuales, incluidos los textos de acceso en español e inglés. + +### Seguridad +- Se incorporaron las capacidades `viewstudentdata` y `deletestudentdata` para separar la consulta/exportación de la eliminación de respuestas. +- Los datos de estudiantes dejaron de estar disponibles automáticamente para roles docentes. +- Se eliminó la capacidad heredada e inactiva `viewreports`. + ## [2.0.4] - 2026-01-18 - Se eliminaron las comprobaciones redundantes de administrador (`is_siteadmin()`) en varias vistas clave, mejorando la detección correcta de roles locales (profesores vs estudiantes) y el sistema de permisos basado en capacidades. - Se agrega negrilla en el titulo del bloque para mejorar la visibilidad. diff --git a/admin_view.php b/admin_view.php index 3cd1d26..997f431 100644 --- a/admin_view.php +++ b/admin_view.php @@ -33,7 +33,7 @@ } // Friendly redirect for unauthorized users -if (!has_capability('block/personality_test:viewreports', $context)) { +if (!has_capability('block/personality_test:viewstudentdata', $context)) { redirect(new moodle_url('/course/view.php', array('id' => $courseid))); } @@ -48,13 +48,17 @@ $PAGE->set_url($admin_url); // Handle Delete Action +if ($action === 'delete' && $userid && !has_capability('block/personality_test:deletestudentdata', $context)) { + redirect($admin_url); +} + if ($action === 'delete' && $userid && confirm_sesskey()) { $confirm = optional_param('confirm', 0, PARAM_INT); if ($confirm) { // Privacy check $targetuser = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); if (!is_enrolled($context, $targetuser, 'block/personality_test:taketest', true) - || has_capability('block/personality_test:viewreports', $context, $userid)) { + || has_capability('block/personality_test:viewstudentdata', $context, $userid)) { redirect(new moodle_url('/course/view.php', array('id' => $courseid))); } @@ -64,7 +68,7 @@ } $title = get_string('admin_manage_title', 'block_personality_test'); -$PAGE->set_pagelayout('standard'); +$PAGE->set_pagelayout('incourse'); $PAGE->set_title($title . " : " . $course->fullname); $PAGE->set_heading($title . " : " . $course->fullname); $PAGE->requires->css('/blocks/personality_test/styles.css'); @@ -79,7 +83,8 @@ 'csv_url' => (new moodle_url('/blocks/personality_test/download_csv.php', ['courseid' => $courseid, 'sesskey' => sesskey()]))->out(false), 'pdf_url' => (new moodle_url('/blocks/personality_test/download_pdf.php', ['courseid' => $courseid, 'sesskey' => sesskey()]))->out(false), 'course_url' => (new moodle_url('/course/view.php', ['id' => $courseid]))->out(false), - 'search_term' => $search + 'search_term' => $search, + 'can_delete' => has_capability('block/personality_test:deletestudentdata', $context), ]; // Handle Delete Confirmation @@ -256,6 +261,7 @@ 'is_completed' => ($p->is_completed == 1), 'created_at' => userdate($p->created_at, get_string('strftimedatetimeshort')), 'view_url' => (new moodle_url('/blocks/personality_test/view_individual.php', ['cid' => $courseid, 'userid' => $p->user]))->out(false), + 'can_delete' => has_capability('block/personality_test:deletestudentdata', $context), 'delete_url' => (new moodle_url('/blocks/personality_test/admin_view.php', ['cid' => $courseid, 'action' => 'delete', 'userid' => $p->user, 'sesskey' => sesskey()]))->out(false) ]; diff --git a/block_personality_test.php b/block_personality_test.php index 9489d2d..85d972e 100644 --- a/block_personality_test.php +++ b/block_personality_test.php @@ -99,7 +99,7 @@ private function _get_teacher_content($DB, $COURSE) { $filtered_student_ids = array(); foreach ($student_ids as $candidateid) { $candidateid = (int)$candidateid; - if (has_capability('block/personality_test:viewreports', $context, $candidateid)) { + if (has_capability('block/personality_test:viewstudentdata', $context, $candidateid)) { continue; } $filtered_student_ids[] = $candidateid; @@ -186,6 +186,21 @@ private function _get_teacher_content($DB, $COURSE) { return $content; } + private function get_secure_admin_content($COURSE) { + global $OUTPUT; + + $content = new stdClass(); + $content->text = $OUTPUT->render_from_template('block_personality_test/admin_launcher', [ + 'icon_html' => $this->get_personality_test_icon('4em', '', true), + 'security_label' => get_string('sensitive_data', 'block_personality_test'), + 'title' => get_string('management_title', 'block_personality_test'), + 'admin_url' => (new moodle_url('/blocks/personality_test/admin_view.php', ['cid' => $COURSE->id]))->out(false), + 'button_label' => get_string('open_admin_panel', 'block_personality_test'), + ]); + $content->footer = ''; + return $content; + } + /** * Helper method to generate personality test icon HTML * @param string $size Icon size (default: 1.8em) @@ -284,20 +299,10 @@ function get_content() $context = context_course::instance($COURSE->id); - // Si el usuario tiene permiso de ver reportes, mostrar la vista del profesor/administración. - if (has_capability('block/personality_test:viewreports', $context)) { - $teacher_content = $this->_get_teacher_content($DB, $COURSE); + // Los resultados se consultan desde el panel protegido, sin métricas en el curso. + if (has_capability('block/personality_test:viewstudentdata', $context)) { + $teacher_content = $this->get_secure_admin_content($COURSE); $this->content = $teacher_content; - - // Agregar enlace a la vista administrativa - $admin_url = new moodle_url('/blocks/personality_test/admin_view.php', array('cid' => $COURSE->id)); - $this->content->footer .= html_writer::div( - html_writer::link($admin_url, - get_string('go_to_administration', 'block_personality_test'), - array('class' => 'btn btn-sm mt-2', 'style' => 'background: linear-gradient(135deg, #00bf91 0%, #00a07a 100%); color: white; padding: 5px 10px; border-radius: 4px; text-decoration: none; border: none;') - ), - 'text-center' - ); return $this->content; } diff --git a/db/access.php b/db/access.php index e34827b..a96a8a4 100644 --- a/db/access.php +++ b/db/access.php @@ -24,21 +24,24 @@ 'clonepermissionsfrom' => 'moodle/site:manageblocks' ), - 'block/personality_test:viewreports' => array( + 'block/personality_test:taketest' => array( 'captype' => 'read', 'contextlevel' => CONTEXT_COURSE, 'archetypes' => array( - 'teacher' => CAP_ALLOW, - 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW + 'student' => CAP_ALLOW ) ), - 'block/personality_test:taketest' => array( + // Los resultados de personalidad requieren una concesión explícita. + 'block/personality_test:viewstudentdata' => array( + 'riskbitmask' => RISK_PERSONAL, 'captype' => 'read', - 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( - 'student' => CAP_ALLOW - ) + 'contextlevel' => CONTEXT_COURSE + ), + + 'block/personality_test:deletestudentdata' => array( + 'riskbitmask' => RISK_DATALOSS | RISK_PERSONAL, + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE ), ); diff --git a/download_pdf.php b/download_pdf.php index 6876b68..7e96f66 100644 --- a/download_pdf.php +++ b/download_pdf.php @@ -44,7 +44,7 @@ $context = context_course::instance($course->id); require_login($course, false); - $canviewreports = has_capability('block/personality_test:viewreports', $context); + $canviewreports = has_capability('block/personality_test:viewstudentdata', $context); if (!$canviewreports && (int)$userid !== (int)$USER->id) { redirect(new moodle_url('/course/view.php', ['id' => $course->id])); } diff --git a/lang/en/block_personality_test.php b/lang/en/block_personality_test.php index 858589f..b93fbfb 100644 --- a/lang/en/block_personality_test.php +++ b/lang/en/block_personality_test.php @@ -1,4 +1,9 @@ +
{{{icon_html}}}
+
{{security_label}}
+
{{title}}
+ {{button_label}} + diff --git a/templates/admin_view.mustache b/templates/admin_view.mustache index 43e8c11..2a7af3b 100644 --- a/templates/admin_view.mustache +++ b/templates/admin_view.mustache @@ -203,9 +203,11 @@ {{#str}}view, block_personality_test{{/str}} - - {{#str}}delete, block_personality_test{{/str}} - + {{#can_delete}} + + {{#str}}delete, block_personality_test{{/str}} + + {{/can_delete}} {{/list}} diff --git a/templates/individual_view.mustache b/templates/individual_view.mustache index af3871e..9648315 100644 --- a/templates/individual_view.mustache +++ b/templates/individual_view.mustache @@ -104,10 +104,10 @@ {{download_pdf_label}} - {{#can_view_reports}} + {{#can_delete}} {{delete_results_label}} - {{/can_view_reports}} + {{/can_delete}} diff --git a/version.php b/version.php index 3c5f59d..6fb56e4 100644 --- a/version.php +++ b/version.php @@ -10,8 +10,8 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2026011801; // YYYYMMDDXX (year, month, day, 2-digit version number). +$plugin->version = 2026072800; // YYYYMMDDXX (year, month, day, 2-digit version number). $plugin->requires = 2022041900; // Moodle 4.0+ $plugin->component = 'block_personality_test'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = '2.0.4'; +$plugin->release = '2.0.5'; diff --git a/view.php b/view.php index 7e748a3..ce747cd 100644 --- a/view.php +++ b/view.php @@ -35,7 +35,7 @@ } // If a user with reporting capability tries to open the student test view, redirect them to admin silently -if (has_capability('block/personality_test:viewreports', $context) && !has_capability('block/personality_test:taketest', $context)) { +if (has_capability('block/personality_test:viewstudentdata', $context) && !has_capability('block/personality_test:taketest', $context)) { redirect(new moodle_url('/blocks/personality_test/admin_view.php', array('cid' => $courseid)), get_string('teachers_redirect_message', 'block_personality_test'), null, \core\output\notification::NOTIFY_INFO); } diff --git a/view_individual.php b/view_individual.php index 87762cf..7cfeae1 100644 --- a/view_individual.php +++ b/view_individual.php @@ -21,7 +21,7 @@ // Verificar permisos y manejo de privacidad $is_own_results = ($USER->id == $userid); -$can_view_reports = has_capability('block/personality_test:viewreports', $context); +$can_view_reports = has_capability('block/personality_test:viewstudentdata', $context); // Acceso básico: Si no es propietario, ni profesor (con permisos), ni admin -> Redirigir if (!$is_own_results && !$can_view_reports) { @@ -221,7 +221,7 @@ 'download_url' => (new moodle_url('/blocks/personality_test/download_pdf.php', array('userid' => $userid, 'cid' => $courseid)))->out(false), 'download_pdf_label' => get_string('download_pdf', 'block_personality_test'), // Permissions for delete action - 'can_delete' => $can_view_reports, + 'can_delete' => has_capability('block/personality_test:deletestudentdata', $context), 'delete_url' => (new moodle_url('/blocks/personality_test/admin_view.php', array('cid' => $courseid, 'action' => 'delete', 'userid' => $userid, 'sesskey' => sesskey())))->out(false), 'confirm_delete_msg' => get_string('confirm_delete_individual', 'block_personality_test'), 'delete_results_label' => get_string('delete_results', 'block_personality_test'),