diff --git a/main/inc/lib/webservices/Rest.php b/main/inc/lib/webservices/Rest.php index adce0bc2ba..03d4f88095 100644 --- a/main/inc/lib/webservices/Rest.php +++ b/main/inc/lib/webservices/Rest.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; diff --git a/main/webservices/api/v2.php b/main/webservices/api/v2.php index 18a041a48f..c4324163c8 100644 --- a/main/webservices/api/v2.php +++ b/main/webservices/api/v2.php @@ -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);