diff --git a/gulpfile.js b/gulpfile.js index 0383a1215..61231ed2d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -42,8 +42,8 @@ gulp.task('services', function() { 'auth', 'salix', 'client', - 'production', - 'route' + 'production' + // 'route' ]; for (var service of lbServices) diff --git a/services/client/common/models/address.js b/services/client/common/models/address.js index 569882208..2d6d38a2b 100644 --- a/services/client/common/models/address.js +++ b/services/client/common/models/address.js @@ -1,10 +1,10 @@ -module.exports = function(Address) { - Address.validate('default',isEnabled,{message: 'No se puede poner predeterminado un consignatario desactivado'}); +module.exports = function(Self) { + Self.validate('default',isEnabled,{message: 'No se puede poner predeterminado un consignatario desactivado'}); function isEnabled(err) { if (!this.isEnabled && this.isDefaultAddress) err(); } - Address.beforeRemote('create',function(ctx, modelInstance, next){ + Self.beforeRemote('create',function(ctx, modelInstance, next){ var data = ctx.req.body; create(data, next); }); @@ -17,13 +17,13 @@ module.exports = function(Address) { } } - Address.beforeRemote('prototype.patchAttributes',function(ctx, modelInstance, next){ + Self.beforeRemote('prototype.patchAttributes',function(ctx, modelInstance, next){ let newData = ctx.req.body; newData.id = ctx.req.params.id; getAddress(ctx, newData, next); }); - Address.beforeRemote('findById', function(ctx, modelInstance, next) { + Self.beforeRemote('findById', function(ctx, modelInstance, next) { ctx.args.filter = { "include": { "relation": "province", @@ -36,7 +36,7 @@ module.exports = function(Address) { }); function getAddress(ctx, newData, next){ - Address.findOne( {where: { id: newData.id}}, function (err, oldData){ + Self.findOne( {where: { id: newData.id}}, function (err, oldData){ if(oldData) callbackGetAddress(ctx, newData, oldData, next); }); @@ -60,7 +60,7 @@ module.exports = function(Address) { } function removeAllDefault(client, next){ - Address.updateAll({clientFk: client.id, isDefaultAddress: true}, {isDefaultAddress: false}, next); + Self.updateAll({clientFk: client.id, isDefaultAddress: true}, {isDefaultAddress: false}, next); } function generateErrorDefaultAddress(){ diff --git a/services/client/common/models/address.json b/services/client/common/models/address.json index ec9ee5805..42ac6d696 100644 --- a/services/client/common/models/address.json +++ b/services/client/common/models/address.json @@ -1,7 +1,6 @@ { "name": "Address", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "type": "Number", @@ -62,19 +61,5 @@ "model": "Agency", "foreignKey": "defaultAgencyFk" } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ] + } } diff --git a/services/client/common/models/agency-service.json b/services/client/common/models/agency-service.json index 4dc63171b..4f4da9a4b 100644 --- a/services/client/common/models/agency-service.json +++ b/services/client/common/models/agency-service.json @@ -1,7 +1,6 @@ { "name": "AgencyService", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "type": "Number", @@ -36,19 +35,5 @@ "model": "AgencyType", "foreignKey": "agencyTypeFk" } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ] + } } diff --git a/services/client/common/models/client-credit-limit.json b/services/client/common/models/client-credit-limit.json index a7982c2c7..eb5872c7b 100644 --- a/services/client/common/models/client-credit-limit.json +++ b/services/client/common/models/client-credit-limit.json @@ -1,7 +1,6 @@ { "name": "ClientCreditLimit", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "type": "Number", @@ -18,19 +17,5 @@ "model": "Role", "foreignKey": "roleFk" } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ] + } } \ No newline at end of file diff --git a/services/client/common/models/client-credit.json b/services/client/common/models/client-credit.json index a9cab0054..f6512bfc7 100644 --- a/services/client/common/models/client-credit.json +++ b/services/client/common/models/client-credit.json @@ -1,6 +1,6 @@ { "name": "ClientCredit", - "base": "MyModel", + "base": "VnModel", "validateUpsert": true, "properties": { "id": { @@ -26,19 +26,5 @@ "model": "Employee", "foreignKey": "employeeFk" } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ] + } } \ No newline at end of file diff --git a/services/client/common/models/client-observation.js b/services/client/common/models/client-observation.js index ba6315a3d..b9f9a4c04 100644 --- a/services/client/common/models/client-observation.js +++ b/services/client/common/models/client-observation.js @@ -1,19 +1,19 @@ -module.exports = function(ClientObservation) { +module.exports = function(Self) { let loopBackContext = require('loopback-context'); - ClientObservation.validate('text', isEnabled, {message: 'Se debe rellenar el campo de texto'}); + Self.validate('text', isEnabled, {message: 'Se debe rellenar el campo de texto'}); function isEnabled(err) { if (!this.text) err(); } - ClientObservation.observe('before save', function(ctx, next) { + Self.observe('before save', function(ctx, next) { ctx.instance.created = Date(); let currentUser = loopBackContext.getCurrentContext(); let userId = currentUser.get('currentUser'); let app = require('../../server/server'); - let employee = app.models.Employee; - employee.findOne({where: {userFk: userId}}, function (err, user){ + let Employee = app.models.Employee; + Employee.findOne({where: {userFk: userId}}, function (err, user){ if (user){ ctx.instance.employeeFk = user.id; next(); diff --git a/services/client/common/models/client-observation.json b/services/client/common/models/client-observation.json index 6046f5083..f209ee468 100644 --- a/services/client/common/models/client-observation.json +++ b/services/client/common/models/client-observation.json @@ -1,8 +1,7 @@ { "name": "ClientObservation", "description": "Notas de los clientes.", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "type": "Number", @@ -33,20 +32,6 @@ "foreignKey": "id" } }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ], "scope": { "include": "employee" } diff --git a/services/client/common/models/client.js b/services/client/common/models/client.js index 9236fdabb..19953fa24 100644 --- a/services/client/common/models/client.js +++ b/services/client/common/models/client.js @@ -1,66 +1,66 @@ var app = require('../../server/server'); -module.exports = function(Client) { +module.exports = function(Self) { var models = app.models; var loopBackContext = require('loopback-context'); // Methods - require('../methods/client/activate.js')(Client); - require('../methods/client/addresses.js')(Client); - require('../methods/client/before-save.js')(Client); - require('../methods/client/card.js')(Client); - require('../methods/client/create.js')(Client); - require('../methods/client/employee.js')(Client); - require('../methods/client/filter.js')(Client); - require('../methods/client/roles.js')(Client); - require('../methods/client/salesperson.js')(Client); - require('../methods/client/addressesPropagateRe.js')(Client); + require('../methods/client/activate.js')(Self); + require('../methods/client/addresses.js')(Self); + require('../methods/client/before-save.js')(Self); + require('../methods/client/card.js')(Self); + require('../methods/client/create.js')(Self); + require('../methods/client/employee.js')(Self); + require('../methods/client/filter.js')(Self); + require('../methods/client/roles.js')(Self); + require('../methods/client/salesperson.js')(Self); + require('../methods/client/addressesPropagateRe.js')(Self); // Validations - Client.validatesUniquenessOf('name', { + Self.validatesUniquenessOf('name', { message: 'El nombre debe ser único' }); - Client.validatesUniquenessOf('fi', { + Self.validatesUniquenessOf('fi', { message: 'El NIF/CIF debe ser único' }); - Client.validatesPresenceOf('socialName', { + Self.validatesPresenceOf('socialName', { message: 'Debe especificarse la razón social' }); - Client.validatesUniquenessOf('socialName', { + Self.validatesUniquenessOf('socialName', { message: 'La razón social debe ser única' }); - Client.validatesFormatOf('postcode', { + Self.validatesFormatOf('postcode', { message: 'El código postal solo debe contener números', allowNull: true, allowBlank: true, with: /^\d+$/ }); - Client.validatesFormatOf('email', { + Self.validatesFormatOf('email', { message: 'Correo electrónico inválido', allowNull: true, allowBlank: true, with: /^[\w|\.|\-]+@\w[\w|\.|\-]*\w(,[\w|\.|\-]+@\w[\w|\.|\-]*\w)*$/ }); - Client.validatesLengthOf('postcode', { + Self.validatesLengthOf('postcode', { allowNull: true, allowBlank: true, min: 3, max: 10 }); var validateIban = require('../validations/validateIban'); - Client.validateBinded('iban',validateIban,{ + Self.validateBinded('iban',validateIban,{ message:'El iban no tiene el formato correcto' }); - Client.validate('payMethod', hasSalesMan, { + Self.validate('payMethod', hasSalesMan, { message: 'No se puede cambiar la forma de pago si no hay comercial asignado' }); function hasSalesMan(err) { if(this.payMethod && !this.salesPerson) err(); } - Client.validateAsync('payMethodFk', hasIban, { + Self.validateAsync('payMethodFk', hasIban, { message: 'El método de pago seleccionado requiere que se especifique el IBAN' }); function hasIban(err, done) { @@ -71,7 +71,7 @@ module.exports = function(Client) { }); } - Client.validateAsync('credit', validateCredit, { + Self.validateAsync('credit', validateCredit, { message: 'No tienes privilegios para modificar el crédito' }); function validateCredit(err, done) { @@ -116,7 +116,7 @@ module.exports = function(Client) { // Si se puso a 0 por gerencia, solo gerencia puede aumentarlo function validate() { let query = 'SELECT * FROM ClientCredit WHERE clientFk = ? ORDER BY created DESC LIMIT 1'; - Client.dataSource.connector.execute (query, [self.id], + Self.dataSource.connector.execute (query, [self.id], (_, res) => maxCb(_, res)); } @@ -143,7 +143,7 @@ module.exports = function(Client) { AND cc.employeeFk = ${instances[0].employeeFk} AND r.\`name\` = 'manager'`; - Client.dataSource.connector.execute(sql, [], (_, res) => clientCreditCb(_, res)); + Self.dataSource.connector.execute(sql, [], (_, res) => clientCreditCb(_, res)); } function clientCreditCb(_, instance) { diff --git a/services/client/common/models/client.json b/services/client/common/models/client.json index f48a63ff2..ddb59bbd7 100644 --- a/services/client/common/models/client.json +++ b/services/client/common/models/client.json @@ -1,7 +1,6 @@ { "name": "Client", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "type": "Number", @@ -142,21 +141,5 @@ "model": "Address", "foreignKey": "clientFk" } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ], - "validations": [], - "methods": {} + } } \ No newline at end of file diff --git a/services/client/common/models/contact-channel.json b/services/client/common/models/contact-channel.json index 8b0469634..b60367074 100644 --- a/services/client/common/models/contact-channel.json +++ b/services/client/common/models/contact-channel.json @@ -1,7 +1,6 @@ { "name": "ContactChannel", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "type": "Number", @@ -12,19 +11,5 @@ "type": "string", "required": true } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ] + } } \ No newline at end of file diff --git a/services/client/common/models/credit-classification.json b/services/client/common/models/credit-classification.json index e972d5908..88f6b74df 100644 --- a/services/client/common/models/credit-classification.json +++ b/services/client/common/models/credit-classification.json @@ -1,8 +1,7 @@ { "name": "CreditClassification", "description": "Clientes clasificados.", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "id": true, @@ -22,19 +21,5 @@ "model": "Client", "foreignKey": "clientFk" } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ] + } } \ No newline at end of file diff --git a/services/client/common/models/pay-method.json b/services/client/common/models/pay-method.json index 4e16d2b93..ab63ef086 100644 --- a/services/client/common/models/pay-method.json +++ b/services/client/common/models/pay-method.json @@ -1,7 +1,6 @@ { "name": "PayMethod", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "type": "Number", @@ -21,19 +20,5 @@ "ibanRequired": { "type": "boolean" } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ] + } } diff --git a/services/mailer/package.json b/services/mailer/package.json index 6061d7b7c..bb4b3d8a6 100644 --- a/services/mailer/package.json +++ b/services/mailer/package.json @@ -11,5 +11,10 @@ "mysql": "^2.13.0", "nodemailer": "^4.0.1", "path": "^0.12.7" - } + }, + "repository": { + "type": "git", + "url": "https://git.verdnatura.es/salix" + }, + "license": "GPL-3.0" } diff --git a/services/production/common/methods/warehouse/list.js b/services/production/common/methods/warehouse/list.js deleted file mode 100644 index 1a3a98609..000000000 --- a/services/production/common/methods/warehouse/list.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = function(Warehouse) { - - var serverFilter = {"where": {"isManaged": {"neq": 0}}}; - - Warehouse.defineScope(serverFilter); - -} \ No newline at end of file diff --git a/services/production/common/models/agency.js b/services/production/common/models/agency.js index ac3aec84a..88ad478d5 100644 --- a/services/production/common/models/agency.js +++ b/services/production/common/models/agency.js @@ -1,5 +1,4 @@ -var app = require('../../server/server'); module.exports = function(Agency) { require('../methods/agency/list.js')(Agency); -}; \ No newline at end of file +}; diff --git a/services/production/common/models/agency.json b/services/production/common/models/agency.json index 69daf7b58..92d2aba60 100644 --- a/services/production/common/models/agency.json +++ b/services/production/common/models/agency.json @@ -1,7 +1,6 @@ { "name": "Agency", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "id": true, @@ -16,19 +15,5 @@ "type": "Number", "required": false } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ] + } } diff --git a/services/production/common/models/client.json b/services/production/common/models/client.json index cdbfa7e3d..c20e82e6c 100644 --- a/services/production/common/models/client.json +++ b/services/production/common/models/client.json @@ -1,7 +1,6 @@ { "name": "Client", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "type": "Number", @@ -12,21 +11,5 @@ "type": "string", "required": true } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ], - "validations": [], - "methods": {} + } } \ No newline at end of file diff --git a/services/production/common/models/employee.json b/services/production/common/models/employee.json deleted file mode 100644 index 2466c1922..000000000 --- a/services/production/common/models/employee.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "name": "Employee", - "base": "MyModel", - "validateUpsert": true, - "properties": { - "id": { - "type": "Number", - "id": true, - "description": "Identifier" - }, - "name":{ - "type": "String" - }, - "surname":{ - "type": "String" - } - }, - "relations": { - "user": { - "type": "belongsTo", - "model": "Account", - "foreignKey": "userFk" - } - }, - "acls": [], - "include":[ - { - "relation": "user", - "scope": { - "fields": ["name"] - } - } - ] -} \ No newline at end of file diff --git a/services/production/common/models/fake-production.js b/services/production/common/models/fake-production.js index 2649ce8df..4b94058fa 100644 --- a/services/production/common/models/fake-production.js +++ b/services/production/common/models/fake-production.js @@ -1,7 +1,6 @@ -var app = require('../../server/server'); -module.exports = function(FakeProduction) { - require('../methods/fake-production/list.js')(FakeProduction); - require('../methods/fake-production/message-send.js')(FakeProduction); - require('../methods/fake-production/route.js')(FakeProduction); -}; \ No newline at end of file +module.exports = function(Self) { + require('../methods/fake-production/list.js')(Self); + require('../methods/fake-production/message-send.js')(Self); + require('../methods/fake-production/route.js')(Self); +}; diff --git a/services/production/common/models/fake-production.json b/services/production/common/models/fake-production.json index d40746869..8d8c6c83a 100644 --- a/services/production/common/models/fake-production.json +++ b/services/production/common/models/fake-production.json @@ -1,7 +1,6 @@ { "name": "FakeProduction", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "type": "Number", @@ -74,19 +73,5 @@ "routeFk":{ "type": "Number" } - }, - "acls": [ - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ] + } } diff --git a/services/production/common/models/message-inbox.json b/services/production/common/models/message-inbox.json index 6cf1498ab..851e04af8 100644 --- a/services/production/common/models/message-inbox.json +++ b/services/production/common/models/message-inbox.json @@ -1,7 +1,6 @@ { "name": "MessageInbox", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "type": "Number", @@ -26,19 +25,5 @@ "sendDate":{ "type": "date" } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ] + } } diff --git a/services/production/common/models/message.json b/services/production/common/models/message.json index 4beacc4ca..249aa3795 100644 --- a/services/production/common/models/message.json +++ b/services/production/common/models/message.json @@ -1,7 +1,6 @@ { "name": "Message", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "type": "Number", @@ -23,19 +22,5 @@ "sendDate":{ "type": "date" } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ] + } } diff --git a/services/production/common/models/province.json b/services/production/common/models/province.json deleted file mode 100644 index b63edbb78..000000000 --- a/services/production/common/models/province.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "Province", - "base": "MyModel", - "validateUpsert": true, - "properties": { - "id": { - "type": "Number", - "id": true, - "description": "Identifier" - }, - "name": { - "type": "string", - "required": true - } - }, - "acls": [ - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - }, - { - "accessType": "WRITE", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - } - ] -} \ No newline at end of file diff --git a/services/production/common/models/route.json b/services/production/common/models/route.json index 2cf784483..ddc34ac07 100644 --- a/services/production/common/models/route.json +++ b/services/production/common/models/route.json @@ -1,7 +1,6 @@ { "name": "Route", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "type": "Number", @@ -12,20 +11,6 @@ "type": "date" } }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ], "validations": [], "methods": {} } \ No newline at end of file diff --git a/services/production/common/models/state.js b/services/production/common/models/state.js index 9e7db9ccb..dde01b36a 100644 --- a/services/production/common/models/state.js +++ b/services/production/common/models/state.js @@ -1,5 +1,4 @@ -var app = require('../../server/server'); -module.exports = function(State) { - require('../methods/state/list.js')(State); -}; \ No newline at end of file +module.exports = function(Self) { + require('../methods/state/list.js')(Self); +}; diff --git a/services/production/common/models/state.json b/services/production/common/models/state.json index 9dff62432..83de332b5 100644 --- a/services/production/common/models/state.json +++ b/services/production/common/models/state.json @@ -1,7 +1,6 @@ { "name": "State", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "id": true, @@ -24,19 +23,5 @@ "type": "String", "required": false } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ] + } } diff --git a/services/production/common/models/ticket-state.js b/services/production/common/models/ticket-state.js index 46b979506..4c320c203 100644 --- a/services/production/common/models/ticket-state.js +++ b/services/production/common/models/ticket-state.js @@ -1,5 +1,4 @@ -var app = require('../../server/server'); -module.exports = function(TicketState) { - require('../methods/ticket-state/change-state.js')(TicketState); +module.exports = function(Self) { + require('../methods/ticket-state/change-state.js')(Self); }; \ No newline at end of file diff --git a/services/production/common/models/ticket-state.json b/services/production/common/models/ticket-state.json index 8ece52942..2fb5270d8 100644 --- a/services/production/common/models/ticket-state.json +++ b/services/production/common/models/ticket-state.json @@ -1,7 +1,6 @@ { "name": "TicketState", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "id": true, @@ -29,19 +28,5 @@ "model": "Employee", "foreignKey": "employeeFk" } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ] + } } diff --git a/services/production/common/models/ticket.js b/services/production/common/models/ticket.js index d3ea5530b..f390c559f 100644 --- a/services/production/common/models/ticket.js +++ b/services/production/common/models/ticket.js @@ -1,6 +1,5 @@ -var app = require('../../server/server'); -module.exports = function(Ticket) { - require('../methods/ticket/change-time.js')(Ticket); - require('../methods/ticket/change-worker.js')(Ticket); +module.exports = function(Self) { + require('../methods/ticket/change-time.js')(Self); + require('../methods/ticket/change-worker.js')(Self); }; diff --git a/services/production/common/models/ticket.json b/services/production/common/models/ticket.json index ab4a152b0..c9c77d34d 100644 --- a/services/production/common/models/ticket.json +++ b/services/production/common/models/ticket.json @@ -1,7 +1,6 @@ { "name": "Ticket", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "id": true, @@ -11,19 +10,5 @@ "date": { "type": "date" } - }, - "acls": [{ - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ] - + } } \ No newline at end of file diff --git a/services/production/common/models/warehouse.js b/services/production/common/models/warehouse.js deleted file mode 100644 index 3ad0a9ccb..000000000 --- a/services/production/common/models/warehouse.js +++ /dev/null @@ -1,5 +0,0 @@ -var app = require('../../server/server'); - -module.exports = function(Warehouse) { - require('../methods/warehouse/list.js')(Warehouse); -}; \ No newline at end of file diff --git a/services/production/server/model-config.json b/services/production/server/model-config.json index 4f7b637a2..681354e38 100644 --- a/services/production/server/model-config.json +++ b/services/production/server/model-config.json @@ -59,7 +59,7 @@ "public": true }, "Employee":{ - "dataSource": "client", + "dataSource": "vn", "public": true }, "Client":{ @@ -67,7 +67,7 @@ "public": true }, "Province":{ - "dataSource": "client", + "dataSource": "vn", "public": true }, "Agency": { diff --git a/services/route/common/models/delivery.js b/services/route/common/models/delivery.js index 8639d24b5..04b9610cf 100644 --- a/services/route/common/models/delivery.js +++ b/services/route/common/models/delivery.js @@ -1,3 +1,4 @@ -module.exports = function(Delivery) { - require('../methods/filter.js')(Delivery); -}; \ No newline at end of file + +module.exports = function(Self) { + require('../methods/filter.js')(Self); +}; diff --git a/services/route/common/models/delivery.json b/services/route/common/models/delivery.json index 3dcd75835..36b83addb 100644 --- a/services/route/common/models/delivery.json +++ b/services/route/common/models/delivery.json @@ -1,7 +1,6 @@ { "name": "Delivery", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "id": true, @@ -17,21 +16,5 @@ "warehouseFk":{ "type": "Number" } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ], - "validations" : [], - "methods": {} + } } diff --git a/services/route/common/models/zone.json b/services/route/common/models/zone.json index a7a45bd27..cc23ebda4 100644 --- a/services/route/common/models/zone.json +++ b/services/route/common/models/zone.json @@ -1,7 +1,6 @@ { "name": "Zone", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "id": true, @@ -14,20 +13,6 @@ "printingOrder":{ "type": "Number" } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ] + } } \ No newline at end of file diff --git a/services/service/boot/root.js b/services/service/boot/root.js index 88e552bb7..b5fe6c878 100644 --- a/services/service/boot/root.js +++ b/services/service/boot/root.js @@ -1,5 +1,30 @@ module.exports = function(app) { + let models = app.models(); + models.forEach(function(model) { + let settings = model.settings; + let acls = settings.acls; + + if (!acls) + model.settings.acls = acls = []; + + acls.push({ + accessType: '*', + principalType: 'ROLE', + principalId: '$everyone', + permission: 'DENY' + }); + acls.push({ + accessType: '*', + principalType: 'ROLE', + principalId: 'root', + permission: 'ALLOW' + }); + + if (settings.validateUpsert === undefined) + settings.validateUpsert = true; + }); + app.enableAuth(); var router = app.loopback.Router(); diff --git a/services/service/methods/warehouse/list.js b/services/service/methods/warehouse/list.js new file mode 100644 index 000000000..591ea68f7 --- /dev/null +++ b/services/service/methods/warehouse/list.js @@ -0,0 +1,3 @@ +module.exports = function(Self) { + Self.defineScope({where: {isManaged: {neq: 0}}}); +}; diff --git a/services/service/models/account.json b/services/service/models/account.json index 7b3fd0739..13c6af2a9 100644 --- a/services/service/models/account.json +++ b/services/service/models/account.json @@ -28,19 +28,5 @@ "updated": { "type": "date" } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ] + } } diff --git a/services/client/common/models/country.json b/services/service/models/country.json similarity index 71% rename from services/client/common/models/country.json rename to services/service/models/country.json index 9814e4966..d464d007c 100644 --- a/services/client/common/models/country.json +++ b/services/service/models/country.json @@ -1,6 +1,6 @@ { "name": "Country", - "base": "MyModel", + "base": "VnModel", "validateUpsert": true, "properties": { "id": { @@ -37,18 +37,6 @@ "principalType": "ROLE", "principalId": "$everyone", "permission": "ALLOW" - }, - { - "accessType": "WRITE", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" } ] } \ No newline at end of file diff --git a/services/client/common/models/employee.json b/services/service/models/employee.json similarity index 55% rename from services/client/common/models/employee.json rename to services/service/models/employee.json index 80bf06ebb..c88f889ef 100644 --- a/services/client/common/models/employee.json +++ b/services/service/models/employee.json @@ -1,7 +1,6 @@ { "name": "Employee", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "type": "Number", @@ -23,19 +22,5 @@ "model": "Account", "foreignKey": "userFk" } - }, - "acls": [ - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" - } - ] + } } \ No newline at end of file diff --git a/services/client/common/models/province.json b/services/service/models/province.json similarity index 72% rename from services/client/common/models/province.json rename to services/service/models/province.json index b6dd16b2e..e19cc87e4 100644 --- a/services/client/common/models/province.json +++ b/services/service/models/province.json @@ -1,6 +1,6 @@ { "name": "Province", - "base": "MyModel", + "base": "VnModel", "validateUpsert": true, "properties": { "id": { @@ -36,18 +36,6 @@ "principalType": "ROLE", "principalId": "$everyone", "permission": "ALLOW" - }, - { - "accessType": "WRITE", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "DENY" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" } ] } \ No newline at end of file diff --git a/services/service/models/my-model.js b/services/service/models/vn-model.js similarity index 92% rename from services/service/models/my-model.js rename to services/service/models/vn-model.js index aa02ff156..740e41a36 100644 --- a/services/service/models/my-model.js +++ b/services/service/models/vn-model.js @@ -1,6 +1,6 @@ -module.exports = function(self) { - self.setup = function() { - self.super_.setup.call(this); +module.exports = function(Self) { + Self.setup = function() { + Self.super_.setup.call(this); let disableMethods = { create: true, @@ -25,7 +25,7 @@ module.exports = function(self) { } }; - self.defineScope = function(serverFilter) { + Self.defineScope = function(serverFilter) { this.remoteMethodCtx('list', { accepts: [ { @@ -78,7 +78,7 @@ module.exports = function(self) { }; }; - self.rawSql = function(query, params, cb) { + Self.rawSql = function(query, params, cb) { var connector = this.dataSource.connector; return new Promise(function(resolve, reject) { connector.execute(query, params, function(error, response) { @@ -92,7 +92,7 @@ module.exports = function(self) { }); }; - self.remoteMethodCtx = function(methodName, args) { + Self.remoteMethodCtx = function(methodName, args) { var ctx = { arg: 'context', type: 'object', @@ -108,21 +108,21 @@ module.exports = function(self) { this.remoteMethod(methodName, args); }; - self.connectToService = function(ctx, dataSource) { + Self.connectToService = function(ctx, dataSource) { this.app.dataSources[dataSource].connector.remotes.auth = { bearer: new Buffer(ctx.req.accessToken.id).toString('base64'), sendImmediately: true }; }; - self.disconnectFromService = function(dataSource) { + Self.disconnectFromService = function(dataSource) { this.app.dataSources[dataSource].connector.remotes.auth = { bearer: new Buffer("").toString('base64'), sendImmediately: true }; }; - self.installMethod = function(methodName, filterCb) { + Self.installMethod = function(methodName, filterCb) { this.remoteMethod(methodName, { description: 'List items using a filter', accessType: 'READ', @@ -180,7 +180,7 @@ module.exports = function(self) { }; }; - self.validateBinded = function(propertyName, validatorFn, options) { + Self.validateBinded = function(propertyName, validatorFn, options) { var customValidator = function(err) { if (!validatorFn(this[propertyName])) err(); }; diff --git a/services/service/models/my-model.json b/services/service/models/vn-model.json similarity index 59% rename from services/service/models/my-model.json rename to services/service/models/vn-model.json index 7a0a975bb..3474e6964 100644 --- a/services/service/models/my-model.json +++ b/services/service/models/vn-model.json @@ -1,4 +1,4 @@ { - "name": "MyModel", + "name": "VnModel", "base": "PersistedModel" } diff --git a/services/service/models/warehouse.js b/services/service/models/warehouse.js new file mode 100644 index 000000000..a4c8abc0a --- /dev/null +++ b/services/service/models/warehouse.js @@ -0,0 +1,4 @@ + +module.exports = function(Self) { + require('../methods/warehouse/list.js')(Self); +}; diff --git a/services/production/common/models/warehouse.json b/services/service/models/warehouse.json similarity index 74% rename from services/production/common/models/warehouse.json rename to services/service/models/warehouse.json index ce29fa124..806c07b40 100644 --- a/services/production/common/models/warehouse.json +++ b/services/service/models/warehouse.json @@ -1,7 +1,6 @@ { "name": "Warehouse", - "base": "MyModel", - "validateUpsert": true, + "base": "VnModel", "properties": { "id": { "id": true, @@ -24,12 +23,6 @@ "principalType": "ROLE", "principalId": "$everyone", "permission": "ALLOW" - }, - { - "accessType": "*", - "principalType": "ROLE", - "principalId": "root", - "permission": "ALLOW" } ], "scopes" : {