Commit ca5d07f3 authored by Bruno Meyer's avatar Bruno Meyer 😢

#22 Add ACL and Documentation for models Orgao, Curso, Setor, Departamento and Secretario

parent 9244bf12
......@@ -21,6 +21,9 @@ ds.automigrate(lbTables, function(err) {
});
var LOG_CREATE = false;
function criaBloco(cb){
// var blocos = [
// {localizacao: '0,0', tamanho: 10, nome: "bloco1", codigo:"codigo1"},
......@@ -30,7 +33,7 @@ function criaBloco(cb){
async.each(blocos, function(bloco, callback) {
app.models.Bloco.create(bloco, function(err, model) {
callback(err);
console.log('Created:', model);
if(LOG_CREATE) console.log('Created:', model);
});
}, function(err) {
if (err) throw err;
......@@ -52,7 +55,7 @@ function criaSala(cb){
async.each(salas, function(sala, callback) {
app.models.Sala.create(sala, function(err, model) {
callback(err);
console.log('Created:', model);
if(LOG_CREATE) console.log('Created:', model);
});
}, function(err) {
if (err) throw err;
......@@ -71,7 +74,7 @@ function criaRecursodesala(cb){
async.each(recursos, function(recurso, callback) {
app.models.Recursodesala.create(recurso, function(err, model) {
callback(err);
console.log('Created:', model);
if(LOG_CREATE) console.log('Created:', model);
});
}, function(err) {
if (err) throw err;
......@@ -87,7 +90,7 @@ function criaTipodesala(cb){
async.each(tipos, function(tipo, callback) {
app.models.Tipodesala.create(tipo, function(err, model) {
callback(err);
console.log('Created:', model);
if(LOG_CREATE) console.log('Created:', model);
});
}, function(err) {
if (err) throw err;
......@@ -97,23 +100,24 @@ function criaTipodesala(cb){
function criaUser(cb){
app.models.User.create([
app.models.Secretario.create([
{username: 'admin', email: 'admin@admin.com', password: '123mudar'},
{username: 'normal', email: 'normal@normal.com', password: '123mudar'}
{username: 'secretario1', email: 'secretario1@secretario.com', password: '123mudar'},
{username: 'secretario2', email: 'secretario2@secretario.com', password: '123mudar'}
],function(err, users) {
if (err) throw err;
console.log('Created users:', users);
if(LOG_CREATE) console.log('Created users:', users);
app.models.Role.create({
name: 'admin'
}, function(err, role) {
if (err) throw err;
console.log('Created role:', role);
if(LOG_CREATE) console.log('Created role:', role);
role.principals.create({
principalType: app.models.RoleMapping.USER,
principalId: users[0].id
}, function(err, principal) {
if (err) throw err;
console.log('Assign admin Role to initial User:', users[0].email);
if(LOG_CREATE) console.log('Assign admin Role to initial User:', users[0].email);
cb(err);
});
});
......@@ -124,7 +128,7 @@ function criaEquivalencia(cb){
app.models.Disciplina.find({id:1}, function(err, disc){
disc[0].addEquivalencia(2,function(err,data){
if (err) throw err;
console.log('Created Equivalenciadisciplina:', disc);
if(LOG_CREATE) console.log('Created Equivalenciadisciplina:', disc);
cb(err);
});
......@@ -142,7 +146,7 @@ function criaDisciplina(cb){
app.models.Disciplina.create(disciplina, function(err, model) {
if (err) throw err;
callback(err);
console.log('Created:', model);
if(LOG_CREATE) console.log('Created:', model);
});
}, function(err) {
if (err) throw err;
......
......@@ -81,9 +81,9 @@ class EnsalamentoTable {
this.get_table_from_db_parsed().then(data =>{
var json = JSON.stringify(data);
console.log("Saving ", this.loopback_name, "into", this.file_path);
console.log("Saving ", this.loopback_name, "into", this.file_path, "with ", data.length, "rows");
fs.writeFile(this.file_path, json, 'utf8', () => {
console.log("Saved ", this.loopback_name, "into", this.file_path);
console.log("Saved ", this.loopback_name, "into", this.file_path, "with ", data.length, "rows");
});
});
}
......
......@@ -24,7 +24,7 @@
// new_name: This is NECESSARILY a name of an model in the Loopback schema
var connectionString = 'postgresql://bhm15:pass@localhost:5432/ensalamento';
var connectionString = 'postgresql://login:password@localhost:5432/ensalamento';
var rooms = [
{
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -4,42 +4,48 @@
- Public: `False`
- Attributes `idInjection`=`false`
* nome : **string**
* codigo : **string** `Required` `primaryKey`
* codigo : **string** `Required`, `id`
* localizacao : **geopoint** `Required`
* andar : **number** default=`0`
* capacidade : **number** `Required`, default=`0`
* restrita : **boolean** `Required`, default=`false`
* observacao : **string**
* _id : **number** `generated` `primaryKey`
* _id : **number** `generated`
- ACLs
* All permissions not specified is `DENY`
* **$everyone** ROLE have all READ operations
* **admin** ROLE have all EXECUTE, READ and WRITE operations
* **owner** ROLE have all EXECUTE, READ and WRITE operations
- Relations
* Belongs to : **Bloco**
* Belongs to : **Bloco** as `blocoCod`
* Has and Belongs To Many : **Recursodesala** as `recursos`
* Belongs to : **Tipodesala** as `tipo`
* Belongs to : **Secretario** as `ownerId`
## Bloco
- Public: `True`
- Attributes `idInjection`=`false`
* nome : **string** `Required` `id`
* codigo : **string** `Required` `primaryKey`
* nome : **string** `Required`
* codigo : **string** `Required`, `id`
* localizacao : **geopoint** `Required`
* tamanho : **number** `Required`, default=`0`
* _id : **number** `generated` `primaryKey`
* _id : **number** `generated`
- ACLs
* All permissions not specified is `DENY`
* **$everyone** ROLE have all READ operations
* **admin** ROLE have all EXECUTE, READ and WRITE operations
- Relations
* Belongs To : **Setor** as `setorCod`
## Disciplina
- Public: `True`
- Attributes
* codigo : **string** `Required`
- Attributes `idInjection`=`false`
* codigo : **string** `Required`, `id`
* carga_horaria : **number** `Required`, default=`0`
* duracao : **string** `Required`, default=`semestral`
* modalidade : **string** `Required`, default=`presencial`
* _id : **number** `generated`
- ACLs
* All permissions not specified is `DENY`
* **$everyone** ROLE have all READ operations
......@@ -48,6 +54,8 @@
* This model have a self-realtion. To implement this, we use the EquivalenciaDisciplina model
* Has Many : **Turma** `Required (in Turma)` as `disciplinaId (in Turma)`
* Has and Belongs To Many : **Recursodesala** as `recursosnecessarios`
* Belongs To : **Tipodesala** as `tipodesalaId`
* Belongs To : **Departamento** as `departamentoCod`
## EquivalenciaDisciplina
......@@ -88,6 +96,7 @@
* **$everyone** ROLE have all READ operations
* **admin** ROLE have all EXECUTE, READ and WRITE operations
- Relations
* Belongs To : **Departamento** as `departamentoCod`
## Recursodesala
- Public: `False`
......@@ -113,8 +122,8 @@
In future, this can be use to allocate a room to disciplinas.
In this case, a disciplina must gain a room that meet this
room type need.
- Attributes
* nome : **string** `Required`
- Attributes `idInjection`=`false`
* nome : **string** `Required`, default=`'normal'`, `id`
- ACLs
* All permissions not specified is `DENY`
* **$everyone** ROLE have all READ operations
......@@ -123,4 +132,75 @@
- Observation: In future, its possible that will be necessary to find
rooms filtering by resources. Loopback gives a set of utilities
to solve many types of this problems, including filtering
relations: https://loopback.io/doc/en/lb3/Include-filter.html
\ No newline at end of file
relations: https://loopback.io/doc/en/lb3/Include-filter.html
## Orgao (server-side)
- Public: `False`
- Description: This will be extended by `Curso`, `Departamento` and `Setor`
- Attributes `idInjection`=`false`
* nome : **sting** `Required`
* localizacao : **geopoint**
* codigo : **string** `Required`, `id`
* _id : **number** `generated`
- ACLs
* All permissions not specified is `DENY`
* **$everyone** ROLE have all READ operations
* **admin** ROLE have all EXECUTE, READ and WRITE operations
- Relations
* Belongs To : **Secretario** as `secretarioId`
## Curso
- Public: `True`
- Description: This model extend `Orgao`
- Attributes
- ACLs
* All permissions not specified is `DENY`
* **$everyone** ROLE have all READ operations
* **admin** ROLE have all EXECUTE, READ and WRITE operations
- Relations
* Belongs To : **Bloco** as `blocoCod`
* Belongs To : **Setor** as `setorCod`
* Has and Belongs To Many : **Setor** as `Disciplina`
- Observation: The relation with Bloco means that one Curso will be relationed
with a Bloco.
## Departamento
- Public: `True`
- Description: This model extend `Orgao`
- Attributes
- ACLs
* All permissions not specified is `DENY`
* **admin** ROLE have all EXECUTE, READ and WRITE operations
- Relations
* Belongs To : **Setor** as `setorCod`
* Has Many : **Turma** as `departamentoCod`
## Setor
- Public: `True`
- Description: This model extend `Orgao`
- Attributes
* website : **string**
* email : **string** `Required`
- ACLs
* All permissions not specified is `DENY`
* **admin** ROLE have all EXECUTE, READ and WRITE operations
- Relations
* Has Many : **Departamento** as `setorCod`
* Has Many : **Bloco** as `setorCod`
* Has Many : **Curso** as `setorCod`
## Secretario
- Public: `True`
- Description: This model extend `User`
- Attributes
* vinculo : **string** `Required`, default=`'departamento'`
* descricao : **string**, default=`'change_password'`
* Used for restrict actions of user in some cases. For instance, when user
has he first login, he must change the password.
- ACLs
* All permissions not specified is `DENY`
* **admin** ROLE have all EXECUTE, READ and WRITE operations
- Relations
* Has Many : **Orgao** as `secretarioId`
* Has Many : **Sala** as `ownerId`
\ No newline at end of file
......@@ -21,22 +21,27 @@
},
"codigo": {
"type": "string",
"required": true,
"id":true
"id": true,
"required": true
},
"tamanho": {
"type": "number",
"required": true,
"default": 0
},
"_id":{
"type":"string",
"id":true,
"generated":true
"_id": {
"type": "number",
"generated": true
}
},
"validations": [],
"relations": {},
"relations": {
"setor": {
"type": "belongsTo",
"model": "Setor",
"foreignKey": "setorCod"
}
},
"acls": [
{
"principalType": "ROLE",
......
'use strict';
module.exports = function(Curso) {
};
{
"name": "Curso",
"plural": "cursos",
"base": "Orgao",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {
"bloco": {
"type": "belongsTo",
"model": "Bloco",
"foreignKey": "blocoCod"
},
"setor": {
"type": "belongsTo",
"model": "Setor",
"foreignKey": "setorCod"
},
"disciplinas": {
"type": "hasAndBelongsToMany",
"model": "Disciplina"
}
},
"acls": [
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY",
"property": "*"
},
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
},
{
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property": "*"
}
],
"methods": {}
}
'use strict';
module.exports = function(Departamento) {
};
{
"name": "Departamento",
"plural": "departamentos",
"base": "Orgao",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {
"setor": {
"type": "belongsTo",
"model": "Setor",
"foreignKey": "setorCod"
},
"turmas": {
"type": "hasMany",
"model": "Turma",
"foreignKey": "departamentoCod"
}
},
"acls": [
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY",
"property": "*"
},
{
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property": "*"
}
],
"methods": {}
}
......@@ -2,9 +2,11 @@
"name": "Disciplina",
"plural": "disciplinas",
"base": "PersistedModel",
"idInjection": false,
"properties": {
"codigo": {
"type": "String",
"id": true,
"required": true,
"length": 64,
"precision": null,
......@@ -32,6 +34,10 @@
"precision": null,
"scale": null,
"default": "presencial"
},
"_id": {
"type": "number",
"generated": true
}
},
"validations": [],
......@@ -51,6 +57,11 @@
"type": "belongsTo",
"model": "Tipodesala",
"foreignKey": "tipodesalaId"
},
"departamento": {
"type": "belongsTo",
"model": "Departamento",
"foreignKey": "departamentoCod"
}
},
"acls": [
......
......@@ -17,7 +17,13 @@ var models = [
'Recursodesala',
'SalaRecursodesala',
'DisciplinaRecursodesala',
'Tipodesala'
'Tipodesala',
'Orgao',
'Secretario',
'Setor',
'Departamento',
'Curso',
"CursoDisciplina"
];
/**
......
......@@ -5,7 +5,6 @@
"idInjection": false,
"options": {
"validateUpsert": true,
"idInjection": false,
"ensalemento": {
"schema": "strongloop",
"table": "sala"
......@@ -41,10 +40,9 @@
"observacao": {
"type": "string"
},
"_id":{
"type":"string",
"id":true,
"generated":true
"_id": {
"type": "number",
"generated": true
}
},
"validations": [],
......@@ -63,6 +61,11 @@
"type": "belongsTo",
"model": "Tipodesala",
"foreignKey": "tipo"
},
"secretario": {
"type": "belongsTo",
"model": "Secretario",
"foreignKey": "ownerId"
}
},
"acls": [
......@@ -83,6 +86,12 @@
"principalId": "admin",
"permission": "ALLOW",
"property": "*"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
}
],
"methods": {}
......
'use strict';
module.exports = function(Secretario) {
};
{
"name": "Secretario",
"plural": "secretarios",
"base": "User",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"vinculo": {
"type": "string",
"required": true,
"default": "departamento"
},
"restricao": {
"type": "string",
"default": "change_password"
}
},
"validations": [],
"relations": {
"orgaos": {
"type": "hasMany",
"model": "Orgao",
"foreignKey": "secretarioId"
},
"salas": {
"type": "hasMany",
"model": "Sala",
"foreignKey": "ownerId"
}
},
"acls": [
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY",
"property": "*"
},
{
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property": "*"
}
],
"methods": {}
}
'use strict';
module.exports = function(Setor) {
};
{
"name": "Setor",
"plural": "setores",
"base": "Orgao",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"website": {
"type": "string"
},
"email": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {
"departamentos": {
"type": "hasMany",
"model": "Departamento",
"foreignKey": "setorCod"
},
"blocos": {
"type": "hasMany",
"model": "Bloco",
"foreignKey": "setorCod"
},
"cursos": {
"type": "hasMany",
"model": "Curso",
"foreignKey": "setorCod"
}
},
"acls": [
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY",
"property": "*"
},
{
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property": "*"
}
],
"methods": {}
}
......@@ -8,9 +8,9 @@
"properties": {
"nome": {
"type": "string",
"id": true,
"required": true,
"default": "normal",
"id": true
"default": "normal"
}
},
"validations": [],
......
......@@ -21,7 +21,13 @@
}
},
"validations": [],
"relations": {},
"relations": {
"departamento": {
"type": "belongsTo",
"model": "Departamento",
"foreignKey": "departamentoCod"
}
},
"acls": [
{
"principalType": "ROLE",
......@@ -32,7 +38,7 @@
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$authenticated",
"principalId": "$everyone",
"permission": "ALLOW"
},
{
......
......@@ -14,7 +14,8 @@
]
},
"User": {
"dataSource": "ensalamento"
"dataSource": "ensalamento",
"public": false
},
"AccessToken": {
"dataSource": "ensalamento",
......@@ -66,5 +67,25 @@
"Tipodesala": {
"dataSource": "ensalamento",
"public": false
},
"Orgao": {
"dataSource": "ensalamento",
"public": false
},
"Secretario": {
"dataSource": "ensalamento",
"public": true
},
"Setor": {
"dataSource": "ensalamento",
"public": true
},
"Departamento": {
"dataSource": "ensalamento",
"public": true
},
"Curso": {
"dataSource": "ensalamento",
"public": true
}
}
'use strict';
module.exports = function(Orgao) {
};
{
"name": "Orgao",
"base": "PersistedModel",
"idInjection": false,
"options": {
"validateUpsert": true
},
"properties": {
"nome": {
"type": "string",
"required": true
},
"localizacao": {
"type": "geopoint"
},
"codigo": {
"type": "string",
"id": true,
"required": true
},
"_id": {
"type": "number",
"generated": true
}
},
"validations": [],
"relations": {
"secretario": {
"type": "belongsTo",