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
2e0f861f
Commit
2e0f861f
authored
Sep 29, 2019
by
Nick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: import users group creation logic
parent
82ba7d0a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
4 deletions
+103
-4
app.scss
client/themes/default/scss/app.scss
+17
-4
system.js
server/graph/resolvers/system.js
+86
-0
No files found.
client/themes/default/scss/app.scss
View file @
2e0f861f
/* THEME SPECIFIC STYLES */
.v-
application
.contents
{
.v-
content
.contents
{
color
:
mc
(
'grey'
,
'800'
);
padding
:
.5rem
0
50px
;
position
:
relative
;
...
...
@@ -464,7 +464,7 @@
display
:
none
;
}
@at-root
.
v-application.theme--dark
.contents
code
{
@at-root
.
theme--dark
&
{
background-color
:
darken
(
mc
(
'grey'
,
'900'
)
,
5%
);
color
:
mc
(
'indigo'
,
'100'
);
}
...
...
@@ -697,7 +697,8 @@
.v-navigation-drawer
,
.v-footer
,
.v-btn--fab
,
.page-col-sd
.page-col-sd
,
.v-tooltip__content
{
display
:
none
!
important
;
}
...
...
@@ -721,13 +722,25 @@
.v-content
{
padding
:
0
!
important
;
font-size
:
14px
;
background-color
:
#FFF
;
}
.v-application
.contents
{
.v-content
.contents
{
color
:
#000
;
background-color
:
#FFF
;
@at-root
.theme--dark
&
{
color
:
#000
;
}
.prismjs
{
box-shadow
:
none
;
background-color
:
#FFF
;
@at-root
.theme--dark
&
{
background-color
:
#FFF
;
}
>
code
{
color
:
#000
;
box-shadow
:
none
;
...
...
server/graph/resolvers/system.js
View file @
2e0f861f
...
...
@@ -8,6 +8,8 @@ const fs = require('fs-extra')
const
moment
=
require
(
'moment'
)
const
graphHelper
=
require
(
'../../helpers/graph'
)
const
request
=
require
(
'request-promise'
)
const
crypto
=
require
(
'crypto'
)
const
nanoid
=
require
(
'nanoid/non-secure/generate'
)
/* global WIKI */
...
...
@@ -85,28 +87,106 @@ module.exports = {
return
graphHelper
.
generateError
(
err
)
}
},
/**
* Import Users from a v1 installation
*/
async
importUsersFromV1
(
obj
,
args
,
context
)
{
try
{
const
MongoClient
=
require
(
'mongodb'
).
MongoClient
if
(
args
.
mongoDbConnString
&&
args
.
mongoDbConnString
.
length
>
10
)
{
// -> Connect to DB
const
client
=
await
MongoClient
.
connect
(
args
.
mongoDbConnString
,
{
appname
:
`Wiki.js
${
WIKI
.
version
}
Migration Tool`
})
const
dbUsers
=
client
.
db
().
collection
(
'users'
)
const
userCursor
=
dbUsers
.
find
({
email
:
{
'$ne'
:
'guest'
}
})
const
curDateISO
=
new
Date
().
toISOString
()
let
failed
=
[]
let
usersCount
=
0
let
groupsCount
=
0
let
assignableGroups
=
[]
let
reuseGroups
=
[]
// -> Create SINGLE group
if
(
args
.
groupMode
===
`SINGLE`
)
{
const
singleGroup
=
await
WIKI
.
models
.
groups
.
query
().
insert
({
name
:
`Import_
${
curDateISO
}
`
,
permissions
:
JSON
.
stringify
(
WIKI
.
data
.
groups
.
defaultPermissions
),
pageRules
:
JSON
.
stringify
(
WIKI
.
data
.
groups
.
defaultPageRules
)
})
groupsCount
++
assignableGroups
.
push
(
singleGroup
.
id
)
}
// -> Iterate all users
while
(
await
userCursor
.
hasNext
())
{
const
usr
=
await
userCursor
.
next
()
let
usrGroup
=
[]
if
(
args
.
groupMode
===
`MULTI`
)
{
// -> Check if global admin
if
(
_
.
some
(
usr
.
rights
,
[
'role'
,
'admin'
]))
{
usrGroup
.
push
(
1
)
}
else
{
// -> Check if identical group already exists
const
currentRights
=
_
.
sortBy
(
_
.
map
(
usr
.
rights
,
r
=>
_
.
pick
(
r
,
[
'role'
,
'path'
,
'exact'
,
'deny'
])),
[
'role'
,
'path'
,
'exact'
,
'deny'
])
const
ruleSetId
=
crypto
.
createHash
(
'sha1'
).
update
(
JSON
.
stringify
(
currentRights
)).
digest
(
'base64'
)
const
existingGroup
=
_
.
find
(
reuseGroups
,
[
'hash'
,
ruleSetId
])
if
(
existingGroup
)
{
usrGroup
.
push
(
existingGroup
.
groupId
)
}
else
{
// -> Build new group
const
pageRules
=
_
.
map
(
usr
.
rights
,
r
=>
{
let
roles
=
[
'read:pages'
,
'read:assets'
,
'read:comments'
,
'write:comments'
]
if
(
r
.
role
===
`write`
)
{
roles
=
_
.
concat
(
roles
,
[
'write:pages'
,
'manage:pages'
,
'read:source'
,
'read:history'
,
'write:assets'
,
'manage:assets'
])
}
return
{
id
:
nanoid
(
'1234567890abcdef'
,
10
),
roles
:
roles
,
match
:
r
.
exact
?
'EXACT'
:
'START'
,
deny
:
r
.
deny
,
path
:
(
r
.
path
.
indexOf
(
'/'
)
===
0
)
?
r
.
path
.
substring
(
1
)
:
r
.
path
,
locales
:
[]
}
})
const
perms
=
_
.
chain
(
pageRules
).
reject
(
'deny'
).
map
(
'roles'
).
union
().
flatten
().
value
()
// -> Create new group
const
newGroup
=
await
WIKI
.
models
.
groups
.
query
().
insert
({
name
:
`Import_
${
curDateISO
}
_
${
groupsCount
+
1
}
`
,
permissions
:
JSON
.
stringify
(
perms
),
pageRules
:
JSON
.
stringify
(
pageRules
)
})
reuseGroups
.
push
({
groupId
:
newGroup
.
id
,
hash
:
ruleSetId
})
groupsCount
++
usrGroup
.
push
(
newGroup
.
id
)
}
}
}
// -> Create User
try
{
await
WIKI
.
models
.
users
.
createNewUser
({
providerKey
:
usr
.
provider
,
email
:
usr
.
email
,
name
:
usr
.
name
,
passwordRaw
:
usr
.
password
,
groups
:
(
usrGroup
.
length
>
0
)
?
usrGroup
:
assignableGroups
,
mustChangePassword
:
false
,
sendWelcomeEmail
:
false
})
...
...
@@ -121,6 +201,12 @@ module.exports = {
}
}
// -> Reload group permissions
if
(
args
.
groupMode
!==
`NONE`
)
{
await
WIKI
.
auth
.
reloadGroups
()
}
client
.
close
()
return
{
responseResult
:
graphHelper
.
generateSuccess
(
'Import completed.'
),
...
...
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