Tracking: Adjustment to correctly validate the admin when editing the item - refs BT#17943

pull/3704/head
Carlos Alvarado 5 years ago
parent 96721a0d9f
commit 80f1807d02
No known key found for this signature in database
GPG Key ID: B612DB1EE6658FBB
  1. 13
      main/inc/lib/extra_field.lib.php
  2. 14
      main/inc/lib/extra_field_value.lib.php
  3. 57
      main/lp/learnpath.class.php
  4. 2
      main/lp/lp_controller.php
  5. 15
      main/lp/lp_edit_item.php

@ -994,19 +994,6 @@ class ExtraField extends Model
continue;
}
}
// see BT#17943
$authors = false;
if (
$field_details['variable'] == 'authors'
|| $field_details['variable'] == 'authorlp'
|| $field_details['variable'] == 'authorlpitem'
|| $field_details['variable'] == 'price'
) {
$authors = true;
}
if (!api_is_platform_admin() && $authors == true) {
continue;
}
// Getting default value id if is set
$defaultValueId = null;

@ -160,20 +160,6 @@ class ExtraFieldValue extends Model
continue;
}
// see BT#17943
$authors = false;
if (
$extraFieldInfo['variable'] == 'authors'
|| $extraFieldInfo['variable'] == 'authorlp'
|| $extraFieldInfo['variable'] == 'authorlpitem'
|| $extraFieldInfo['variable'] == 'price'
) {
$authors = true;
}
if (!api_is_platform_admin() && $authors == true) {
continue;
}
$commentVariable = 'extra_'.$field_variable.'_comment';
$comment = isset($params[$commentVariable]) ? $params[$commentVariable] : null;
$dirPermissions = api_get_permissions_for_new_directories();

@ -7333,8 +7333,10 @@ class learnpath
*
* @return string
*/
public function display_edit_item($item_id)
{
public function display_edit_item(
$item_id,
$exclude = []
) {
$course_id = api_get_course_int_id();
$return = '';
$item_id = (int) $item_id;
@ -7359,7 +7361,8 @@ class learnpath
get_lang('EditCurrentChapter').' :',
'edit',
$item_id,
$row
$row,
$exclude
);
} else {
$return .= $this->display_item_form(
@ -7367,7 +7370,8 @@ class learnpath
get_lang('EditCurrentChapter').' :',
'edit_item',
$item_id,
$row
$row,
$exclude
);
}
break;
@ -7386,7 +7390,12 @@ class learnpath
$return .= $this->display_manipulate($item_id, $row['item_type']);
if ($row['item_type'] === TOOL_DOCUMENT) {
$return .= $this->display_document_form('edit', $item_id, $row_step);
$return .= $this->display_document_form(
'edit',
$item_id,
$row_step,
null,
$exclude);
}
if ($row['item_type'] === TOOL_READOUT_TEXT) {
@ -7414,7 +7423,7 @@ class learnpath
}
}
$return .= $this->display_manipulate($item_id, $row['item_type']);
$return .= $this->display_link_form('edit', $item_id, $row);
$return .= $this->display_link_form('edit', $item_id, $row, null, $exclude);
break;
case TOOL_LP_FINAL_ITEM:
Session::write('finalItem', true);
@ -7429,11 +7438,11 @@ class learnpath
$res_step = Database::query($sql);
$row_step = Database::fetch_array($res_step, 'ASSOC');
$return .= $this->display_manipulate($item_id, $row['item_type']);
$return .= $this->display_document_form('edit', $item_id, $row_step);
$return .= $this->display_document_form('edit', $item_id, $row_step, $exclude);
break;
case TOOL_QUIZ:
$return .= $this->display_manipulate($item_id, $row['item_type']);
$return .= $this->display_quiz_form('edit', $item_id, $row);
$return .= $this->display_quiz_form('edit', $item_id, $row, $exclude);
break;
case TOOL_HOTPOTATOES:
$return .= $this->display_manipulate($item_id, $row['item_type']);
@ -7579,8 +7588,12 @@ class learnpath
*
* @return string HTML form
*/
public function display_quiz_form($action = 'add', $id = 0, $extra_info = '')
{
public function display_quiz_form(
$action = 'add',
$id = 0,
$extra_info = '',
$exclude = []
) {
$course_id = api_get_course_int_id();
$id = (int) $id;
$tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
@ -7728,7 +7741,7 @@ class learnpath
if ('edit' === $action) {
$extraField = new ExtraField('lp_item');
$extraField->addElements($form, $id);
$extraField->addElements($form, $id, $exclude);
}
if ($action === 'add') {
@ -8597,8 +8610,13 @@ class learnpath
*
* @return string HTML form
*/
public function display_document_form($action = 'add', $id = 0, $extra_info = 'new', $item = null)
{
public function display_document_form(
$action = 'add',
$id = 0,
$extra_info = 'new',
$item = null,
$exclude = []
) {
$course_id = api_get_course_int_id();
$_course = api_get_course_info();
$tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
@ -8827,7 +8845,7 @@ class learnpath
if ('edit' === $action) {
$extraField = new ExtraField('lp_item');
$extraField->addElements($form, $id);
$extraField->addElements($form, $id, $exclude );
}
if ($action !== 'move') {
@ -9412,8 +9430,13 @@ class learnpath
*
* @return string HTML form
*/
public function display_link_form($action = 'add', $id = 0, $extra_info = '', $item = null)
{
public function display_link_form(
$action = 'add',
$id = 0,
$extra_info = '',
$item = null,
$exclude = []
) {
$course_id = api_get_course_int_id();
$tbl_link = Database::get_course_table(TABLE_LINK);
@ -9568,7 +9591,7 @@ class learnpath
if ('edit' === $action) {
$extraField = new ExtraField('lp_item');
$extraField->addElements($form, $id);
$extraField->addElements($form, $id, $exclude);
}
if ($action === 'add') {

@ -912,7 +912,7 @@ switch ($action) {
$is_success = true;
$extraFieldValues = new ExtraFieldValue('lp_item');
$extraFieldValues->saveFieldValues($_POST);
$extraFieldValues->saveFieldValues($_POST, true);
Display::addFlash(Display::return_message(get_lang('Updated')));
$url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();

@ -160,6 +160,16 @@ if (!empty($path_file) && isset($path_parts['extension']) && $path_parts['extens
echo '</div>';
echo '<div id="doc_form" class="col-md-8">';
$exclude = [
'authors',
'authorlp',
'authorlpitem',
'price',
];
if (api_is_platform_admin() ) {
// Only admins can edit this items
$exclude = [];
}
if (isset($is_success) && $is_success === true) {
$msg = '<div class="lp_message" style="margin-bottom:10px;">';
$msg .= 'The item has been edited.';
@ -167,7 +177,10 @@ if (isset($is_success) && $is_success === true) {
echo $learnPath->display_item($_GET['id'], $msg);
} else {
$item = $learnPath->getItem($_GET['id']);
echo $learnPath->display_edit_item($item->getIid());
echo $learnPath->display_edit_item(
$item->getIid(),
$exclude
);
$finalItem = Session::read('finalItem');
if ($finalItem) {
echo '<script>$("#frmModel").remove()</script>';

Loading…
Cancel
Save