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
df3d83fd
authored
Jan 06, 2018
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
issue
#440
fixed, to be tested
parent
12be7529
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
24 deletions
sails/src/CHANGES.md
sails/src/api/controllers/StudentController.js
sails/src/api/models/Student.js
sails/src/api/models/Supervisor.js
sails/src/CHANGES.md
View file @
df3d83fd
...
...
@@ -5,5 +5,5 @@
# Changes for new grid system
-
Lanzar desde MySQL el archivo roles/database/files/new-grid-system-adapt
2
.sql
-
Lanzar desde MySQL el archivo roles/database/files/new-grid-system-adapt.sql
-
Reactivar triggers
sails/src/api/controllers/StudentController.js
View file @
df3d83fd
...
...
@@ -61,15 +61,10 @@ module.exports = {
.
then
(
function
(
student
)
{
if
(
student
)
{
if
(
bcrypt
.
compareSync
(
req
.
body
.
password
,
student
.
password
))
{
student
.
isStudent
=
true
;
if
(
!
student
.
license
||
!
student
.
license
[
0
])
{
sails
.
log
.
error
(
'Tried to login with non valid license ${req.body.username}'
);
res
.
unauthorized
(
"Student has an invalid license"
);
}
else
{
var
hasExpired
=
student
.
license
[
0
].
hasExpired
();
student
=
student
.
toObject
();
// to enable overwrite license field
student
.
license
=
student
.
license
[
0
];
student
.
license
.
expired
=
hasExpired
;
return
res
.
ok
({
user
:
student
,
token
:
sailsTokenAuth
.
issueToken
(
student
,
sails
.
config
.
jwt
.
expiresInMinutes
),
...
...
@@ -143,10 +138,16 @@ module.exports = {
// Promisify asynchronous call to Student.supervisors
var
supervisors
=
new
Promise
(
function
(
resolve
,
reject
)
{
Student
.
validSupervisors
(
student
.
id
,
req
.
token
.
id
,
function
(
err
,
ss
)
{
if
(
err
)
return
reject
(
err
);
return
resolve
(
ss
);
});
if
(
req
.
token
.
isStudent
)
Student
.
allSupervisors
(
student
.
id
,
function
(
err
,
ss
)
{
if
(
err
)
return
reject
(
err
);
return
resolve
(
ss
);
});
else
Student
.
validSupervisors
(
student
.
id
,
req
.
token
.
id
,
function
(
err
,
ss
)
{
if
(
err
)
return
reject
(
err
);
return
resolve
(
ss
);
});
});
return
[
student
,
supervisors
];
...
...
sails/src/api/models/Student.js
View file @
df3d83fd
...
...
@@ -113,6 +113,7 @@ module.exports = {
if
(
student
.
license
&&
student
.
license
[
0
])
{
student
.
license
=
student
.
license
[
0
];
student
.
license
.
isValid
=
!
License
.
hasExpired
(
student
.
license
);
student
.
license
.
expired
=
!
student
.
license
.
isValid
;
student
.
license
.
isTrial
=
student
.
license
.
type
==
'trial'
;
student
.
license
.
isOfficial
=
student
.
license
.
type
==
'official'
;
}
else
student
.
license
=
null
;
...
...
@@ -121,15 +122,19 @@ module.exports = {
if
(
!
student
.
surname
||
student
.
surname
.
length
==
0
)
student
.
surname
=
sails
.
__
({
phrase
:
'no_surname'
,
locale
:
student
.
lang
});
student
.
attributes
=
Student
.
getValidAttributes
(
student
.
attributes
);
if
(
student
.
lastInstruction
&&
student
.
lastInstruction
[
0
]
&&
student
.
lastInstruction
[
0
].
met_name
)
{
student
.
current_method
=
student
.
lastInstruction
[
0
].
met_name
;
student
.
current_instruction
=
student
.
lastInstruction
[
0
].
ins_name
;
}
else
{
student
.
current_method
=
"no_method"
;
student
.
current_instruction
=
"no_instruction"
;
}
if
(
student
.
lastInstruction
&&
student
.
lastInstruction
[
0
]
&&
student
.
lastInstruction
[
0
].
met_name
)
{
student
.
current_method
=
student
.
lastInstruction
[
0
].
met_name
;
student
.
current_instruction
=
student
.
lastInstruction
[
0
].
ins_name
;
}
else
{
student
.
current_method
=
"no_method"
;
student
.
current_instruction
=
"no_instruction"
;
}
student
.
isTutor
=
false
;
student
.
isTherapist
=
false
;
student
.
isOffice
=
false
;
student
.
isAdmin
=
false
;
student
.
isStudent
=
true
;
delete
student
.
password
;
return
student
;
},
...
...
@@ -312,8 +317,10 @@ module.exports = {
},
//
// Class method for getting the list of supervisors associated to a given
// student and where the requester is related office
// Returns a callback(err, supervisors) where supervisors (when no errors)
// is the list of supervisors associated to a given student and they all
// belong to the same office
//
validSupervisors
:
function
(
id_stu
,
id_sup
,
callback
)
{
// Get all supervisors
...
...
@@ -327,14 +334,13 @@ module.exports = {
return
([
stuSups
,
SupOff
.
find
({
office
:
id_sup
}).
populate
(
'supervisor'
)]);
})
.
spread
((
stuSups
,
supOffs
)
=>
{
if
(
!
supOffs
||
supOffs
.
length
==
0
)
{
// if we get here, only the requester being directly related to the
// student is valid
var
supIdx
=
stuSups
.
findIndex
(
x
=>
x
.
supervisor
&&
x
.
supervisor
.
id
==
id_sup
);
if
(
supIdx
>=
0
)
return
([
stuSups
[
supIdx
].
supervisor
]);
// break "then" chain
throw
new
Error
(
"
No supervisors related
"
);
return
([
stuSups
[
supIdx
].
supervisor
]);
//
return only the supervisor herself and
break "then" chain
throw
new
Error
(
"
Your are not associated to the student
"
);
}
// else (continue then chain)
...
...
sails/src/api/models/Supervisor.js
View file @
df3d83fd
...
...
@@ -130,6 +130,7 @@ module.exports = {
supervisor
.
isTherapist
=
supervisor
.
role
==
'therapist'
;
supervisor
.
isOffice
=
supervisor
.
role
==
'office'
;
supervisor
.
isAdmin
=
supervisor
.
role
==
'admin'
;
supervisor
.
isStudent
=
false
;
if
(
!
supervisor
.
name
||
supervisor
.
name
.
length
==
0
)
supervisor
.
name
=
sails
.
__
({
phrase
:
'no_name'
,
locale
:
supervisor
.
lang
});
if
(
!
supervisor
.
surname
||
supervisor
.
surname
.
length
==
0
)
...
...
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