diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..13ee2b0 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "nuxt.isNuxtApp": false +} \ No newline at end of file diff --git a/index.js b/index.js index 1ff0fda..0f0cc3e 100644 --- a/index.js +++ b/index.js @@ -15,44 +15,47 @@ log.debug(JSON.stringify(config)) + // dn: site.compatTransform(site.fnUserDn({ cn: cn })), + // attributes: { + // cn: cn, + // displayname: "Admin", + // id: 0, + // uid: "Admin", + // bbbrole: "admin", + // entryUUID: , + // givenname: "Administrator", + // objectclass: [c.LDAP_OBJCLASS_USER, "simpleSecurityObject", "organizationalRole"], + // } + +const updateCache = (site, siteCacheFunctions) => { - dn: site.compatTransform(site.fnUserDn({ cn: cn })), - attributes: { - cn: cn, - displayname: "Admin", - id: 0, - uid: "Admin", - bbbrole: "admin", - entryUUID: , - givenname: "Administrator", - objectclass: [c.LDAP_OBJCLASS_USER, "simpleSecurityObject", "organizationalRole"], - } - - - for (var site in config.sites) { - const siteCacheFunctions = ldapcache.init(site.name, transform.getRootObj(site.ldap.dn, site.ldap.admin, site.ldap.o)) const siteTramsforms = transform.getSiteTransforms(site) - const configGroupIds = site.selectionGroupIds.map((id) => id) - const ctPersonIds = await ctservice.getPersonsInGroups(configGroupIds, site.site) + const churchtoolsdata = ctservice.getChurchToolsData(site) + const groups = siteTramsforms.getLdapGroupsWithoutMembers() + const persons = siteTramsforms.getLdapUser() + siteTramsforms.addMembersToGroups(groups, persons) - site.tranformedGroups.forEach(element => { - if (!configGroupIds.includes(element.gid)) - configGroupIds.push(element.guid) - }); - const ctGroups = await ctservice.getGroups(configGroupIds, site.site) + ldapcache.update(site.name, persons, groups) +} - const ctPersons = [] - for await (const id of ctPersonIds) { - ctPersons.push( - await ctservice.getPersonRecordForId(id, site.site) - ) - } - const ctGroupMembership = ctservice.getGroupMemberships(configGroupIds, site.site) +const initCahce = (site) => { + const siteCacheFunctions = ldapcache.init(site.name, transform.getRootObj(site.ldap.dn, site.ldap.admin, site.ldap.o)) + updateCache(site, siteCacheFunctions) + // Todo implement an update strategy +} - siteTramsforms +const updateLdapServerData = (siteldap) => { - } +} + +const startLdapServer = (siteldap) => { + updateLdapServerData(siteldap) +} + +for (var site in config.sites) { + initCahce(site) +} // LdapCache.init( Root Object ) diff --git a/src/ctservice.js b/src/ctservice.js index 6ce1446..8205e7c 100644 --- a/src/ctservice.js +++ b/src/ctservice.js @@ -1,64 +1,62 @@ -const log = require("./logging"); -const c = require("./constants"); -const t = require("./transform"); -const ctconn = require("./ctconnection"); +const log = require('./logging'); +const c = require('./constants'); +const t = require('./transform'); +const ctconn = require('./ctconnection'); gettehgroups = async (groupIds, site) => { - var url = site.url + c.API_SLUG + c.GROUPMEMBERS_AP - groupIds.forEach(id => { - url = url + c.IDS + id + var url = site.url + c.API_SLUG + c.GROUPMEMBERS_AP; + groupIds.forEach((id) => { + url = url + c.IDS + id; }); - return await ctconn.get(url, site) -} + return await ctconn.get(url, site); +}; exports.getPersonsInGroups = async (groupIds, site) => { - const result = await gettehgroups(groupIds, site) - const personIds = [] + const result = await gettehgroups(groupIds, site); + const personIds = []; result.data.forEach((el) => { - if (!personIds.includes(el.personId)) - personIds.push(el.personId) - }) - return personIds -} + if (!personIds.includes(el.personId)) personIds.push(el.personId); + }); + return personIds; +}; exports.getGroupMemberships = async (groupIds, site) => { - const result = await gettehgroups(groupIds, site) - const members = [] + const result = await gettehgroups(groupIds, site); + const members = []; result.data.forEach((el) => { members.push({ personId: el.personId, - groupId: el.groupId - }) - }) - return members -} - + groupId: el.groupId, + }); + }); + return members; +}; exports.getGroups = async (groupIds, site) => { - var url = site.url + c.API_SLUG + c.GROUPS_AP - groupIds.forEach(id => { - url = url + c.IDS + id + var url = site.url + c.API_SLUG + c.GROUPS_AP; + groupIds.forEach((id) => { + url = url + c.IDS + id; }); - const result = await ctconn.get(url, site) - const groups = [] + const result = await ctconn.get(url, site); + const groups = []; result.data.forEach((el) => { groups.push({ id: el.id, guid: el.guid, - name: el.name - }) - }) - return groups -} + name: el.name, + }); + }); + return groups; +}; exports.getUid = (data) => { if (data[c.LDAPID_FIELD] && data[c.LDAPID_FIELD].length > 0) return data[c.LDAPID_FIELD]; - return t.stringConvLowercaseUmlaut(data.firstName + "." + data.lastName) -} + return t.stringConvLowercaseUmlaut(data.firstName + '.' + data.lastName); +}; exports.getPersonRecordForId = async (id, site) => { - var url = site.url + c.API_SLUG + c.PERSONS_AP + "/" + id; - const { data } = await ctconn.get(url, site) + var url = site.url + c.API_SLUG + c.PERSONS_AP + '/' + id; + const { data } = await ctconn.get(url, site); var person = { id: data.id, guid: data.guid, @@ -70,9 +68,31 @@ exports.getPersonRecordForId = async (id, site) => { phonePrivate: data.phonePrivate, zip: data.zip, city: data.city, - cmsuserid: (data.cmsUserId ? data.cmsUserId : this.getUid(data)), + cmsuserid: data.cmsUserId ? data.cmsUserId : this.getUid(data), email: data.email, + }; + person[c.LDAPID_FIELD] = this.getUid(data); + return person; +}; + +exports.getChurchToolsData = async (site) => { + const configGroupIds = site.selectionGroupIds.map((id) => id); + const ctPersonIds = await this.getPersonsInGroups(configGroupIds, site.site); + + this.tranformedGroups.forEach((element) => { + if (!configGroupIds.includes(element.gid)) + configGroupIds.push(element.guid); + }); + const ctGroups = await this.getGroups(configGroupIds, site.site); + + const ctPersons = []; + for await (const id of ctPersonIds) { + this.push(await this.getPersonRecordForId(id, site.site)); } - person[c.LDAPID_FIELD] = this.getUid(data) - return person -} \ No newline at end of file + const ctGroupMembership = this.getGroupMemberships(configGroupIds, site.site); + return { + groups: ctGroups, + persons: ctPersons, + memberships: ctGroupMembership, + }; +};