REST Service for POPCORN - ILIAS
alex
2025-11-27 a8c152f255665bc4eae00cc5a7f266cc9e7ffa51
GS-2333
1 files added
1 files modified
106 ■■■■■ changed files
lib/db.js 54 ●●●●● patch | view | raw | blame | history
test/testCourseAdmins.js 52 ●●●●● patch | view | raw | blame | history
lib/db.js
@@ -57,6 +57,9 @@
    getKursRoles,
    setStatus,
   getCourseAdmins,
   getCoursesWithNoAdmins,
}
/////////////////////////////////////////////////////////////////////////
@@ -673,3 +676,54 @@
        }
    }
}
/////// ADMINS ////////////////////////////////////////////////////////////////
async function getCourseAdmins() {
   const pool = await poolP
   const q = `SELECT om.obj_id as kurs_obj_id,
                     t.ref_id  as kurs_ref_id,
                     om.usr_id,
                     ud.login,
                     om.admin,
                     ud.firstname,
                     ud.lastname,
                     od2.title
              FROM ${database}.obj_members om
                       INNER JOIN ${database}.usr_data ud ON ud.usr_id = om.usr_id
                       INNER JOIN ${database}.object_data od2 ON od2.obj_id = om.obj_id
                       INNER JOIN ${database}.object_reference t ON t.obj_id = om.obj_id
              WHERE om.admin = 1
   `
   const [results] = await pool.query(q)
   return results
}
/**
 * Liefert die Kurse ohne Admins
 * Admins hier definiert als Einträge in obj_members wo admin==1
 * Darüber hinaus gibt es offenbar noch einen anderen Mechanismus über die Rolle.
 * Denn ein Kurs ohne Admin (z.B. lokal Fliesenratgeber ref_id=88) hat in ILIAS
 * trotzdem einen Admin im Screen "Members".
 * Dort wird wohl über die Rolle zugeordnet.
 *
 * Die Frage ist wo der Fehler GS-2333 auftritt.
 * Bei obj_members oder bei fehlender Rolle.
 * @return {Promise<*>}
 */
async function getCoursesWithNoAdmins() {
   const pool = await poolP
   const q = `
       SELECT asdf.obj_id, t.ref_id, asdf.numTn, asdf.title
       FROM (SELECT om.obj_id, COUNT(*) as numTn, od.title, MAX(om.admin) as maxAdmin
             FROM ${database}.obj_members om
                      INNER JOIN ${database}.object_data od ON od.obj_id = om.obj_id
             GROUP by om.obj_id
             ORDER BY numTn DESC) asdf
                INNER JOIN ${database}.object_reference t ON t.obj_id = asdf.obj_id
       WHERE asdf.maxAdmin = 0
   `
   const [results] = await pool.query(q)
   return results
}
test/testCourseAdmins.js
New file
@@ -0,0 +1,52 @@
const expect = require("chai").expect
const settings = require("../settings")
const libIlias = require("../lib/libIlias")
const db = require("../lib/db")
const testData = require("./data")
/////////////////////////////////////////////////////////////////////////
describe("The functions for Course Admins", function () {
   beforeEach(async function () {
   })
   afterEach(async function () {
   })
   describe("the function getCourseAdmins()", function () {
      it("should get the Admins of all courses", async function () {
         const res = await db.getCourseAdmins()
         console.table(res)
         expect(res).to.be.a("array")
         for (const item of res) {
            expect(item).to.have.property("kurs_obj_id").and.to.be.a("number")
            expect(item).to.have.property("kurs_ref_id").and.to.be.a("number")
            expect(item).to.have.property("usr_id").and.to.be.a("number")
            expect(item).to.have.property("login").and.to.be.a("string")
            expect(item).to.have.property("firstname").and.to.be.a("string")
            expect(item).to.have.property("lastname").and.to.be.a("string")
            expect(item).to.have.property("title").and.to.be.a("string")
         }
      })
   })
   describe("the function getCoursesWithNoAdmins()", function () {
      it("should return all courses without a single admin member", async function () {
         const res = await db.getCoursesWithNoAdmins()
         console.table(res)
         expect(res).to.be.a("array")
         for (const item of res) {
            expect(item).to.have.property("obj_id").and.to.be.a("number")
            expect(item).to.have.property("ref_id").and.to.be.a("number")
            expect(item).to.have.property("numTn").and.to.be.a("number")
            expect(item).to.have.property("title").and.to.be.a("string")
         }
      })
   })
})
/////////////////////////////////////////////////////////////////////////