feat: authentication providers resolver - filter + orderBy
This commit is contained in:
@@ -30,6 +30,8 @@
|
||||
<script>
|
||||
/* global CONSTANTS, graphQL, siteConfig */
|
||||
|
||||
import _ from 'lodash'
|
||||
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
@@ -68,13 +70,10 @@ export default {
|
||||
refreshStrategies () {
|
||||
this.isLoading = true
|
||||
graphQL.query({
|
||||
query: CONSTANTS.GRAPHQL.GQL_QUERY_AUTHENTICATION,
|
||||
variables: {
|
||||
mode: 'active'
|
||||
}
|
||||
query: CONSTANTS.GRAPH.AUTHENTICATION.QUERY_LOGIN_PROVIDERS
|
||||
}).then(resp => {
|
||||
if (resp.data.authentication) {
|
||||
this.strategies = resp.data.authentication
|
||||
if (_.has(resp, 'data.authentication.providers')) {
|
||||
this.strategies = _.get(resp, 'data.authentication.providers', [])
|
||||
} else {
|
||||
throw new Error('No authentication providers available!')
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ export default {
|
||||
props
|
||||
title
|
||||
useForm
|
||||
icon
|
||||
config {
|
||||
key
|
||||
value
|
||||
@@ -19,6 +18,21 @@ export default {
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
QUERY_LOGIN_PROVIDERS: gql`
|
||||
query {
|
||||
authentication {
|
||||
providers(
|
||||
filter: "isEnabled eq true",
|
||||
orderBy: "title ASC"
|
||||
) {
|
||||
key
|
||||
title
|
||||
useForm
|
||||
icon
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
},
|
||||
GQL_QUERY_TRANSLATIONS: gql`
|
||||
|
||||
22
package.json
22
package.json
@@ -66,6 +66,7 @@
|
||||
"follow-redirects": "1.4.1",
|
||||
"fs-extra": "5.0.0",
|
||||
"graphql": "0.13.1",
|
||||
"graphql-list-fields": "2.0.1",
|
||||
"graphql-tools": "2.21.0",
|
||||
"i18next": "10.5.0",
|
||||
"i18next-express-middleware": "1.1.1",
|
||||
@@ -82,7 +83,7 @@
|
||||
"markdown-it-anchor": "4.0.0",
|
||||
"markdown-it-attrs": "1.2.1",
|
||||
"markdown-it-emoji": "1.4.0",
|
||||
"markdown-it-expand-tabs": "1.0.12",
|
||||
"markdown-it-expand-tabs": "1.0.13",
|
||||
"markdown-it-external-links": "0.0.6",
|
||||
"markdown-it-footnote": "3.0.1",
|
||||
"markdown-it-imsize": "2.0.1",
|
||||
@@ -90,7 +91,7 @@
|
||||
"markdown-it-mathjax": "2.0.0",
|
||||
"markdown-it-sub": "1.0.0",
|
||||
"markdown-it-sup": "1.0.0",
|
||||
"markdown-it-task-lists": "2.1.0",
|
||||
"markdown-it-task-lists": "2.1.1",
|
||||
"mathjax-node": "2.0.1",
|
||||
"mime-types": "2.1.18",
|
||||
"moment": "2.21.0",
|
||||
@@ -118,13 +119,14 @@
|
||||
"pg-hstore": "2.3.2",
|
||||
"pg-promise": "7.5.3",
|
||||
"pm2": "2.10.1",
|
||||
"pug": "2.0.0-rc.4",
|
||||
"pug": "2.0.1",
|
||||
"qr-image": "3.2.0",
|
||||
"raven": "2.4.2",
|
||||
"read-chunk": "2.1.0",
|
||||
"remove-markdown": "0.2.2",
|
||||
"request": "2.83.0",
|
||||
"request-promise": "4.2.2",
|
||||
"scim-query-filter-parser": "1.1.0",
|
||||
"semver": "5.5.0",
|
||||
"sequelize": "4.35.2",
|
||||
"serve-favicon": "2.4.5",
|
||||
@@ -144,7 +146,7 @@
|
||||
"babel-core": "6.26.0",
|
||||
"babel-eslint": "8.2.2",
|
||||
"babel-jest": "22.4.1",
|
||||
"babel-loader": "7.1.3",
|
||||
"babel-loader": "7.1.4",
|
||||
"babel-plugin-graphql-tag": "1.5.0",
|
||||
"babel-plugin-lodash": "3.3.2",
|
||||
"babel-plugin-transform-imports": "1.5.0",
|
||||
@@ -154,7 +156,7 @@
|
||||
"babel-preset-stage-2": "6.24.1",
|
||||
"brace": "0.11.1",
|
||||
"cache-loader": "1.2.2",
|
||||
"clean-webpack-plugin": "0.1.18",
|
||||
"clean-webpack-plugin": "0.1.19",
|
||||
"colors": "1.1.2",
|
||||
"copy-webpack-plugin": "4.5.0",
|
||||
"css-loader": "0.28.10",
|
||||
@@ -165,7 +167,7 @@
|
||||
"eslint-config-standard": "11.0.0",
|
||||
"eslint-plugin-import": "2.9.0",
|
||||
"eslint-plugin-node": "6.0.1",
|
||||
"eslint-plugin-promise": "3.6.0",
|
||||
"eslint-plugin-promise": "3.7.0",
|
||||
"eslint-plugin-standard": "3.0.1",
|
||||
"eslint-plugin-vue": "4.3.0",
|
||||
"extract-text-webpack-plugin": "3.0.2",
|
||||
@@ -188,7 +190,7 @@
|
||||
"raw-loader": "0.5.1",
|
||||
"sass-loader": "6.0.7",
|
||||
"sass-resources-loader": "1.3.3",
|
||||
"simple-progress-webpack-plugin": "1.1.1",
|
||||
"simple-progress-webpack-plugin": "1.1.2",
|
||||
"style-loader": "0.20.2",
|
||||
"stylus": "0.54.5",
|
||||
"stylus-loader": "3.0.2",
|
||||
@@ -201,12 +203,12 @@
|
||||
"vue-clipboards": "1.2.2",
|
||||
"vue-codemirror": "4.0.3",
|
||||
"vue-hot-reload-api": "2.3.0",
|
||||
"vue-loader": "14.1.1",
|
||||
"vue-material-design-icons": "1.1.0",
|
||||
"vue-loader": "14.2.1",
|
||||
"vue-material-design-icons": "1.2.1",
|
||||
"vue-router": "3.0.1",
|
||||
"vue-simple-breakpoints": "1.0.3",
|
||||
"vue-template-compiler": "2.5.13",
|
||||
"vuetify": "1.0.4",
|
||||
"vuetify": "1.0.5",
|
||||
"vuex": "3.0.1",
|
||||
"vuex-persistedstate": "2.4.2",
|
||||
"webpack": "3.11.0",
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
const _ = require('lodash')
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
const graphHelper = require('../../helpers/graph')
|
||||
|
||||
// const getFieldNames = require('graphql-list-fields')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
@@ -13,16 +16,17 @@ module.exports = {
|
||||
},
|
||||
AuthenticationQuery: {
|
||||
providers(obj, args, context, info) {
|
||||
return _.chain(WIKI.auth.strategies).map(str => {
|
||||
return {
|
||||
isEnabled: true,
|
||||
key: str.key,
|
||||
props: str.props,
|
||||
title: str.title,
|
||||
useForm: str.useForm,
|
||||
config: []
|
||||
}
|
||||
}).sortBy(['title']).value()
|
||||
let prv = _.map(WIKI.auth.strategies, str => ({
|
||||
isEnabled: true,
|
||||
key: str.key,
|
||||
props: str.props,
|
||||
title: str.title,
|
||||
useForm: str.useForm,
|
||||
config: []
|
||||
}))
|
||||
if (args.filter) { prv = graphHelper.filter(prv, args.filter) }
|
||||
if (args.orderBy) { prv = graphHelper.orderBy(prv, args.orderBy) }
|
||||
return prv
|
||||
}
|
||||
},
|
||||
AuthenticationProvider: {
|
||||
|
||||
@@ -7,7 +7,10 @@ extend type Mutation {
|
||||
}
|
||||
|
||||
type AuthenticationQuery {
|
||||
providers: [AuthenticationProvider]
|
||||
providers(
|
||||
filter: String
|
||||
orderBy: String
|
||||
): [AuthenticationProvider]
|
||||
}
|
||||
|
||||
type AuthenticationMutation {
|
||||
|
||||
13
server/helpers/graph.js
Normal file
13
server/helpers/graph.js
Normal file
@@ -0,0 +1,13 @@
|
||||
const _ = require('lodash')
|
||||
const Filter = require('scim-query-filter-parser')
|
||||
|
||||
module.exports = {
|
||||
filter (arr, filterString) {
|
||||
const prvFilter = new Filter(_.toString(filterString).replace(/'/g, `"`))
|
||||
return arr.filter(prvFilter.test)
|
||||
},
|
||||
orderBy (arr, orderString) {
|
||||
let orderParams = _.zip(orderString.split(',').map(ord => _.trim(ord).split(' ').map(_.trim)))
|
||||
return _.orderBy(arr, orderParams[0], orderParams[1])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user