Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
yotta
/
pictogram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
60
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
684534be
authored
Feb 23, 2017
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
issue #949 fixed (adding missing policy file)
parent
7f807c1d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
sails/src/api/policies/isSupervisorOfStudentOrIsSupAdminOrIsStudent.js
sails/src/api/policies/isSupervisorOfStudentOrIsSupAdminOrIsStudent.js
0 → 100644
View file @
684534be
module
.
exports
=
function
isSupervisorOfStudentOrIsSupAdminOrIsStudent
(
req
,
res
,
next
)
{
// sails.log("TOKEN: " + JSON.stringify(req.token));
if
(
!
req
.
params
.
id_stu
)
return
res
.
json
(
401
,
{
error
:
'Access denied 1'
});
// If it is a student, then is ok
Student
.
findOne
(
req
.
params
.
id_stu
)
.
then
(
function
(
s
)
{
if
(
req
.
token
&&
req
.
token
.
isStudent
&&
req
.
token
.
id
==
req
.
params
.
id_stu
)
return
next
();
// Is Student
if
(
req
.
token
.
office
&&
s
.
office
==
req
.
token
.
office
.
id
&&
req
.
token
.
isSupAdmin
)
return
next
();
// Is Office's administrator
s
.
supervisors
((
err
,
sups
)
=>
{
if
(
err
||
!
sups
||
sups
.
length
==
0
)
return
res
.
json
(
401
,
{
error
:
"This student has no supervisors associated"
});
if
(
sups
.
map
(
function
(
e
)
{
return
e
.
id
}).
indexOf
(
req
.
token
.
id
)
>=
0
)
return
next
();
// Is Supervisor of Student
return
res
.
json
(
401
,
{
error
:
"No valid credentials"
});
});
})
.
catch
((
err
)
=>
{
return
res
.
json
(
401
,
{
error
:
"Student not found"
});
});
};
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