WebServices: set visibility to student work

pull/3952/head
Angel Fernando Quiroz Campos 4 years ago
parent 9b8d71847f
commit c146d907f8
  1. 23
      main/inc/lib/webservices/Rest.php
  2. 17
      main/webservices/api/v2.php

@ -60,6 +60,8 @@ class Rest extends WebService
const SAVE_FORUM_THREAD = 'save_forum_thread';
const SET_THREAD_NOTIFY = 'set_thread_notify';
const PUT_WORK_STUDENT_ITEM_VISIBILITY = 'put_course_work_visibility';
const CREATE_CAMPUS = 'add_campus';
const EDIT_CAMPUS = 'edit_campus';
const DELETE_CAMPUS = 'delete_campus';
@ -2585,6 +2587,27 @@ class Rest extends WebService
);
}
/**
* @throws Exception
*/
public function putCourseWorkVisibility(int $workId, int $status): bool
{
Event::event_access_tool(TOOL_STUDENTPUBLICATION);
$courseInfo = api_get_course_info_by_id($this->course->getId());
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
switch ($status) {
case 1:
return makeVisible($workId, $courseInfo);
case 0;
return makeInvisible($workId, $courseInfo);
default:
throw new Exception(get_lang('ActionNotAllowed'));
}
}
public static function isAllowedByRequest(bool $inpersonate = false): bool
{
$username = $_GET['username'] ?? null;

@ -296,6 +296,23 @@ try {
);
break;
case Rest::PUT_WORK_STUDENT_ITEM_VISIBILITY:
if (!isset($_POST['status'], $_POST['work'])) {
throw new Exception(get_lang('ActionNotAllowed'));
}
if (!api_is_allowed_to_edit() && !api_is_coach()) {
throw new Exception(get_lang('NotAllowed'));
}
$data = $restApi->putCourseWorkVisibility(
(int) $_POST['work'],
(int) $_POST['status']
);
$restResponse->setData(['status' => $data]);
break;
case Rest::CREATE_CAMPUS:
$data = $restApi->createCampusURL($_POST);
$restResponse->setData($data);

Loading…
Cancel
Save