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
864a0701
Commit
864a0701
authored
Apr 29, 2017
by
NGPixel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: All Pages - Limit to user access rights
parent
8f3a6ed9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
15 deletions
+23
-15
ws.js
server/controllers/ws.js
+1
-1
entries.js
server/libs/entries.js
+17
-11
rights.js
server/libs/rights.js
+5
-3
No files found.
server/controllers/ws.js
View file @
864a0701
...
...
@@ -25,7 +25,7 @@ module.exports = (socket) => {
if
(
socket
.
request
.
user
.
logged_in
)
{
socket
.
on
(
'treeFetch'
,
(
data
,
cb
)
=>
{
cb
=
cb
||
_
.
noop
entries
.
getFromTree
(
data
.
basePath
).
then
((
f
)
=>
{
entries
.
getFromTree
(
data
.
basePath
,
socket
.
request
.
user
).
then
((
f
)
=>
{
return
cb
(
f
)
||
true
})
})
...
...
server/libs/entries.js
View file @
864a0701
...
...
@@ -300,10 +300,10 @@ module.exports = {
/**
* Create a new document
*
* @param
{String} entryPath
The entry path
* @param
{String} contents
The markdown-formatted contents
* @param
{String} entryPath
The entry path
* @param
{String} contents
The markdown-formatted contents
* @param {Object} author The author user object
* @return
{Promise<Boolean>}
True on success, false on failure
* @return
{Promise<Boolean>}
True on success, false on failure
*/
create
(
entryPath
,
contents
,
author
)
{
let
self
=
this
...
...
@@ -327,10 +327,10 @@ module.exports = {
/**
* Makes a document persistent to disk and git repository
*
* @param
{String} entryPath
The entry path
* @param
{String} contents
The markdown-formatted contents
* @param
{String} entryPath
The entry path
* @param
{String} contents
The markdown-formatted contents
* @param {Object} author The author user object
* @return
{Promise<Boolean>}
True on success, false on failure
* @return
{Promise<Boolean>}
True on success, false on failure
*/
makePersistent
(
entryPath
,
contents
,
author
)
{
let
fpath
=
entryHelper
.
getFullPath
(
entryPath
)
...
...
@@ -343,10 +343,10 @@ module.exports = {
/**
* Move a document
*
* @param
{String} entryPath
The current entry path
* @param
{String}
newEntryPath The new entry path
* @param
{String} entryPath
The current entry path
* @param
{String}
newEntryPath The new entry path
* @param {Object} author The author user object
* @return
{Promise}
Promise of the operation
* @return
{Promise}
Promise of the operation
*/
move
(
entryPath
,
newEntryPath
,
author
)
{
let
self
=
this
...
...
@@ -393,9 +393,15 @@ module.exports = {
* Get all entries from base path
*
* @param {String} basePath Path to list from
* @param {Object} usr Current user
* @return {Promise<Array>} List of entries
*/
getFromTree
(
basePath
)
{
return
db
.
Entry
.
find
({
parentPath
:
basePath
},
'title parentPath isDirectory isEntry'
).
sort
({
title
:
'asc'
})
getFromTree
(
basePath
,
usr
)
{
return
db
.
Entry
.
find
({
parentPath
:
basePath
},
'title parentPath isDirectory isEntry'
).
sort
({
title
:
'asc'
}).
then
(
results
=>
{
return
_
.
filter
(
results
,
r
=>
{
console
.
log
(
r
.
_id
,
rights
.
checkRole
(
r
.
_id
,
usr
.
rights
,
'read'
))
return
rights
.
checkRole
(
'/'
+
r
.
_id
,
usr
.
rights
,
'read'
)
})
})
}
}
server/libs/rights.js
View file @
864a0701
...
...
@@ -58,15 +58,15 @@ module.exports = {
let
rt
=
[]
let
p
=
_
.
chain
(
req
.
originalUrl
).
toLower
().
trim
().
value
()
// Load
User R
ights
// Load
user r
ights
if
(
_
.
isArray
(
req
.
user
.
rights
))
{
rt
=
req
.
user
.
rights
}
//
Is admin?
//
Check rights
if
(
_
.
find
(
rt
,
{
role
:
'admin'
}
))
{
if
(
self
.
checkRole
(
p
,
rt
,
'admin'
))
{
perm
.
read
=
true
perm
.
write
=
true
perm
.
manage
=
true
...
...
@@ -89,6 +89,8 @@ module.exports = {
* @return {boolean} True if authorized
*/
checkRole
(
p
,
rt
,
role
)
{
if
(
_
.
find
(
rt
,
{
role
:
'admin'
}))
{
return
true
}
// Check specific role on path
let
filteredRights
=
_
.
filter
(
rt
,
(
r
)
=>
{
...
...
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