mirror of https://github.com/Requarks/wiki.git
22 changed files with 424 additions and 445 deletions
Unified View
Diff Options
-
14client/components/editor.vue
-
149client/components/editor/editor-code.vue
-
5client/components/nav-header.vue
-
113server/db/migrations/2.0.0.js
-
5server/db/models/groups.js
-
70server/db/models/pages.js
-
49server/db/models/tags.js
-
6server/db/models/users.js
-
51server/graph/resolvers/page.js
-
78server/graph/schemas/page.graphql
-
16server/models_old/_relations.js
-
16server/models_old/comment.js
-
64server/models_old/document.js
-
42server/models_old/file.js
-
22server/models_old/folder.js
-
16server/models_old/group.js
-
39server/models_old/locale.js
-
36server/models_old/right.js
-
26server/models_old/setting.js
-
22server/models_old/tag.js
-
6server/modules/authentication/local.js
-
24server/setup.js
@ -0,0 +1,70 @@ |
|||||
|
const Model = require('objection').Model |
||||
|
|
||||
|
/** |
||||
|
* Pages model |
||||
|
*/ |
||||
|
module.exports = class Page extends Model { |
||||
|
static get tableName() { return 'pages' } |
||||
|
|
||||
|
static get jsonSchema () { |
||||
|
return { |
||||
|
type: 'object', |
||||
|
required: ['path', 'title'], |
||||
|
|
||||
|
properties: { |
||||
|
id: {type: 'integer'}, |
||||
|
path: {type: 'string'}, |
||||
|
title: {type: 'string'}, |
||||
|
description: {type: 'string'}, |
||||
|
isPublished: {type: 'boolean'}, |
||||
|
publishStartDate: {type: 'string'}, |
||||
|
publishEndDate: {type: 'string'}, |
||||
|
content: {type: 'string'}, |
||||
|
|
||||
|
createdAt: {type: 'string'}, |
||||
|
updatedAt: {type: 'string'} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
static get relationMappings() { |
||||
|
return { |
||||
|
tags: { |
||||
|
relation: Model.ManyToManyRelation, |
||||
|
modelClass: require('./tags'), |
||||
|
join: { |
||||
|
from: 'pages.id', |
||||
|
through: { |
||||
|
from: 'pageTags.pageId', |
||||
|
to: 'pageTags.tagId' |
||||
|
}, |
||||
|
to: 'tags.id' |
||||
|
} |
||||
|
}, |
||||
|
author: { |
||||
|
relation: Model.BelongsToOneRelation, |
||||
|
modelClass: require('./users'), |
||||
|
join: { |
||||
|
from: 'pages.authorId', |
||||
|
to: 'users.id' |
||||
|
} |
||||
|
}, |
||||
|
locale: { |
||||
|
relation: Model.BelongsToOneRelation, |
||||
|
modelClass: require('./locales'), |
||||
|
join: { |
||||
|
from: 'users.locale', |
||||
|
to: 'locales.code' |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$beforeUpdate() { |
||||
|
this.updatedAt = new Date().toISOString() |
||||
|
} |
||||
|
$beforeInsert() { |
||||
|
this.createdAt = new Date().toISOString() |
||||
|
this.updatedAt = new Date().toISOString() |
||||
|
} |
||||
|
} |
@ -0,0 +1,49 @@ |
|||||
|
const Model = require('objection').Model |
||||
|
|
||||
|
/** |
||||
|
* Tags model |
||||
|
*/ |
||||
|
module.exports = class Tag extends Model { |
||||
|
static get tableName() { return 'tags' } |
||||
|
|
||||
|
static get jsonSchema () { |
||||
|
return { |
||||
|
type: 'object', |
||||
|
required: ['tag'], |
||||
|
|
||||
|
properties: { |
||||
|
id: {type: 'integer'}, |
||||
|
tag: {type: 'string'}, |
||||
|
title: {type: 'string'}, |
||||
|
|
||||
|
createdAt: {type: 'string'}, |
||||
|
updatedAt: {type: 'string'} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
static get relationMappings() { |
||||
|
return { |
||||
|
pages: { |
||||
|
relation: Model.ManyToManyRelation, |
||||
|
modelClass: require('./pages'), |
||||
|
join: { |
||||
|
from: 'tags.id', |
||||
|
through: { |
||||
|
from: 'pageTags.tagId', |
||||
|
to: 'pageTags.pageId' |
||||
|
}, |
||||
|
to: 'pages.id' |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$beforeUpdate() { |
||||
|
this.updatedAt = new Date().toISOString() |
||||
|
} |
||||
|
$beforeInsert() { |
||||
|
this.createdAt = new Date().toISOString() |
||||
|
this.updatedAt = new Date().toISOString() |
||||
|
} |
||||
|
} |
@ -0,0 +1,51 @@ |
|||||
|
const graphHelper = require('../../helpers/graph') |
||||
|
|
||||
|
/* global WIKI */ |
||||
|
|
||||
|
module.exports = { |
||||
|
Query: { |
||||
|
async pages() { return {} } |
||||
|
}, |
||||
|
Mutation: { |
||||
|
async pages() { return {} } |
||||
|
}, |
||||
|
PageQuery: { |
||||
|
async list(obj, args, context, info) { |
||||
|
return WIKI.db.groups.query().select( |
||||
|
'groups.*', |
||||
|
WIKI.db.groups.relatedQuery('users').count().as('userCount') |
||||
|
) |
||||
|
}, |
||||
|
async single(obj, args, context, info) { |
||||
|
return WIKI.db.groups.query().findById(args.id) |
||||
|
} |
||||
|
}, |
||||
|
PageMutation: { |
||||
|
async create(obj, args) { |
||||
|
const group = await WIKI.db.pages.query().insertAndFetch({ |
||||
|
name: args.name |
||||
|
}) |
||||
|
return { |
||||
|
responseResult: graphHelper.generateSuccess('Group created successfully.'), |
||||
|
group |
||||
|
} |
||||
|
}, |
||||
|
async delete(obj, args) { |
||||
|
await WIKI.db.groups.query().deleteById(args.id) |
||||
|
return { |
||||
|
responseResult: graphHelper.generateSuccess('Group has been deleted.') |
||||
|
} |
||||
|
}, |
||||
|
async update(obj, args) { |
||||
|
await WIKI.db.groups.query().patch({ name: args.name }).where('id', args.id) |
||||
|
return { |
||||
|
responseResult: graphHelper.generateSuccess('Group has been updated.') |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
Page: { |
||||
|
// comments(pg) {
|
||||
|
// return pg.$relatedQuery('comments')
|
||||
|
// }
|
||||
|
} |
||||
|
} |
@ -0,0 +1,78 @@ |
|||||
|
# =============================================== |
||||
|
# PAGES |
||||
|
# =============================================== |
||||
|
|
||||
|
extend type Query { |
||||
|
pages: PageQuery |
||||
|
} |
||||
|
|
||||
|
extend type Mutation { |
||||
|
pages: PageMutation |
||||
|
} |
||||
|
|
||||
|
# ----------------------------------------------- |
||||
|
# QUERIES |
||||
|
# ----------------------------------------------- |
||||
|
|
||||
|
type PageQuery { |
||||
|
list( |
||||
|
filter: String |
||||
|
orderBy: String |
||||
|
): [PageMinimal] |
||||
|
|
||||
|
single( |
||||
|
id: Int! |
||||
|
): Page |
||||
|
} |
||||
|
|
||||
|
# ----------------------------------------------- |
||||
|
# MUTATIONS |
||||
|
# ----------------------------------------------- |
||||
|
|
||||
|
type PageMutation { |
||||
|
create( |
||||
|
description: String |
||||
|
isPublished: Boolean |
||||
|
locale: String |
||||
|
path: String! |
||||
|
publishEndDate: Date |
||||
|
publishStartDate: Date |
||||
|
tags: [String] |
||||
|
title: String! |
||||
|
): PageResponse |
||||
|
|
||||
|
update( |
||||
|
id: Int! |
||||
|
name: String! |
||||
|
): DefaultResponse |
||||
|
|
||||
|
delete( |
||||
|
id: Int! |
||||
|
): DefaultResponse |
||||
|
} |
||||
|
|
||||
|
# ----------------------------------------------- |
||||
|
# TYPES |
||||
|
# ----------------------------------------------- |
||||
|
|
||||
|
type PageResponse { |
||||
|
responseResult: ResponseStatus! |
||||
|
page: Page |
||||
|
} |
||||
|
|
||||
|
type PageMinimal { |
||||
|
id: Int! |
||||
|
name: String! |
||||
|
userCount: Int |
||||
|
createdAt: Date! |
||||
|
updatedAt: Date! |
||||
|
} |
||||
|
|
||||
|
type Page { |
||||
|
id: Int! |
||||
|
name: String! |
||||
|
rights: [Right] |
||||
|
users: [User] |
||||
|
createdAt: Date! |
||||
|
updatedAt: Date! |
||||
|
} |
@ -1,16 +0,0 @@ |
|||||
/** |
|
||||
* Associate DB Model relations |
|
||||
*/ |
|
||||
module.exports = db => { |
|
||||
db.User.belongsToMany(db.Group, { through: 'userGroups' }) |
|
||||
db.Group.belongsToMany(db.User, { through: 'userGroups' }) |
|
||||
db.Group.hasMany(db.Right) |
|
||||
db.Right.belongsTo(db.Group) |
|
||||
db.Document.belongsToMany(db.Tag, { through: 'documentTags' }) |
|
||||
db.Document.hasMany(db.Comment) |
|
||||
db.Tag.belongsToMany(db.Document, { through: 'documentTags' }) |
|
||||
db.File.belongsTo(db.Folder) |
|
||||
db.Folder.hasMany(db.File) |
|
||||
db.Comment.belongsTo(db.Document) |
|
||||
db.Comment.belongsTo(db.User, { as: 'author' }) |
|
||||
} |
|
@ -1,16 +0,0 @@ |
|||||
/** |
|
||||
* Comment schema |
|
||||
*/ |
|
||||
module.exports = (sequelize, DataTypes) => { |
|
||||
let commentSchema = sequelize.define('comment', { |
|
||||
content: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: false |
|
||||
} |
|
||||
}, { |
|
||||
timestamps: true, |
|
||||
version: true |
|
||||
}) |
|
||||
|
|
||||
return commentSchema |
|
||||
} |
|
@ -1,64 +0,0 @@ |
|||||
/** |
|
||||
* Document schema |
|
||||
*/ |
|
||||
module.exports = (sequelize, DataTypes) => { |
|
||||
let documentSchema = sequelize.define('setting', { |
|
||||
path: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: false |
|
||||
}, |
|
||||
title: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: false, |
|
||||
validate: { |
|
||||
len: [2, 255] |
|
||||
} |
|
||||
}, |
|
||||
subtitle: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: true, |
|
||||
defaultValue: '' |
|
||||
}, |
|
||||
parentPath: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: true, |
|
||||
defaultValue: '' |
|
||||
}, |
|
||||
parentTitle: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: true, |
|
||||
defaultValue: '' |
|
||||
}, |
|
||||
isDirectory: { |
|
||||
type: DataTypes.BOOLEAN, |
|
||||
allowNull: false, |
|
||||
defaultValue: false |
|
||||
}, |
|
||||
isEntry: { |
|
||||
type: DataTypes.BOOLEAN, |
|
||||
allowNull: false, |
|
||||
defaultValue: false |
|
||||
}, |
|
||||
isDraft: { |
|
||||
type: DataTypes.BOOLEAN, |
|
||||
allowNull: false, |
|
||||
defaultValue: false |
|
||||
}, |
|
||||
searchContent: { |
|
||||
type: DataTypes.TEXT, |
|
||||
allowNull: true, |
|
||||
defaultValue: '' |
|
||||
} |
|
||||
}, { |
|
||||
timestamps: true, |
|
||||
version: true, |
|
||||
indexes: [ |
|
||||
{ |
|
||||
unique: true, |
|
||||
fields: ['path'] |
|
||||
} |
|
||||
] |
|
||||
}) |
|
||||
|
|
||||
return documentSchema |
|
||||
} |
|
@ -1,42 +0,0 @@ |
|||||
/** |
|
||||
* File schema |
|
||||
*/ |
|
||||
module.exports = (sequelize, DataTypes) => { |
|
||||
let fileSchema = sequelize.define('file', { |
|
||||
category: { |
|
||||
type: DataTypes.ENUM('binary', 'image'), |
|
||||
allowNull: false, |
|
||||
defaultValue: 'binary' |
|
||||
}, |
|
||||
mime: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: false, |
|
||||
defaultValue: 'application/octet-stream' |
|
||||
}, |
|
||||
extra: { |
|
||||
type: DataTypes.JSON, |
|
||||
allowNull: true |
|
||||
}, |
|
||||
filename: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: false |
|
||||
}, |
|
||||
basename: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: false |
|
||||
}, |
|
||||
filesize: { |
|
||||
type: DataTypes.INTEGER, |
|
||||
allowNull: false, |
|
||||
validate: { |
|
||||
isInt: true, |
|
||||
min: 0 |
|
||||
} |
|
||||
} |
|
||||
}, { |
|
||||
timestamps: true, |
|
||||
version: true |
|
||||
}) |
|
||||
|
|
||||
return fileSchema |
|
||||
} |
|
@ -1,22 +0,0 @@ |
|||||
/** |
|
||||
* Folder schema |
|
||||
*/ |
|
||||
module.exports = (sequelize, DataTypes) => { |
|
||||
let folderSchema = sequelize.define('folder', { |
|
||||
name: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: false |
|
||||
} |
|
||||
}, { |
|
||||
timestamps: true, |
|
||||
version: true, |
|
||||
indexes: [ |
|
||||
{ |
|
||||
unique: true, |
|
||||
fields: ['name'] |
|
||||
} |
|
||||
] |
|
||||
}) |
|
||||
|
|
||||
return folderSchema |
|
||||
} |
|
@ -1,16 +0,0 @@ |
|||||
/** |
|
||||
* Group schema |
|
||||
*/ |
|
||||
module.exports = (sequelize, DataTypes) => { |
|
||||
let groupSchema = sequelize.define('group', { |
|
||||
name: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: false |
|
||||
} |
|
||||
}, { |
|
||||
timestamps: true, |
|
||||
version: true |
|
||||
}) |
|
||||
|
|
||||
return groupSchema |
|
||||
} |
|
@ -1,39 +0,0 @@ |
|||||
/** |
|
||||
* Locale schema |
|
||||
*/ |
|
||||
module.exports = (sequelize, DataTypes) => { |
|
||||
let localeSchema = sequelize.define('locale', { |
|
||||
code: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: false |
|
||||
}, |
|
||||
strings: { |
|
||||
type: DataTypes.JSON, |
|
||||
allowNull: true |
|
||||
}, |
|
||||
isRTL: { |
|
||||
type: DataTypes.BOOLEAN, |
|
||||
allowNull: false, |
|
||||
defaultValue: false |
|
||||
}, |
|
||||
name: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: false |
|
||||
}, |
|
||||
nativeName: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: false |
|
||||
} |
|
||||
}, { |
|
||||
timestamps: true, |
|
||||
version: true, |
|
||||
indexes: [ |
|
||||
{ |
|
||||
unique: true, |
|
||||
fields: ['code'] |
|
||||
} |
|
||||
] |
|
||||
}) |
|
||||
|
|
||||
return localeSchema |
|
||||
} |
|
@ -1,36 +0,0 @@ |
|||||
/** |
|
||||
* Right schema |
|
||||
*/ |
|
||||
module.exports = (sequelize, DataTypes) => { |
|
||||
let rightSchema = sequelize.define('right', { |
|
||||
path: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: false |
|
||||
}, |
|
||||
role: { |
|
||||
type: DataTypes.ENUM('read', 'write', 'manage'), |
|
||||
allowNull: false, |
|
||||
defaultValue: 'read' |
|
||||
}, |
|
||||
exact: { |
|
||||
type: DataTypes.BOOLEAN, |
|
||||
allowNull: false, |
|
||||
defaultValue: false |
|
||||
}, |
|
||||
allow: { |
|
||||
type: DataTypes.BOOLEAN, |
|
||||
allowNull: false, |
|
||||
defaultValue: false |
|
||||
} |
|
||||
}, { |
|
||||
timestamps: true, |
|
||||
version: true, |
|
||||
indexes: [ |
|
||||
{ |
|
||||
fields: ['path'] |
|
||||
} |
|
||||
] |
|
||||
}) |
|
||||
|
|
||||
return rightSchema |
|
||||
} |
|
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Settings schema |
|
||||
*/ |
|
||||
module.exports = (sequelize, DataTypes) => { |
|
||||
let settingSchema = sequelize.define('setting', { |
|
||||
key: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: false |
|
||||
}, |
|
||||
config: { |
|
||||
type: DataTypes.JSON, |
|
||||
allowNull: false |
|
||||
} |
|
||||
}, { |
|
||||
timestamps: true, |
|
||||
version: true, |
|
||||
indexes: [ |
|
||||
{ |
|
||||
unique: true, |
|
||||
fields: ['key'] |
|
||||
} |
|
||||
] |
|
||||
}) |
|
||||
|
|
||||
return settingSchema |
|
||||
} |
|
@ -1,22 +0,0 @@ |
|||||
/** |
|
||||
* Tags schema |
|
||||
*/ |
|
||||
module.exports = (sequelize, DataTypes) => { |
|
||||
let tagSchema = sequelize.define('tag', { |
|
||||
key: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: false |
|
||||
} |
|
||||
}, { |
|
||||
timestamps: true, |
|
||||
version: true, |
|
||||
indexes: [ |
|
||||
{ |
|
||||
unique: true, |
|
||||
fields: ['key'] |
|
||||
} |
|
||||
] |
|
||||
}) |
|
||||
|
|
||||
return tagSchema |
|
||||
} |
|
Write
Preview
Loading…
Cancel
Save