1 files added
4 files modified
| New file |
| | |
| | | const db = require("../lib/db") |
| | | const yargs = require("yargs") |
| | | const {anmelden} = require("../lib/libIlias") |
| | | |
| | | ///////////////////////////////////////////////////////////////////////// |
| | | |
| | | const argv = yargs |
| | | .usage("$0 <usr_id> <course_id>", "User anmelden (ACHTUNG course_id muss obj_id sein!)",) |
| | | .strict() |
| | | .version(false) |
| | | .parse() |
| | | |
| | | ///////////////////////////////////////////////////////////////////////// |
| | | |
| | | run(argv) |
| | | .then(console.log) |
| | | .catch(console.error) |
| | | .finally(process.exit) |
| | | |
| | | ///////////////////////////////////////////////////////////////////////// |
| | | |
| | | async function run ({usr_id, course_id}) { |
| | | return await anmelden(usr_id, course_id) |
| | | } |
| | | |
| | |
| | | getKursTeilnehmerCount, |
| | | |
| | | getUdf, |
| | | |
| | | getMemberRoleForCourse, |
| | | } |
| | | |
| | | ///////////////////////////////////////////////////////////////////////// |
| | |
| | | |
| | | async function getUdf() { |
| | | const pool = await poolP |
| | | const q = `SELECT field_id, field_name, field_type from ${database}.udf_definition;` |
| | | const q = `SELECT field_id, field_name, field_type |
| | | from ${database}.udf_definition;` |
| | | const [results] = await pool.query(q) |
| | | return results |
| | | } |
| | | |
| | | /////// ROLLEN //////////////////////////////////////////////////////////////// |
| | | |
| | | async function getMemberRoleForCourse (obj_id) { |
| | | const pool = await poolP |
| | | const q = `SELECT obj_id, title, description |
| | | from object_data od |
| | | WHERE type = "role" #AND title LIKE 'il_crs_member_157' |
| | | AND od.description LIKE 'Member%${obj_id}' |
| | | ` |
| | | const [results] = await pool.query(q) |
| | | // darf nur einen Treffer ergeben |
| | | if (results.length) { |
| | | const {obj_id, title, description} = results[0] |
| | | return obj_id |
| | | } |
| | | else { |
| | | return null |
| | | } |
| | | } |
| | |
| | | getUser, |
| | | |
| | | importIliasUser, |
| | | |
| | | anmelden, |
| | | |
| | | deleteUser, |
| | | deleteAllUsers, |
| | | deleteTeilnahme, |
| | | |
| | | |
| | | } |
| | | |
| | | ///////////////////////////////////////////////////////////////////////// |
| | |
| | | } |
| | | } |
| | | |
| | | /////// Anmelden //////////////////////////////////////////////////////////////// |
| | | |
| | | async function anmelden (usr_id, course_id) { |
| | | // const role = await db.getMemberRoleForCourse(course_id) // nein es wird relative id gebraucht, siehe php |
| | | const sp = new URLSearchParams({ |
| | | command: "anmelden", |
| | | usr_id, |
| | | course_id, |
| | | token: iliastoken, |
| | | }) |
| | | let url2 = `${url}?${sp.toString()}` |
| | | console.log(url2) |
| | | const res = await fetch(url2, {method: "POST"}) |
| | | return await res.json() |
| | | } |
| | |
| | | $res["msg"] = "User Import OK"; |
| | | break; |
| | | } |
| | | case "anmelden": // params: usr_id, course_id, role |
| | | if ($method == "POST") { |
| | | $usr_id = (int) $_GET["usr_id"]; |
| | | $course_id = (int) $_GET["course_id"]; |
| | | $role = (int) $_GET["role"]; |
| | | |
| | | $res2 = anmelden($usr_id, $course_id, $role); |
| | | $res["status"] = "ok"; |
| | | $res["msg"] = "Anmelden OK"; |
| | | $res["params"] = array("usr_id"=>$usr_id, "course_id"=>$course_id, "role"=> $role); |
| | | $res["res2"] = $res2; |
| | | break; |
| | | } |
| | | case "deleteUser": |
| | | if ($method == "DELETE") { |
| | | $res["msg"] = deleteUser($obj_id, $dry); |
| | |
| | | return $usr_id; |
| | | } |
| | | |
| | | // ACHTUNG course_id muss obj_id sein! |
| | | // die Rolle muss aus dem Kurs gelesen werden |
| | | function anmelden($usr_id, $course_id) { |
| | | $course = ilObjectFactory::getInstanceByObjId($course_id); |
| | | $membersObject = $course->getMembersObject(); |
| | | $role = $membersObject::IL_CRS_MEMBER; |
| | | return $membersObject->add($usr_id, $role); |
| | | } |
| | | |
| | | function deleteUser($obj_id, $dry) |
| | | { |
| | | $usr = ilObjectFactory::getInstanceByObjId($obj_id); |
| | |
| | | |
| | | function deleteTeilnahme($obj_id, $usr_id, $dry) { |
| | | # beim Löschen durch den Kurs wird zwar die Teilnahme gelöscht, aber nicht die Rollenzugehörigkeit |
| | | $course = ilObjectFactory::getInstanceByObjId($obj_id); |
| | | // $course = ilObjectFactory::getInstanceByObjId($obj_id); |
| | | |
| | | $parti = ilCourseParticipant::_getInstanceByObjId($obj_id, $usr_id); ## Achtung die usr_id hier ist Admin id?? |
| | | #return "parti.isParticipant() = {$parti->isParticipant()}"; |
| | |
| | | }, |
| | | } |
| | | |
| | | beforeEach(async function () { |
| | | |
| | | }) |
| | | |
| | | afterEach(async function () { |
| | | // await deleteUser(lastUserId) |
| | | await deleteUser(lastUserId) |
| | | }) |
| | | |
| | | it("should import a new user to ILIAS", async function () { |
| | |
| | | |
| | | }) |
| | | |
| | | ///////////////////////////////////////////////////////////////////////// |
| | | |
| | | async function deleteUser (usr_id) { |
| | | const res2 = await libIlias.deleteUser(usr_id) |