Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
e85de927
Commit
e85de927
authored
Feb 29, 2020
by
NGPixel
Committed by
Nicolas Giard
Mar 01, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: restore page version
parent
e50dc895
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
125 additions
and
8 deletions
+125
-8
history.vue
client/components/history.vue
+73
-4
page.js
server/graph/resolvers/page.js
+37
-1
page.graphql
server/graph/schemas/page.graphql
+5
-0
error.js
server/helpers/error.js
+4
-0
pages.js
server/models/pages.js
+6
-3
No files found.
client/components/history.vue
View file @
e85de927
...
...
@@ -55,7 +55,7 @@
v-list-item(@click='download(ph.versionId)')
v-list-item-avatar(size='24'): v-icon mdi-cloud-download-outline
v-list-item-title Download Version
v-list-item(@click='restore(ph.versionId)', :disabled='ph.versionId === 0')
v-list-item(@click='restore(ph.versionId
, ph.versionDate
)', :disabled='ph.versionId === 0')
v-list-item-avatar(size='24'): v-icon(:disabled='ph.versionId === 0') mdi-history
v-list-item-title Restore
v-list-item(@click='branchOff(ph.versionId)')
...
...
@@ -111,6 +111,17 @@
.overline View Mode
v-card.mt-3(light, v-html='diffHTML', flat)
v-dialog(v-model='isRestoreConfirmDialogShown', max-width='650', persistent)
v-card
.dialog-header.is-orange
{{
$t
(
'history:restore.confirmTitle'
)
}}
v-card-text.pa-4
i18next(tag='span', path='history:restore.confirmText')
strong(place='date')
{{
restoreTarget
.
versionDate
|
moment
(
'LLL'
)
}}
v-card-actions
v-spacer
v-btn(text, @click='isRestoreConfirmDialogShown = false', :disabled='restoreLoading')
{{
$t
(
'common:actions.cancel'
)
}}
v-btn(color='orange darken-2', dark, @click='restoreConfirm', :loading='restoreLoading')
{{
$t
(
'history:restore.confirmButton'
)
}}
nav-footer
notify
search-results
...
...
@@ -124,6 +135,7 @@ import _ from 'lodash'
import
gql
from
'graphql-tag'
export
default
{
i18nOptions
:
{
namespaces
:
'history'
},
props
:
{
pageId
:
{
type
:
Number
,
...
...
@@ -194,7 +206,13 @@ export default {
offsetPage
:
0
,
total
:
0
,
viewMode
:
'line-by-line'
,
cache
:
[]
cache
:
[],
restoreTarget
:
{
versionId
:
0
,
versionDate
:
''
},
isRestoreConfirmDialogShown
:
false
,
restoreLoading
:
false
}
},
computed
:
{
...
...
@@ -335,8 +353,59 @@ export default {
download
(
versionId
)
{
window
.
location
.
assign
(
`/d/
${
this
.
locale
}
/
${
this
.
path
}
?v=
${
versionId
}
`
)
},
restore
(
versionId
)
{
restore
(
versionId
,
versionDate
)
{
this
.
restoreTarget
=
{
versionId
,
versionDate
}
this
.
isRestoreConfirmDialogShown
=
true
},
async
restoreConfirm
()
{
this
.
restoreLoading
=
true
this
.
$store
.
commit
(
`loadingStart`
,
'history-restore'
)
try
{
const
resp
=
await
this
.
$apollo
.
mutate
({
mutation
:
gql
`
mutation ($pageId: Int!, $versionId: Int!) {
pages {
restore (pageId: $pageId, versionId: $versionId) {
responseResult {
succeeded
errorCode
slug
message
}
}
}
}
`
,
variables
:
{
versionId
:
this
.
restoreTarget
.
versionId
,
pageId
:
this
.
pageId
}
})
if
(
_
.
get
(
resp
,
'data.pages.restore.responseResult.succeeded'
,
false
)
===
true
)
{
this
.
$store
.
commit
(
'showNotification'
,
{
style
:
'success'
,
message
:
this
.
$t
(
'history:restore.success'
),
icon
:
'check'
})
this
.
isRestoreConfirmDialogShown
=
false
setTimeout
(()
=>
{
window
.
location
.
assign
(
`/
${
this
.
locale
}
/
${
this
.
path
}
`
)
},
1000
)
}
else
{
throw
new
Error
(
_
.
get
(
resp
,
'data.pages.restore.responseResult.message'
,
'An unexpected error occured'
))
}
}
catch
(
err
)
{
this
.
$store
.
commit
(
'showNotification'
,
{
style
:
'red'
,
message
:
err
.
message
,
icon
:
'alert'
})
}
this
.
$store
.
commit
(
`loadingStop`
,
'history-restore'
)
this
.
restoreLoading
=
false
},
branchOff
(
versionId
)
{
...
...
server/graph/resolvers/page.js
View file @
e85de927
...
...
@@ -385,7 +385,7 @@ module.exports = {
try
{
const
page
=
await
WIKI
.
models
.
pages
.
query
().
findById
(
args
.
id
)
if
(
!
page
)
{
throw
new
Error
(
'Invalid Page Id'
)
throw
new
WIKI
.
Error
.
PageNotFound
(
)
}
await
WIKI
.
models
.
pages
.
renderPage
(
page
)
return
{
...
...
@@ -394,6 +394,42 @@ module.exports = {
}
catch
(
err
)
{
return
graphHelper
.
generateError
(
err
)
}
},
/**
* RESTORE PAGE VERSION
*/
async
restore
(
obj
,
args
,
context
)
{
try
{
const
page
=
await
WIKI
.
models
.
pages
.
query
().
select
(
'path'
,
'localeCode'
).
findById
(
args
.
pageId
)
if
(
!
page
)
{
throw
new
WIKI
.
Error
.
PageNotFound
()
}
if
(
!
WIKI
.
auth
.
checkAccess
(
context
.
req
.
user
,
[
'write:pages'
],
{
path
:
page
.
path
,
locale
:
page
.
localeCode
}))
{
throw
new
WIKI
.
Error
.
PageRestoreForbidden
()
}
const
targetVersion
=
await
WIKI
.
models
.
pageHistory
.
getVersion
({
pageId
:
args
.
pageId
,
versionId
:
args
.
versionId
})
if
(
!
targetVersion
)
{
throw
new
WIKI
.
Error
.
PageNotFound
()
}
await
WIKI
.
models
.
pages
.
updatePage
({
...
targetVersion
,
id
:
targetVersion
.
pageId
,
user
:
context
.
req
.
user
,
action
:
'restored'
})
return
{
responseResult
:
graphHelper
.
generateSuccess
(
'Page version restored successfully.'
)
}
}
catch
(
err
)
{
return
graphHelper
.
generateError
(
err
)
}
}
},
Page
:
{
...
...
server/graph/schemas/page.graphql
View file @
e85de927
...
...
@@ -129,6 +129,11 @@ type PageMutation {
render
(
id
:
Int
!
):
DefaultResponse
@
auth
(
requires
:
[
"
manage
:
system
"
])
restore
(
pageId
:
Int
!
versionId
:
Int
!
):
DefaultResponse
@
auth
(
requires
:
[
"
write
:
pages
"
,
"
manage
:
pages
"
,
"
manage
:
system
"
])
}
# -----------------------------------------------
...
...
server/helpers/error.js
View file @
e85de927
...
...
@@ -153,6 +153,10 @@ module.exports = {
message
:
'Destination page path already exists.'
,
code
:
6006
}),
PageRestoreForbidden
:
CustomError
(
'PageRestoreForbidden'
,
{
message
:
'You are not authorized to restore this page version.'
,
code
:
6011
}),
PageUpdateForbidden
:
CustomError
(
'PageUpdateForbidden'
,
{
message
:
'You are not authorized to update this page.'
,
code
:
6009
...
...
server/models/pages.js
View file @
e85de927
...
...
@@ -326,7 +326,8 @@ module.exports = class Page extends Model {
await
WIKI
.
models
.
pageHistory
.
addVersion
({
...
ogPage
,
isPublished
:
ogPage
.
isPublished
===
true
||
ogPage
.
isPublished
===
1
,
action
:
'updated'
action
:
opts
.
action
?
opts
.
action
:
'updated'
,
versionDate
:
ogPage
.
updatedAt
})
// -> Update page
...
...
@@ -422,7 +423,8 @@ module.exports = class Page extends Model {
// -> Create version snapshot
await
WIKI
.
models
.
pageHistory
.
addVersion
({
...
page
,
action
:
'moved'
action
:
'moved'
,
versionDate
:
page
.
updatedAt
})
const
destinationHash
=
pageHelper
.
generateHash
({
path
:
opts
.
destinationPath
,
locale
:
opts
.
destinationLocale
,
privateNS
:
opts
.
isPrivate
?
'TODO'
:
''
})
...
...
@@ -503,7 +505,8 @@ module.exports = class Page extends Model {
// -> Create version snapshot
await
WIKI
.
models
.
pageHistory
.
addVersion
({
...
page
,
action
:
'deleted'
action
:
'deleted'
,
versionDate
:
page
.
updatedAt
})
// -> Delete page
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment