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
dd318eb2
Commit
dd318eb2
authored
May 28, 2018
by
NGPixel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: locale namespacing save + auth fetch fix
parent
416755f1
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
69 additions
and
51 deletions
+69
-51
admin-locale.vue
client/components/admin/admin-locale.vue
+12
-2
admin-locale-mutation-save.gql
client/graph/admin-locale-mutation-save.gql
+2
-2
admin-locale-query-list.gql
client/graph/admin-locale-query-list.gql
+2
-0
auth.js
server/core/auth.js
+1
-1
config.js
server/core/config.js
+6
-7
localization.js
server/core/localization.js
+2
-3
authentication.js
server/graph/resolvers/authentication.js
+10
-11
localization.js
server/graph/resolvers/localization.js
+9
-5
localization.graphql
server/graph/schemas/localization.graphql
+4
-0
sync-graph-locales.js
server/jobs/sync-graph-locales.js
+5
-5
setup.js
server/setup.js
+16
-15
No files found.
client/components/admin/admin-locale.vue
View file @
dd318eb2
...
...
@@ -64,7 +64,7 @@
:value='true'
icon='warning'
)
span The locale code will be prefixed to all paths. (e.g. /
en
/page-name)
span The locale code will be prefixed to all paths. (e.g. /
{{
selectedLocale
}}
/page-name)
.caption.grey--text Paths without a locale code will be automatically redirected to the base locale defined above.
v-divider
v-select(
...
...
@@ -181,7 +181,9 @@ export default {
mutation
:
localesSaveMutation
,
variables
:
{
locale
:
this
.
selectedLocale
,
autoUpdate
:
this
.
autoUpdate
autoUpdate
:
this
.
autoUpdate
,
namespacing
:
this
.
namespacing
,
namespaces
:
this
.
namespaces
}
})
const
resp
=
_
.
get
(
respRaw
,
'data.localization.updateLocale.responseResult'
,
{})
...
...
@@ -216,6 +218,14 @@ export default {
autoUpdate
:
{
query
:
localesQuery
,
update
:
(
data
)
=>
data
.
localization
.
config
.
autoUpdate
},
namespacing
:
{
query
:
localesQuery
,
update
:
(
data
)
=>
data
.
localization
.
config
.
namespacing
},
namespaces
:
{
query
:
localesQuery
,
update
:
(
data
)
=>
data
.
localization
.
config
.
namespaces
}
}
}
...
...
client/graph/admin-locale-mutation-save.gql
View file @
dd318eb2
mutation
(
$locale
:
String
!,
$autoUpdate
:
Boolean
!)
{
mutation
(
$locale
:
String
!,
$autoUpdate
:
Boolean
!
,
$namespacing
:
Boolean
!,
$namespaces
:
[
String
]!
)
{
localization
{
updateLocale
(
locale
:
$locale
,
autoUpdate
:
$autoUpdate
)
{
updateLocale
(
locale
:
$locale
,
autoUpdate
:
$autoUpdate
,
namespacing
:
$namespacing
,
namespaces
:
$namespaces
)
{
responseResult
{
succeeded
errorCode
...
...
client/graph/admin-locale-query-list.gql
View file @
dd318eb2
...
...
@@ -13,6 +13,8 @@
config
{
locale
autoUpdate
namespacing
namespaces
}
}
}
server/core/auth.js
View file @
dd318eb2
...
...
@@ -34,7 +34,7 @@ module.exports = {
async
activateStrategies
()
{
try
{
// Unload any active strategies
WIKI
.
auth
.
strategies
=
[]
WIKI
.
auth
.
strategies
=
{}
const
currentStrategies
=
_
.
keys
(
passport
.
_strategies
)
_
.
pull
(
currentStrategies
,
'session'
)
_
.
forEach
(
currentStrategies
,
stg
=>
{
passport
.
unuse
(
stg
)
})
...
...
server/core/config.js
View file @
dd318eb2
...
...
@@ -67,19 +67,18 @@ module.exports = {
* @returns Promise
*/
async
saveToDb
(
keys
)
{
let
trx
=
await
WIKI
.
db
.
Objection
.
transaction
.
start
(
WIKI
.
db
.
knex
)
try
{
for
(
let
key
of
keys
)
{
const
value
=
_
.
get
(
WIKI
.
config
,
key
,
null
)
let
affectedRows
=
await
WIKI
.
db
.
settings
.
query
(
trx
).
patch
({
value
}).
where
(
'key'
,
key
)
let
value
=
_
.
get
(
WIKI
.
config
,
key
,
null
)
if
(
!
_
.
isPlainObject
(
value
))
{
value
=
{
v
:
value
}
}
let
affectedRows
=
await
WIKI
.
db
.
settings
.
query
().
patch
({
value
}).
where
(
'key'
,
key
)
if
(
affectedRows
===
0
&&
value
)
{
await
WIKI
.
db
.
settings
.
query
(
trx
).
insert
({
key
,
value
})
await
WIKI
.
db
.
settings
.
query
().
insert
({
key
,
value
})
}
}
await
trx
.
commit
()
}
catch
(
err
)
{
await
trx
.
rollback
(
err
)
WIKI
.
logger
.
error
(
`Failed to save configuration to DB:
${
err
.
message
}
`
)
return
false
}
...
...
server/core/localization.js
View file @
dd318eb2
...
...
@@ -17,7 +17,7 @@ module.exports = {
ns
:
this
.
namespaces
,
defaultNS
:
'common'
,
saveMissing
:
false
,
lng
:
WIKI
.
config
.
lang
,
lng
:
WIKI
.
config
.
lang
.
code
,
fallbackLng
:
'en'
})
...
...
@@ -31,7 +31,7 @@ module.exports = {
}
// Load current language
this
.
loadLocale
(
WIKI
.
config
.
lang
,
{
silent
:
true
})
this
.
loadLocale
(
WIKI
.
config
.
lang
.
code
,
{
silent
:
true
})
return
this
},
...
...
@@ -55,7 +55,6 @@ module.exports = {
const
res
=
await
WIKI
.
db
.
locales
.
query
().
findOne
(
'code'
,
locale
)
if
(
res
)
{
if
(
_
.
isPlainObject
(
res
.
strings
))
{
console
.
info
(
res
.
strings
)
_
.
forOwn
(
res
.
strings
,
(
data
,
ns
)
=>
{
this
.
namespaces
.
push
(
ns
)
this
.
engine
.
addResourceBundle
(
locale
,
ns
,
data
,
true
,
true
)
...
...
server/graph/resolvers/authentication.js
View file @
dd318eb2
...
...
@@ -15,18 +15,17 @@ module.exports = {
async
authentication
()
{
return
{}
}
},
AuthenticationQuery
:
{
providers
(
obj
,
args
,
context
,
info
)
{
let
prv
=
_
.
map
(
WIKI
.
auth
.
strategies
,
str
=>
({
isEnabled
:
str
.
config
.
isEnabled
,
key
:
str
.
key
,
props
:
str
.
props
,
title
:
str
.
title
,
useForm
:
str
.
useForm
,
config
:
[]
async
providers
(
obj
,
args
,
context
,
info
)
{
let
strategies
=
await
WIKI
.
db
.
authentication
.
query
().
orderBy
(
'title'
)
strategies
=
strategies
.
map
(
stg
=>
({
...
stg
,
config
:
_
.
transform
(
stg
.
config
,
(
res
,
value
,
key
)
=>
{
res
.
push
({
key
,
value
})
},
[])
}))
if
(
args
.
filter
)
{
prv
=
graphHelper
.
filter
(
prv
,
args
.
filter
)
}
if
(
args
.
orderBy
)
{
prv
=
graphHelper
.
orderBy
(
prv
,
args
.
orderBy
)
}
return
prv
if
(
args
.
filter
)
{
strategies
=
graphHelper
.
filter
(
strategies
,
args
.
filter
)
}
if
(
args
.
orderBy
)
{
strategies
=
graphHelper
.
orderBy
(
strategies
,
args
.
orderBy
)
}
return
strategies
}
},
AuthenticationMutation
:
{
...
...
server/graph/resolvers/localization.js
View file @
dd318eb2
...
...
@@ -26,8 +26,10 @@ module.exports = {
},
async
config
(
obj
,
args
,
context
,
info
)
{
return
{
locale
:
WIKI
.
config
.
site
.
lang
,
autoUpdate
:
WIKI
.
config
.
site
.
langAutoUpdate
locale
:
WIKI
.
config
.
lang
.
code
,
autoUpdate
:
WIKI
.
config
.
lang
.
autoUpdate
,
namespacing
:
WIKI
.
config
.
lang
.
namespacing
,
namespaces
:
WIKI
.
config
.
lang
.
namespaces
}
}
},
...
...
@@ -49,9 +51,11 @@ module.exports = {
},
async
updateLocale
(
obj
,
args
,
context
)
{
try
{
WIKI
.
config
.
site
.
lang
=
args
.
locale
WIKI
.
config
.
site
.
langAutoUpdate
=
args
.
autoUpdate
await
WIKI
.
configSvc
.
saveToDb
([
'site'
])
WIKI
.
config
.
lang
.
code
=
args
.
locale
WIKI
.
config
.
lang
.
autoUpdate
=
args
.
autoUpdate
WIKI
.
config
.
lang
.
namespacing
=
args
.
namespacing
WIKI
.
config
.
lang
.
namespaces
=
args
.
namespaces
await
WIKI
.
configSvc
.
saveToDb
([
'lang'
])
await
WIKI
.
lang
.
setCurrentLocale
(
args
.
locale
)
...
...
server/graph/schemas/localization.graphql
View file @
dd318eb2
...
...
@@ -31,6 +31,8 @@ type LocalizationMutation {
updateLocale
(
locale
:
String
!
autoUpdate
:
Boolean
!
namespacing
:
Boolean
!
namespaces
:
[
String
]!
):
DefaultResponse
}
...
...
@@ -52,4 +54,6 @@ type LocalizationLocale {
type
LocalizationConfig
{
locale
:
String
!
autoUpdate
:
Boolean
!
namespacing
:
Boolean
!
namespaces
:
[
String
]!
}
server/jobs/sync-graph-locales.js
View file @
dd318eb2
...
...
@@ -34,11 +34,11 @@ module.exports = async (job) => {
})
const
locales
=
_
.
sortBy
(
_
.
get
(
respList
,
'data.localization.locales'
,
[]),
'name'
).
map
(
lc
=>
({...
lc
,
isInstalled
:
(
lc
.
code
===
'en'
)}))
WIKI
.
redis
.
set
(
'locales'
,
JSON
.
stringify
(
locales
))
const
currentLocale
=
_
.
find
(
locales
,
[
'code'
,
WIKI
.
config
.
site
.
lang
])
const
currentLocale
=
_
.
find
(
locales
,
[
'code'
,
WIKI
.
config
.
lang
.
code
])
// -> Download locale strings
if
(
WIKI
.
config
.
site
.
langAutoUpdate
)
{
if
(
WIKI
.
config
.
langAutoUpdate
)
{
const
respStrings
=
await
apollo
({
query
:
`query ($code: String!) {
localization {
...
...
@@ -49,7 +49,7 @@ module.exports = async (job) => {
}
}`
,
variables
:
{
code
:
WIKI
.
config
.
site
.
lang
code
:
WIKI
.
config
.
lang
.
code
}
})
const
strings
=
_
.
get
(
respStrings
,
'data.localization.strings'
,
[])
...
...
@@ -60,12 +60,12 @@ module.exports = async (job) => {
})
await
WIKI
.
db
.
locales
.
query
().
update
({
code
:
WIKI
.
config
.
site
.
lang
,
code
:
WIKI
.
config
.
lang
.
code
,
strings
:
lcObj
,
isRTL
:
currentLocale
.
isRTL
,
name
:
currentLocale
.
name
,
nativeName
:
currentLocale
.
nativeName
}).
where
(
'code'
,
WIKI
.
config
.
site
.
lang
)
}).
where
(
'code'
,
WIKI
.
config
.
lang
.
code
)
}
WIKI
.
logger
.
info
(
'Syncing locales with Graph endpoint: [ COMPLETED ]'
)
...
...
server/setup.js
View file @
dd318eb2
...
...
@@ -271,30 +271,31 @@ module.exports = () => {
await
fs
.
writeFileAsync
(
path
.
join
(
WIKI
.
ROOTPATH
,
'config.yml'
),
confRaw
)
// Set config
_
.
set
(
WIKI
.
config
,
'defaultEditor'
,
true
)
_
.
set
(
WIKI
.
config
,
'defaultEditor'
,
'markdown'
)
_
.
set
(
WIKI
.
config
,
'graphEndpoint'
,
'https://graph.requarks.io'
)
_
.
set
(
WIKI
.
config
,
'lang'
,
'en'
)
_
.
set
(
WIKI
.
config
,
'langAutoUpdate'
,
true
)
_
.
set
(
WIKI
.
config
,
'langRTL'
,
false
)
_
.
set
(
WIKI
.
config
,
'lang.code'
,
'en'
)
_
.
set
(
WIKI
.
config
,
'lang.autoUpdate'
,
true
)
_
.
set
(
WIKI
.
config
,
'lang.namespacing'
,
false
)
_
.
set
(
WIKI
.
config
,
'lang.namespaces'
,
[])
_
.
set
(
WIKI
.
config
,
'paths.content'
,
req
.
body
.
pathContent
)
_
.
set
(
WIKI
.
config
,
'paths.data'
,
req
.
body
.
pathData
)
_
.
set
(
WIKI
.
config
,
'port'
,
req
.
body
.
port
)
_
.
set
(
WIKI
.
config
,
'public'
,
req
.
body
.
public
===
'true'
)
_
.
set
(
WIKI
.
config
,
'sessionSecret'
,
(
await
crypto
.
randomBytesAsync
(
32
)).
toString
(
'hex'
))
_
.
set
(
WIKI
.
config
,
'telemetry'
,
req
.
body
.
telemetry
===
'true'
)
_
.
set
(
WIKI
.
config
,
'telemetry.isEnabled'
,
req
.
body
.
telemetry
===
'true'
)
_
.
set
(
WIKI
.
config
,
'telemetry.clientId'
,
WIKI
.
telemetry
.
cid
)
_
.
set
(
WIKI
.
config
,
'title'
,
req
.
body
.
title
)
// Save config to DB
WIKI
.
logger
.
info
(
'Persisting config to DB...'
)
await
WIKI
.
db
.
settings
.
query
().
insert
([
{
key
:
'defaultEditor'
,
value
:
{
v
:
WIKI
.
config
.
defaultEditor
}
},
{
key
:
'graphEndpoint'
,
value
:
{
v
:
WIKI
.
config
.
graphEndpoint
}
},
{
key
:
'lang'
,
value
:
{
v
:
WIKI
.
config
.
lang
}
},
{
key
:
'langAutoUpdate'
,
value
:
{
v
:
WIKI
.
config
.
langAutoUpdate
}
},
{
key
:
'langRTL'
,
value
:
{
v
:
WIKI
.
config
.
langRTL
}
},
{
key
:
'public'
,
value
:
{
v
:
WIKI
.
config
.
public
}
},
{
key
:
'sessionSecret'
,
value
:
{
v
:
WIKI
.
config
.
sessionSecret
}
},
{
key
:
'telemetry'
,
value
:
{
v
:
WIKI
.
config
.
telemetry
}
},
{
key
:
'title'
,
value
:
{
v
:
WIKI
.
config
.
title
}
}
await
WIKI
.
configSvc
.
saveToDb
([
'defaultEditor'
,
'graphEndpoint'
,
'lang'
,
'public'
,
'sessionSecret'
,
'telemetry'
,
'title'
])
// Create default locale
...
...
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