Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 10 additions & 4 deletions admin_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

Expand All @@ -48,13 +48,17 @@
$PAGE->set_url($admin_url);

// Handle Delete Action
if ($action === 'delete' && $userid && !has_capability('block/personality_test:deletestudentdata', $context)) {

Check failure on line 51 in admin_view.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "block/personality_test:deletestudentdata" 3 times.

See more on https://sonarcloud.io/project/issues?id=ISCOUTB_personality_test&issues=AZ-nh4RRiLnwHvvk09E5&open=AZ-nh4RRiLnwHvvk09E5&pullRequest=32
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)));
}

Expand All @@ -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');
Expand All @@ -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
Expand Down Expand Up @@ -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)
];

Expand Down
33 changes: 19 additions & 14 deletions block_personality_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
* @param object $COURSE El objeto global del curso actual.
* @return stdClass Un objeto con las propiedades 'text' y 'footer' para el contenido del bloque.
*/
private function _get_teacher_content($DB, $COURSE) {

Check warning on line 86 in block_personality_test.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused private "_get_teacher_content" method.

See more on https://sonarcloud.io/project/issues?id=ISCOUTB_personality_test&issues=AZ-nh4WTiLnwHvvk09E7&open=AZ-nh4WTiLnwHvvk09E7&pullRequest=32
global $OUTPUT;

$content = new stdClass();
Expand All @@ -99,7 +99,7 @@
$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;
Expand Down Expand Up @@ -186,6 +186,21 @@
return $content;
}

private function get_secure_admin_content($COURSE) {

Check warning on line 189 in block_personality_test.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename function "get_secure_admin_content" to match the regular expression ^[a-z][a-zA-Z0-9]*$.

See more on https://sonarcloud.io/project/issues?id=ISCOUTB_personality_test&issues=AZ-nh4WTiLnwHvvk09E6&open=AZ-nh4WTiLnwHvvk09E6&pullRequest=32

Check warning on line 189 in block_personality_test.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this parameter "$COURSE" to match the regular expression ^[a-z_][a-zA-Z0-9_]*$.

See more on https://sonarcloud.io/project/issues?id=ISCOUTB_personality_test&issues=AZ-nh4WTiLnwHvvk09E8&open=AZ-nh4WTiLnwHvvk09E8&pullRequest=32
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)
Expand Down Expand Up @@ -284,20 +299,10 @@

$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;
}

Expand Down
21 changes: 12 additions & 9 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
);
2 changes: 1 addition & 1 deletion download_pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
Expand Down
5 changes: 5 additions & 0 deletions lang/en/block_personality_test.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
$string['personality_test:viewstudentdata'] = 'View sensitive student data';
$string['personality_test:deletestudentdata'] = 'Delete sensitive student data';
$string['personality_test:taketest'] = 'Take the personality exploration';
$string['sensitive_data'] = 'Sensitive data';
$string['open_admin_panel'] = 'Open administration panel';
$string['pluginname'] = 'Personality Exploration';
$string['course_overview'] = 'Course Overview';
$string['management_title'] = 'Personality Exploration Management';
Expand Down
5 changes: 5 additions & 0 deletions lang/es/block_personality_test.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
$string['personality_test:viewstudentdata'] = 'Ver datos sensibles de estudiantes';
$string['personality_test:deletestudentdata'] = 'Eliminar datos sensibles de estudiantes';
$string['personality_test:taketest'] = 'Realizar la exploración de personalidad';
$string['sensitive_data'] = 'Datos sensibles';
$string['open_admin_panel'] = 'Abrir panel de administración';
$string['pluginname'] = 'Exploración de Personalidad';
$string['management_title'] = 'Gestión - Exploración de Personalidad';
$string['course_overview'] = 'Resumen del Curso';
Expand Down
4 changes: 2 additions & 2 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function block_personality_test_get_report_data($courseid) {
require_login($course, false);

// Check permissions
if (!has_capability('block/personality_test:viewreports', $context)) {
if (!has_capability('block/personality_test:viewstudentdata', $context)) {
return false;
}

Expand All @@ -89,7 +89,7 @@ function block_personality_test_get_report_data($courseid) {
$student_ids = array();
foreach ($enrolled_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;
}
$student_ids[] = $candidateid;
Expand Down
6 changes: 6 additions & 0 deletions templates/admin_launcher.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="savio-admin-launcher text-center" style="padding: 1.25rem 1rem; border: 1px solid #caeee3; border-radius: 14px; background: linear-gradient(145deg, #fbfffd 0%, #e9faf5 100%); box-shadow: 0 8px 20px rgba(0, 191, 145, .10);">
<div style="margin: 0 auto .85rem; line-height: 0;">{{{icon_html}}}</div>
<div class="small font-weight-bold text-uppercase" style="letter-spacing: .07em; color: #008a69;"><i class="fa fa-lock mr-1"></i>{{security_label}}</div>
<h6 class="mt-2 mb-2 font-weight-bold">{{title}}</h6>
<a href="{{admin_url}}" class="btn btn-sm btn-block" style="background: linear-gradient(135deg, #00bf91 0%, #00a07a 100%); color: #fff !important; border: 0; font-weight: 700; border-radius: 8px;"><i class="fa fa-arrow-right mr-1"></i>{{button_label}}</a>
</div>
8 changes: 5 additions & 3 deletions templates/admin_view.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,11 @@
<a href="{{view_url}}" class="btn btn-sm btn-info mr-2" title="{{#str}}view_results, block_personality_test{{/str}}">
<i class="fa fa-eye"></i> {{#str}}view, block_personality_test{{/str}}
</a>
<a href="{{delete_url}}" class="btn btn-sm btn-danger" title="{{#str}}delete_participation, block_personality_test{{/str}}">
<i class="fa fa-trash"></i> {{#str}}delete, block_personality_test{{/str}}
</a>
{{#can_delete}}
<a href="{{delete_url}}" class="btn btn-sm btn-danger" title="{{#str}}delete_participation, block_personality_test{{/str}}">
<i class="fa fa-trash"></i> {{#str}}delete, block_personality_test{{/str}}
</a>
{{/can_delete}}
</td>
</tr>
{{/list}}
Expand Down
4 changes: 2 additions & 2 deletions templates/individual_view.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@
<a href='{{download_url}}' class='btn mr-3' style='background: linear-gradient(135deg, #28a745 0%, #1e7e34 100%) !important; border: none; color: white;'>
<i class='fa fa-download'></i> {{download_pdf_label}}
</a>
{{#can_view_reports}}
{{#can_delete}}
<a href='{{delete_url}}' class='btn btn-danger' onclick='return confirm("{{confirm_delete_msg}}")'>
<i class='fa fa-trash'></i> {{delete_results_label}}
{{/can_view_reports}}
{{/can_delete}}
</a>
</div>

Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
2 changes: 1 addition & 1 deletion view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions view_individual.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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'),
Expand Down
Loading