Skip to content

Commit

Permalink
WebServices: set visibility to student work
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Aug 24, 2021
1 parent 9b8d718 commit c146d90
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
23 changes: 23 additions & 0 deletions main/inc/lib/webservices/Rest.php
Expand Up @@ -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';
Expand Down Expand Up @@ -2585,6 +2587,27 @@ function (array $work) use ($isAllowedToEdit, $courseInfo, $courseId, $sessionId
);
}

/**
* @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;
Expand Down
17 changes: 17 additions & 0 deletions main/webservices/api/v2.php
Expand Up @@ -296,6 +296,23 @@
);
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);
Expand Down

0 comments on commit c146d90

Please sign in to comment.