mirror of https://github.com/requarks/wiki
parent
2b98a5f27a
commit
fcee4c0945
@ -0,0 +1,38 @@
|
|||||||
|
mutation (
|
||||||
|
$host: String!
|
||||||
|
$title: String!
|
||||||
|
$description: String!
|
||||||
|
$keywords: String!
|
||||||
|
$robots: [String]!
|
||||||
|
$ga: String!
|
||||||
|
$company: String!
|
||||||
|
$hasLogo: Boolean!
|
||||||
|
$logoIsSquare: Boolean!
|
||||||
|
$featurePageRatings: Boolean!
|
||||||
|
$featurePageComments: Boolean!
|
||||||
|
$featurePersonalWikis: Boolean!
|
||||||
|
) {
|
||||||
|
site {
|
||||||
|
updateConfig(
|
||||||
|
host: $host,
|
||||||
|
title: $title,
|
||||||
|
description: $description,
|
||||||
|
keywords: $keywords,
|
||||||
|
robots: $robots,
|
||||||
|
ga: $ga,
|
||||||
|
company: $company,
|
||||||
|
hasLogo: $hasLogo,
|
||||||
|
logoIsSquare: $logoIsSquare,
|
||||||
|
featurePageRatings: $featurePageRatings,
|
||||||
|
featurePageComments: $featurePageComments,
|
||||||
|
featurePersonalWikis: $featurePersonalWikis
|
||||||
|
) {
|
||||||
|
responseResult {
|
||||||
|
succeeded
|
||||||
|
errorCode
|
||||||
|
slug
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
site {
|
||||||
|
config {
|
||||||
|
host
|
||||||
|
title
|
||||||
|
description
|
||||||
|
keywords
|
||||||
|
robots
|
||||||
|
ga
|
||||||
|
company
|
||||||
|
hasLogo
|
||||||
|
logoIsSquare
|
||||||
|
featurePageRatings
|
||||||
|
featurePageComments
|
||||||
|
featurePersonalWikis
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
After Width: | Height: | Size: 1.9 KiB |
@ -0,0 +1,56 @@
|
|||||||
|
const _ = require('lodash')
|
||||||
|
const graphHelper = require('../../helpers/graph')
|
||||||
|
|
||||||
|
/* global WIKI */
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
Query: {
|
||||||
|
async site() { return {} }
|
||||||
|
},
|
||||||
|
Mutation: {
|
||||||
|
async site() { return {} }
|
||||||
|
},
|
||||||
|
SiteQuery: {
|
||||||
|
async config(obj, args, context, info) {
|
||||||
|
return {
|
||||||
|
host: WIKI.config.host,
|
||||||
|
title: WIKI.config.title,
|
||||||
|
company: WIKI.config.company,
|
||||||
|
...WIKI.config.seo,
|
||||||
|
...WIKI.config.logo,
|
||||||
|
...WIKI.config.features
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
SiteMutation: {
|
||||||
|
async updateConfig(obj, args, context) {
|
||||||
|
try {
|
||||||
|
WIKI.config.host = args.host
|
||||||
|
WIKI.config.title = args.title
|
||||||
|
WIKI.config.company = args.company
|
||||||
|
WIKI.config.seo = {
|
||||||
|
description: args.description,
|
||||||
|
keywords: args.keywords,
|
||||||
|
robots: args.robots,
|
||||||
|
ga: args.ga
|
||||||
|
}
|
||||||
|
WIKI.config.logo = {
|
||||||
|
hasLogo: args.hasLogo,
|
||||||
|
logoIsSquare: args.logoIsSquare
|
||||||
|
}
|
||||||
|
WIKI.config.features = {
|
||||||
|
featurePageRatings: args.featurePageRatings,
|
||||||
|
featurePageComments: args.featurePageComments,
|
||||||
|
featurePersonalWikis: args.featurePersonalWikis
|
||||||
|
}
|
||||||
|
await WIKI.configSvc.saveToDb(['host', 'title', 'company', 'seo', 'logo', 'features'])
|
||||||
|
|
||||||
|
return {
|
||||||
|
responseResult: graphHelper.generateSuccess('Site configuration updated successfully')
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
return graphHelper.generateError(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
# ===============================================
|
||||||
|
# SITE
|
||||||
|
# ===============================================
|
||||||
|
|
||||||
|
extend type Query {
|
||||||
|
site: SiteQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
extend type Mutation {
|
||||||
|
site: SiteMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
# -----------------------------------------------
|
||||||
|
# QUERIES
|
||||||
|
# -----------------------------------------------
|
||||||
|
|
||||||
|
type SiteQuery {
|
||||||
|
config: SiteConfig @auth(requires: ["manage:system"])
|
||||||
|
}
|
||||||
|
|
||||||
|
# -----------------------------------------------
|
||||||
|
# MUTATIONS
|
||||||
|
# -----------------------------------------------
|
||||||
|
|
||||||
|
type SiteMutation {
|
||||||
|
updateConfig(
|
||||||
|
host: String!
|
||||||
|
title: String!
|
||||||
|
description: String!
|
||||||
|
keywords: String!
|
||||||
|
robots: [String]!
|
||||||
|
ga: String!
|
||||||
|
company: String!
|
||||||
|
hasLogo: Boolean!
|
||||||
|
logoIsSquare: Boolean!
|
||||||
|
featurePageRatings: Boolean!
|
||||||
|
featurePageComments: Boolean!
|
||||||
|
featurePersonalWikis: Boolean!
|
||||||
|
): DefaultResponse @auth(requires: ["manage:system"])
|
||||||
|
}
|
||||||
|
|
||||||
|
# -----------------------------------------------
|
||||||
|
# TYPES
|
||||||
|
# -----------------------------------------------
|
||||||
|
|
||||||
|
type SiteConfig {
|
||||||
|
host: String!
|
||||||
|
title: String!
|
||||||
|
description: String!
|
||||||
|
keywords: String!
|
||||||
|
robots: [String]!
|
||||||
|
ga: String!
|
||||||
|
company: String!
|
||||||
|
hasLogo: Boolean!
|
||||||
|
logoIsSquare: Boolean!
|
||||||
|
featurePageRatings: Boolean!
|
||||||
|
featurePageComments: Boolean!
|
||||||
|
featurePersonalWikis: Boolean!
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
/* global WIKI */
|
||||||
|
|
||||||
|
const _ = require('lodash')
|
||||||
|
const securityHelper = require('../helpers/security')
|
||||||
|
const Model = require('objection').Model
|
||||||
|
const moment = require('moment')
|
||||||
|
const nanoid = require('nanoid')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Users model
|
||||||
|
*/
|
||||||
|
module.exports = class UserKey extends Model {
|
||||||
|
static get tableName() { return 'userKeys' }
|
||||||
|
|
||||||
|
static get jsonSchema () {
|
||||||
|
return {
|
||||||
|
type: 'object',
|
||||||
|
required: ['kind', 'token', 'validUntil'],
|
||||||
|
|
||||||
|
properties: {
|
||||||
|
id: {type: 'integer'},
|
||||||
|
kind: {type: 'string'},
|
||||||
|
token: {type: 'string'},
|
||||||
|
createdAt: {type: 'string'},
|
||||||
|
validUntil: {type: 'string'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static get relationMappings() {
|
||||||
|
return {
|
||||||
|
user: {
|
||||||
|
relation: Model.BelongsToOneRelation,
|
||||||
|
modelClass: require('./users'),
|
||||||
|
join: {
|
||||||
|
from: 'userKeys.userId',
|
||||||
|
to: 'users.id'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async $beforeInsert(context) {
|
||||||
|
await super.$beforeInsert(context)
|
||||||
|
|
||||||
|
this.createdAt = moment.utc().toISOString()
|
||||||
|
}
|
||||||
|
|
||||||
|
static async generateToken ({ userId, kind }, context) {
|
||||||
|
const token = await nanoid()
|
||||||
|
await WIKI.models.userKeys.query().insert({
|
||||||
|
kind,
|
||||||
|
token,
|
||||||
|
validUntil: moment.utc().add(1, 'days').toISOString(),
|
||||||
|
userId
|
||||||
|
})
|
||||||
|
return token
|
||||||
|
}
|
||||||
|
|
||||||
|
static async validateToken ({ kind, token }, context) {
|
||||||
|
const res = await WIKI.models.userKeys.query().findOne({ kind, token }).eager('user')
|
||||||
|
if (res) {
|
||||||
|
await WIKI.models.userKeys.query().deleteById(res.id)
|
||||||
|
if (moment.utc().isAfter(moment.utc(res.validUntil))) {
|
||||||
|
throw new WIKI.Error.AuthValidationTokenInvalid()
|
||||||
|
}
|
||||||
|
return res.user
|
||||||
|
} else {
|
||||||
|
throw new WIKI.Error.AuthValidationTokenInvalid()
|
||||||
|
}
|
||||||
|
|
||||||
|
return token
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue