Skip to content

Commit

Permalink
Notebook: Validate that only the author can edit the note
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Apr 18, 2023
1 parent 80d1a8c commit f9a17bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions main/inc/lib/notebook.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public static function get_note_information($notebook_id)
$notebook_id = (int) $notebook_id;

$sql = "SELECT
user_id,
notebook_id AS notebook_id,
title AS note_title,
description AS note_comment,
Expand Down
14 changes: 11 additions & 3 deletions main/notebook/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ function setFocus(){
// Tracking
Event::event_access_tool(TOOL_NOTEBOOK);

$action = isset($_GET['action']) ? $_GET['action'] : '';
$currentUserId = api_get_user_id();
$action = $_GET['action'] ?? '';

$logInfo = [
'tool' => TOOL_NOTEBOOK,
Expand Down Expand Up @@ -137,6 +138,15 @@ function setFocus(){
exit;
}

// Setting the defaults
$defaults = NotebookManager::get_note_information((int) $_GET['notebook_id']);

if ($currentUserId !== (int) $defaults['user_id']) {
echo Display::return_message(get_lang('NotAllowed'), 'error');
Display::display_footer();
exit();
}

// Initialize the object
$form = new FormValidator(
'note',
Expand All @@ -159,8 +169,6 @@ function setFocus(){
);
$form->addButtonUpdate(get_lang('ModifyNote'), 'SubmitNote');

// Setting the defaults
$defaults = NotebookManager::get_note_information(Security::remove_XSS($_GET['notebook_id']));
$form->setDefaults($defaults);

// Setting the rules
Expand Down

0 comments on commit f9a17bf

Please sign in to comment.