From 32cd36c95f02145edc0784f5c58420574c610777 Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Mon, 30 Jul 2018 00:23:29 +0000 Subject: [server/migrations] add ondelete cascade to group_x_group and group_x_client --- server/migrations/20180717202333-create-group_x_group.js | 2 ++ server/migrations/20180717202533-create-group_x_client.js | 2 ++ 2 files changed, 4 insertions(+) (limited to 'server/migrations') diff --git a/server/migrations/20180717202333-create-group_x_group.js b/server/migrations/20180717202333-create-group_x_group.js index 4263f9a..a40278d 100644 --- a/server/migrations/20180717202333-create-group_x_group.js +++ b/server/migrations/20180717202333-create-group_x_group.js @@ -6,6 +6,7 @@ module.exports = { primaryKey: true, allowNull: false, type: Sequelize.INTEGER, + onDelete: "cascade", references: { model: 'groups', key: 'id' @@ -15,6 +16,7 @@ module.exports = { primaryKey: true, allowNull: false, type: Sequelize.INTEGER, + onDelete: "cascade", references: { model: 'groups', key: 'id' diff --git a/server/migrations/20180717202533-create-group_x_client.js b/server/migrations/20180717202533-create-group_x_client.js index e3bd490..2330cdb 100644 --- a/server/migrations/20180717202533-create-group_x_client.js +++ b/server/migrations/20180717202533-create-group_x_client.js @@ -6,6 +6,7 @@ module.exports = { primaryKey: true, allowNull: false, type: Sequelize.INTEGER, + onDelete: "cascade", references: { model: 'groups', key: 'id' @@ -15,6 +16,7 @@ module.exports = { primaryKey: true, allowNull: false, type: Sequelize.INTEGER, + onDelete: "cascade", references: { model: 'clients', key: 'id' -- cgit v1.2.3-55-g7522 From cb7711cc9f76fe4211538bad74de68c57cd07e83 Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Tue, 31 Jul 2018 02:20:37 +0000 Subject: [groups] add edit form for groups; add description to groups and clients --- server/api/clients.js | 22 +++-- server/api/groups.js | 63 ++++++------ server/migrations/20180717132233-create-group.js | 3 + server/migrations/20180717132333-create-client.js | 3 + server/models/client.js | 1 + server/models/group.js | 3 +- webapp/src/components/GroupModule.vue | 48 ++++----- webapp/src/components/GroupModuleClientList.vue | 80 +++++++++------ webapp/src/components/GroupModuleClientView.vue | 32 ++++++ webapp/src/components/GroupModuleEditDialog.vue | 83 ---------------- webapp/src/components/GroupModuleGroupList.vue | 75 +++++++------- webapp/src/components/GroupModuleGroupView.vue | 114 ++++++++++++++++++++-- webapp/src/store/groups.js | 114 ++++++++++++++++------ 13 files changed, 397 insertions(+), 244 deletions(-) create mode 100644 webapp/src/components/GroupModuleClientView.vue delete mode 100644 webapp/src/components/GroupModuleEditDialog.vue (limited to 'server/migrations') diff --git a/server/api/clients.js b/server/api/clients.js index 37e207b..d494fd0 100644 --- a/server/api/clients.js +++ b/server/api/clients.js @@ -2,17 +2,19 @@ var path = require('path') var db = require(path.join(__appdir, 'lib', 'sequelize')) -module.exports = { - get: { - - getInfo: function (req, res) { - db.client.findOne({ where: { id: req.query.id } }).then(client => { - res.send(client) - }) - } - +// GET Requests +module.exports.get = { + getList: function (req, res) { + db.client.findAll({ attributes: ['id', 'name'] }).then(list => { + res.send(list) + }) }, - post: { + getGroups: function (req, res) { + db.client.findOne({ where: { id: req.query.id } }).then(client => { + client.getGroups().then(groups => { + res.send(groups) + }) + }) } } diff --git a/server/api/groups.js b/server/api/groups.js index ff29799..fa2c1ca 100644 --- a/server/api/groups.js +++ b/server/api/groups.js @@ -2,41 +2,44 @@ var path = require('path') var db = require(path.join(__appdir, 'lib', 'sequelize')) -module.exports = { - get: { - - getParents: function (req, res) { - const id = req.query.id > 0 ? req.query.id : null - db.group.findOne({ where: { id: id }, include: ['parents'] }).then(group => { - group.getParents().then(parents => { - res.send(parents.map(x => ({ id: x.id, name: x.name }))) - }) - }) - }, - - getSubGroups: function (req, res) { - const id = req.query.id > 0 ? req.query.id : null - db.group.findAll({ where: { '$parents.id$': id }, include: ['parents'] }).then(result => { - res.send(result) - }) - }, +// GET Requests +module.exports.get = { + getList: function (req, res) { + db.group.findAll({ attributes: ['id', 'name'] }).then(list => { + res.send(list) + }) + }, - getClients: function (req, res) { - const id = req.query.id > 0 ? req.query.id : null - db.client.findAll({ where: { '$groups.id$': id }, include: ['groups'] }).then(result => { - res.send(result) + getParents: function (req, res) { + const id = req.query.id > 0 ? req.query.id : null + db.group.findOne({ where: { id: id }, include: ['parents'] }).then(group => { + group.getParents().then(parents => { + res.send(parents) }) - } + }) + }, + getSubGroups: function (req, res) { + const id = req.query.id > 0 ? req.query.id : null + db.group.findAll({ where: { '$parents.id$': id }, include: ['parents'] }).then(subgroups => { + res.send(subgroups) + }) }, - post: { - update: function (req, res) { - const id = req.body.id > 0 ? req.body.id : null - if (!id) res.end() - db.group.update({ name: req.body.name }, { where: { id: id } }) - res.end() - } + getClients: function (req, res) { + const id = req.query.id > 0 ? req.query.id : null + db.client.findAll({ where: { '$groups.id$': id }, include: ['groups'] }).then(clients => { + res.send(clients) + }) + } +} +// POST Requests +module.exports.post = { + update: function (req, res) { + const id = req.body.id > 0 ? req.body.id : null + if (!id) res.end() + db.group.update({ name: req.body.name }, { where: { id: id } }) + res.end() } } diff --git a/server/migrations/20180717132233-create-group.js b/server/migrations/20180717132233-create-group.js index 720a1e7..71258dd 100644 --- a/server/migrations/20180717132233-create-group.js +++ b/server/migrations/20180717132233-create-group.js @@ -10,6 +10,9 @@ module.exports = { }, name: { type: Sequelize.STRING + }, + description: { + type: Sequelize.STRING } }) }, diff --git a/server/migrations/20180717132333-create-client.js b/server/migrations/20180717132333-create-client.js index 79552c4..955f2f9 100644 --- a/server/migrations/20180717132333-create-client.js +++ b/server/migrations/20180717132333-create-client.js @@ -11,6 +11,9 @@ module.exports = { name: { type: Sequelize.STRING }, + description: { + type: Sequelize.STRING + }, ip: { type: Sequelize.STRING }, diff --git a/server/models/client.js b/server/models/client.js index 1086023..483d1e6 100644 --- a/server/models/client.js +++ b/server/models/client.js @@ -8,6 +8,7 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.INTEGER }, name: DataTypes.STRING, + description: DataTypes.STRING, ip: DataTypes.STRING, mac: DataTypes.STRING, uuid: DataTypes.STRING diff --git a/server/models/group.js b/server/models/group.js index 223df07..e988497 100644 --- a/server/models/group.js +++ b/server/models/group.js @@ -7,7 +7,8 @@ module.exports = (sequelize, DataTypes) => { primaryKey: true, type: DataTypes.INTEGER }, - name: DataTypes.STRING + name: DataTypes.STRING, + description: DataTypes.STRING }, { timestamps: false }) diff --git a/webapp/src/components/GroupModule.vue b/webapp/src/components/GroupModule.vue index 123f847..b690628 100644 --- a/webapp/src/components/GroupModule.vue +++ b/webapp/src/components/GroupModule.vue @@ -12,60 +12,64 @@ - - diff --git a/webapp/src/components/GroupModuleClientList.vue b/webapp/src/components/GroupModuleClientList.vue index 8f9c306..20ae332 100644 --- a/webapp/src/components/GroupModuleClientList.vue +++ b/webapp/src/components/GroupModuleClientList.vue @@ -52,10 +52,9 @@ + + + diff --git a/webapp/src/store/groups.js b/webapp/src/store/groups.js index 6c5a23c..45fa59b 100644 --- a/webapp/src/store/groups.js +++ b/webapp/src/store/groups.js @@ -6,42 +6,28 @@ export default { state: { groupList: [], clientList: [], - groupCache: {}, - clientCache: {}, - groupChain: [], - client: null, + tabChain: [], activeTab: 0 }, mutations: { setGroupList: (state, list) => { state.groupList = list }, setClientList: (state, list) => { state.clientList = list }, - setActiveTab: (state, tabIndex) => { state.activeTab = tabIndex }, - setGroupChain: (state, chain) => { state.groupChain = chain }, - setClient: (state, id) => { state.client = state.clientCache[id] }, - setGroupInChain (state, { id, tabIndex }) { - if (state.groupChain.length <= tabIndex || state.groupChain[tabIndex].id !== id) { - state.client = null - state.groupChain = state.groupChain.slice(0, tabIndex) - state.groupChain.push(state.groupCache[id]) - } - }, - cacheGroup (state, group) { - if ('id' in group) { - if (!(group.id in state.groupCache)) state.groupCache[group.id] = group - else Object.keys(group).forEach(key => { Vue.set(state.groupCache[group.id], key, group[key]) }) - } - }, - cacheClient (state, client) { - if ('id' in client) { - if (!(client.id in state.clientCache)) state.clientCache[client.id] = client - else Object.keys(client).forEach(key => { Vue.set(state.clientCache[client.id], key, client[key]) }) + setActiveTab: (state, index) => { state.activeTab = index }, + deleteFromTabChain: (state, { index, count }) => { state.tabChain.splice(index, count) }, + setTab: (state, { index, item }) => { + if (state.tabChain.length > index && state.tabChain[index].id === item.id) { + Object.keys(item).forEach(key => { + Vue.set(state.tabChain[index], key, item[key]) + }) + } else { + state.tabChain = state.tabChain.slice(0, index) + state.tabChain.push(item) } }, resetStore (state) { state.groupList = [] state.clientList = [] - state.groupCache = {} - state.clientCache = {} + state.home = null state.groupChain = [] state.client = null state.activeTab = 0 @@ -49,60 +35,49 @@ export default { }, actions: { loadLists (context) { - var getGroupList = axios.get('/api/groups/getList') - var getClientList = axios.get('/api/clients/getList') - axios.all([getGroupList, getClientList]).then(axios.spread((groupResponse, clientResponse) => { - context.commit('setGroupList', groupResponse.data.map(x => ({ value: x.id, text: x.name || x.id }))) - context.commit('setClientList', clientResponse.data.map(x => ({ value: x.id, text: x.name || x.id }))) - })) + Promise.all([axios.get('/api/groups/getList'), axios.get('/api/clients/getList')]).then(res => { + context.commit('setGroupList', res[0].data.map(x => ({ value: x.id, text: x.name || x.id }))) + context.commit('setClientList', res[1].data.map(x => ({ value: x.id, text: x.name || x.id }))) + }) }, - loadRoot (context) { - var getGroups = axios.get('/api/groups/getSubGroups?id=' + 0) - var getClients = axios.get('/api/groups/getClients?id=' + 0) - axios.all([getGroups, getClients]).then(axios.spread((groupResponse, clientResponse) => { - groupResponse.data.forEach(group => { context.commit('cacheGroup', group) }) - clientResponse.data.forEach(client => { context.commit('cacheClient', client) }) - context.commit('setGroupChain', [{ id: 0, subGroups: groupResponse.data, clients: clientResponse.data }]) - })) + loadHome (context) { + Promise.all([axios.get('/api/groups/getTopLevel'), axios.get('/api/clients/getTopLevel')]).then(res => { + context.commit('setTab', { index: 0, item: { tabType: 'home', groups: res[0].data, clients: res[1].data } }) + }) }, - loadGroupIntoTab (context, { id, tabIndex }) { - var cached = null - if (context.state.groupCache[id].fullyCached) { - cached = new Promise(resolve => resolve()) - } else { - var getParents = axios.get('/api/groups/getParents?id=' + id) - var getSubGroups = axios.get('/api/groups/getSubGroups?id=' + id) - var getClients = axios.get('/api/groups/getClients?id=' + id) - cached = axios.all([getParents, getSubGroups, getClients]).then(axios.spread((parentResponse, groupResponse, clientResponse) => { - parentResponse.data.forEach(group => { context.commit('cacheGroup', group) }) - groupResponse.data.forEach(group => { context.commit('cacheGroup', group) }) - clientResponse.data.forEach(client => { context.commit('cacheClient', client) }) - context.commit('cacheGroup', { - id, - fullyCached: true, - parents: parentResponse.data.map(x => context.state.groupCache[x.id]), - subGroups: groupResponse.data.map(x => context.state.groupCache[x.id]), - clients: clientResponse.data.map(x => context.state.clientCache[x.id]) - }) - })) - } - cached.then(() => { - context.commit('setGroupInChain', { id, tabIndex }) - context.commit('setActiveTab', tabIndex) + loadGroup (context, { id, tabIndex, switchTab }) { + axios.get('/api/groups/getGroup?id=' + id).then(res => { + res.data.tabType = 'group' + context.commit('setTab', { index: tabIndex, item: res.data }) + if (switchTab) context.commit('setActiveTab', tabIndex) }) }, - loadClientIntoTab (context, id) { - var cached = null - if (context.state.clientCache[id].fullyCached) { - cached = new Promise(resolve => resolve()) - } else { - cached = axios.get('/api/clients/getGroups?id=' + id).then(response => { - context.commit('cacheClient', { id, fullyCached: true, groups: response.data.map(x => context.state.groupCache[x.id]) }) - }) - } - cached.then(() => { - context.commit('setClient', id) - context.commit('setActiveTab', context.state.groupChain.length) + loadClient (context, { id, tabIndex, switchTab }) { + axios.get('/api/clients/getClient?id=' + id).then(res => { + res.data.tabType = 'client' + context.commit('setTab', { index: tabIndex, item: res.data }) + if (switchTab) context.commit('setActiveTab', tabIndex) + }) + }, + reload (context) { + context.state.tabChain.forEach((item, index) => { + if (item.tabType === 'home') context.dispatch('loadHome') + else if (item.tabType === 'group') context.dispatch('loadGroup', { id: item.id, tabIndex: index }) + else if (item.tabType === 'client') context.dispatch('loadClient', { id: item.id, tabIndex: index }) + }) + }, + saveGroupInfo (context, { id, info, tabIndex }) { + axios.post('/api/groups/saveInfo', { + id, + name: info.name, + description: info.description, + parentIds: info.parentIds + }).then(res => { + if (tabIndex > 1 && !(context.state.tabChain[tabIndex - 1].id in info.parentIds)) { + context.commit('deleteFromTabChain', { index: 1, count: tabIndex - 1 }) + context.commit('setActiveTab', 1) + } + context.dispatch('reload') }) } } -- cgit v1.2.3-55-g7522 From cee3b5539762d12ad8b22e90404b76219886af44 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Thu, 2 Aug 2018 21:17:50 +0000 Subject: [server/external-backends] Added sync settings for the backends. Method for getting the backend oject types and the client / group mapping saved in the db. --- server/api/backends.js | 34 ++++++++++++++++++++++ .../external-backends/backends/idoit-backend.js | 32 ++++++++++++++++++-- server/lib/external-backends/external-backends.js | 5 ++++ server/migrations/20180715193710-create-backend.js | 17 ++++++++++- server/models/backend.js | 19 +++++++++++- 5 files changed, 102 insertions(+), 5 deletions(-) (limited to 'server/migrations') diff --git a/server/api/backends.js b/server/api/backends.js index 3d7c36e..2b82cab 100644 --- a/server/api/backends.js +++ b/server/api/backends.js @@ -58,6 +58,28 @@ module.exports.get = { res.status(200).send(result) }) }) + }, + + getObjectTypes: function (req, res) { + const id = req.query.id + db.backend.findOne({ where: { id: id } }).then(backend => { + const ba = new ExternalBackends() + const instance = ba.getInstance(backend.type) + console.log(backend.type) + instance.getObjectTypes(backend.credentials).then(result => { + res.status(200).send(result) + }) + }) + }, + + getObjectTypesById: function (req, res) { + const id = req.query.id + var types = {} + db.backend.findOne({ where: { id: id } }).then(backend => { + types.groups = JSON.parse(backend.groups) + types.clients = JSON.parse(backend.clients) + res.status(200).send(types) + }) } } @@ -105,5 +127,17 @@ module.exports.post = { res.status(200).send({ success: connection.success, msg: connection.msg }) }) }) + }, + + // Saves the group / clients assigned object types in the database. + saveObjectTypes: function (req, res) { + const id = req.body.id + const groups = JSON.stringify(req.body.groups) + const clients = JSON.stringify(req.body.clients) + db.backend.findOne({ where: { id: id } }).then(backend => { + db.backend.update({ groups: groups, clients: clients }, { where: { id: id } }).then(() => { + res.status(200).send() + }) + }) } } diff --git a/server/lib/external-backends/backends/idoit-backend.js b/server/lib/external-backends/backends/idoit-backend.js index cdd4dde..de41481 100644 --- a/server/lib/external-backends/backends/idoit-backend.js +++ b/server/lib/external-backends/backends/idoit-backend.js @@ -26,6 +26,35 @@ class IdoitBackend extends ExternalBackends { return this.getSession(c) } + // Return the list of object types created in iDoIT. + async getObjectTypes (credentials) { + var c = this.mapCredentials(credentials) + var login = await this.getSession(c) + var sid = login.data.result['session-id'] + + // Headers + var headers = { + 'X-RPC-Auth-Session': sid + } + + // Params + var params = { + 'apikey': c.apikey, + 'language': 'en' + } + + var result = {} + result.types = await this.axiosRequest(c.url, 'cmdb.object_types', params, headers) + result.types = result.types.data.result + + var types = [] + result.types.forEach(type => { + types.push({ id: type.id, title: type.title }) + }) + + return types + } + // Optional functions e.g. helperfunctions or testing stuff. // Helper function, to map the array of credential objects into a single js object. @@ -68,9 +97,6 @@ class IdoitBackend extends ExternalBackends { result.object = result.object.data.result result.childs = result.childs.data.result - console.log(result) - // Make an request to read the object - //return this.axiosRequest(c.url, 'cmdb.location_tree', params, headers) return result } diff --git a/server/lib/external-backends/external-backends.js b/server/lib/external-backends/external-backends.js index 7d306b3..20f8ce6 100644 --- a/server/lib/external-backends/external-backends.js +++ b/server/lib/external-backends/external-backends.js @@ -31,6 +31,11 @@ class ExternalBackends { console.log('If this method gets called the backend class has NOT IMPLEMENTED the checkConnection method!') return null } + + // Return an empty array [] if the backends doesn't have such a function. + async getObjectTypes (credentials) { + return [] + } } module.exports = ExternalBackends diff --git a/server/migrations/20180715193710-create-backend.js b/server/migrations/20180715193710-create-backend.js index e89362e..98f5476 100644 --- a/server/migrations/20180715193710-create-backend.js +++ b/server/migrations/20180715193710-create-backend.js @@ -15,7 +15,22 @@ module.exports = { type: Sequelize.STRING }, credentials: { - type: Sequelize.STRING(2048) + allowNull: false, + type: Sequelize.STRING(2048), + defaultValue: '[]' + }, + groups: { + allowNull: false, + type: Sequelize.STRING(4096), + defaultValue: '[]' + }, + clients: { + allowNull: false, + type: Sequelize.STRING(4096), + defaultValue: '[]' + }, + sync: { + type: Sequelize.STRING(1024) } }) }, diff --git a/server/models/backend.js b/server/models/backend.js index 4ed5fce..62b936a 100644 --- a/server/models/backend.js +++ b/server/models/backend.js @@ -9,7 +9,24 @@ module.exports = (sequelize, DataTypes) => { }, name: DataTypes.STRING, type: DataTypes.STRING, - credentials: DataTypes.STRING(2048) + credentials: { + allowNull: false, + type: DataTypes.STRING(2048), + defaultValue: '[]' + }, + groups: { + allowNull: false, + type: DataTypes.STRING(4096), + defaultValue: '[]' + }, + clients: { + allowNull: false, + type: DataTypes.STRING(4096), + defaultValue: '[]' + }, + sync: { + type: DataTypes.STRING(1024) + } }, { timestamps: false }) -- cgit v1.2.3-55-g7522