feat: admin logging + search

This commit is contained in:
Nicolas Giard
2018-09-01 22:37:20 -04:00
parent 5919d14670
commit 019537563e
15 changed files with 550 additions and 69 deletions

View File

@@ -0,0 +1,59 @@
const _ = require('lodash')
const graphHelper = require('../../helpers/graph')
/* global WIKI */
module.exports = {
Query: {
async logging() { return {} }
},
Mutation: {
async logging() { return {} }
},
LoggingQuery: {
async loggers(obj, args, context, info) {
let loggers = await WIKI.models.loggers.getLoggers()
loggers = loggers.map(logger => {
const loggerInfo = _.find(WIKI.data.loggers, ['key', logger.key]) || {}
return {
...loggerInfo,
...logger,
config: _.sortBy(_.transform(logger.config, (res, value, key) => {
const configData = _.get(loggerInfo.props, key, {})
res.push({
key,
value: JSON.stringify({
...configData,
value
})
})
}, []), 'key')
}
})
if (args.filter) { loggers = graphHelper.filter(loggers, args.filter) }
if (args.orderBy) { loggers = graphHelper.orderBy(loggers, args.orderBy) }
return loggers
}
},
LoggingMutation: {
async updateLoggers(obj, args, context) {
try {
for (let logger of args.loggers) {
await WIKI.models.loggers.query().patch({
isEnabled: logger.isEnabled,
level: logger.level,
config: _.reduce(logger.config, (result, value, key) => {
_.set(result, `${value.key}`, value.value)
return result
}, {})
}).where('key', logger.key)
}
return {
responseResult: graphHelper.generateSuccess('Loggers updated successfully')
}
} catch (err) {
return graphHelper.generateError(err)
}
}
}
}

View File

@@ -0,0 +1,58 @@
const _ = require('lodash')
const graphHelper = require('../../helpers/graph')
/* global WIKI */
module.exports = {
Query: {
async search() { return {} }
},
Mutation: {
async search() { return {} }
},
SearchQuery: {
async searchEngines(obj, args, context, info) {
let searchEngines = await WIKI.models.searchEngines.getSearchEngines()
searchEngines = searchEngines.map(searchEngine => {
const searchEngineInfo = _.find(WIKI.data.searchEngines, ['key', searchEngine.key]) || {}
return {
...searchEngineInfo,
...searchEngine,
config: _.sortBy(_.transform(searchEngine.config, (res, value, key) => {
const configData = _.get(searchEngineInfo.props, key, {})
res.push({
key,
value: JSON.stringify({
...configData,
value
})
})
}, []), 'key')
}
})
if (args.filter) { searchEngines = graphHelper.filter(searchEngines, args.filter) }
if (args.orderBy) { searchEngines = graphHelper.orderBy(searchEngines, args.orderBy) }
return searchEngines
}
},
SearchMutation: {
async updateSearchEngines(obj, args, context) {
try {
for (let searchEngine of args.searchEngines) {
await WIKI.models.searchEngines.query().patch({
isEnabled: searchEngine.isEnabled,
config: _.reduce(searchEngine.config, (result, value, key) => {
_.set(result, `${value.key}`, value.value)
return result
}, {})
}).where('key', searchEngine.key)
}
return {
responseResult: graphHelper.generateSuccess('Search Engines updated successfully')
}
} catch (err) {
return graphHelper.generateError(err)
}
}
}
}

View File

@@ -92,12 +92,6 @@ type Right {
group: Group!
}
type SearchResult {
path: String
title: String
tags: [String]
}
type Setting {
id: Int!
createdAt: Date
@@ -133,7 +127,6 @@ type Query {
files(id: Int): [File]
folders(id: Int, name: String): [Folder]
rights(id: Int): [Right]
search(q: String, tags: [String]): [SearchResult]
settings(key: String): [Setting]
tags(key: String): [Tag]
translations(locale: String!, namespace: String!): [Translation]

View File

@@ -0,0 +1,54 @@
# ===============================================
# LOGGING
# ===============================================
extend type Query {
logging: LoggingQuery
}
extend type Mutation {
logging: LoggingMutation
}
# -----------------------------------------------
# QUERIES
# -----------------------------------------------
type LoggingQuery {
loggers(
filter: String
orderBy: String
): [Logger]
}
# -----------------------------------------------
# MUTATIONS
# -----------------------------------------------
type LoggingMutation {
updateLoggers(
loggers: [LoggerInput]
): DefaultResponse
}
# -----------------------------------------------
# TYPES
# -----------------------------------------------
type Logger {
isEnabled: Boolean!
key: String!
title: String!
description: String
logo: String
website: String
level: String
config: [KeyValuePair]
}
input LoggerInput {
isEnabled: Boolean!
key: String!
level: String!
config: [KeyValuePairInput]
}

View File

@@ -0,0 +1,52 @@
# ===============================================
# SEARCH
# ===============================================
extend type Query {
search: SearchQuery
}
extend type Mutation {
search: SearchMutation
}
# -----------------------------------------------
# QUERIES
# -----------------------------------------------
type SearchQuery {
searchEngines(
filter: String
orderBy: String
): [SearchEngine]
}
# -----------------------------------------------
# MUTATIONS
# -----------------------------------------------
type SearchMutation {
updateSearchEngines(
searchEngines: [SearchEngineInput]
): DefaultResponse
}
# -----------------------------------------------
# TYPES
# -----------------------------------------------
type SearchEngine {
isEnabled: Boolean!
key: String!
title: String!
description: String
logo: String
website: String
config: [KeyValuePair]
}
input SearchEngineInput {
isEnabled: Boolean!
key: String!
config: [KeyValuePairInput]
}

View File

@@ -2,7 +2,7 @@ key: eventlog
title: Windows Event Log
description: Report logs to the Windows Event Log
author: requarks.io
logo: https://static.requarks.io/logo/windows.svg
logo: https://static.requarks.io/logo/windows-server.svg
website: https://wiki.js.org
defaultLevel: warn
props: {}

View File

@@ -2,6 +2,6 @@ key: aws
title: AWS CloudSearch
description: Amazon CloudSearch is a managed service in the AWS Cloud that makes it simple and cost-effective to set up, manage, and scale a search solution for your website or application.
author: requarks.io
logo: https://static.requarks.io/logo/aws.svg
logo: https://static.requarks.io/logo/aws-cloudsearch.svg
website: https://aws.amazon.com/cloudsearch/
props: {}

View File

@@ -2,6 +2,6 @@ key: db
title: Database (built-in)
description: Default database-based search engine.
author: requarks.io
logo: https://static.requarks.io/logo/db.svg
logo: https://static.requarks.io/logo/database.svg
website: https://www.requarks.io/
props: {}

View File

@@ -21,8 +21,7 @@ module.exports = () => {
const favicon = require('serve-favicon')
const http = require('http')
const Promise = require('bluebird')
const fs = Promise.promisifyAll(require('fs-extra'))
const yaml = require('js-yaml')
const fs = require('fs-extra')
const _ = require('lodash')
const cfgHelper = require('./helpers/config')
const crypto = Promise.promisifyAll(require('crypto'))