Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
VILLASweb-backend-node
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ACS
Public
VILLASframework
VILLASweb-backend-node
Commits
1b86d9b0
Commit
1b86d9b0
authored
8 years ago
by
Markus Grigull
Browse files
Options
Downloads
Patches
Plain Diff
Add user change own data when not an admin
parent
892dd2f8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+4
-1
4 additions, 1 deletion
README.md
routes/users.js
+19
-4
19 additions, 4 deletions
routes/users.js
with
23 additions
and
5 deletions
README.md
+
4
−
1
View file @
1b86d9b0
...
...
@@ -4,7 +4,10 @@
This is the backend for the VILLASweb frontend. It is build upon NodeJS, Express and MongoDB.
## To-Do
-
Don't send user password
-
Don't send user password
(select: false)
-
Only get projects which are accessible by the user
-
Add support for config.js with docker volumes
-
Add support for key-secret for bcrypt
-
Let user change own properties if not admin
-
Model IDs readonly
-
Handle relations server side
This diff is collapsed.
Click to expand it.
routes/users.js
+
19
−
4
View file @
1b86d9b0
...
...
@@ -24,7 +24,7 @@ router.route('/users').get(auth.validateAdminLevel(1), function(req, res) {
});
});
router
.
route
(
'
/users
'
).
post
(
function
(
req
,
res
)
{
router
.
route
(
'
/users
'
).
post
(
auth
.
validateAdminLevel
(
1
),
function
(
req
,
res
)
{
// create new user
var
user
=
new
User
(
req
.
body
);
...
...
@@ -37,16 +37,31 @@ router.route('/users').post(function(req, res) {
});
});
router
.
route
(
'
/users/:id
'
).
put
(
auth
.
validateAdminLevel
(
1
),
function
(
req
,
res
)
{
router
.
route
(
'
/users/:id
'
).
put
(
function
(
req
,
res
)
{
// get user
User
.
findOne
({
_id
:
req
.
params
.
id
},
function
(
err
,
user
)
{
if
(
err
)
{
return
res
.
send
(
err
);
}
// if user is not an admin, only allow some changes on own data
// update all properties
for
(
property
in
req
.
body
.
user
)
{
user
[
property
]
=
req
.
body
.
user
[
property
];
if
(
user
.
adminLevel
>=
1
)
{
for
(
property
in
req
.
body
.
user
)
{
user
[
property
]
=
req
.
body
.
user
[
property
];
}
}
else
if
(
req
.
decoded
.
_doc
.
_id
===
req
.
params
.
id
)
{
// only copy the allowed properties since the user is not an admin
for
(
property
in
req
.
body
.
user
)
{
if
(
property
===
'
_id
'
||
property
===
'
adminLevel
'
)
{
continue
;
}
user
[
property
]
=
req
.
body
.
user
[
property
];
}
}
else
{
return
res
.
send
({
success
:
false
,
message
:
'
Invalid authorization
'
});
}
// save the changes
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment