Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"ignoreComments": true,
"ignoreUrls": true,
"ignorePattern": "^\\s*var\\s.+=\\s*(require\\s*\\()|(/)"
}]
}],
"no-unused-expressions": "off",
}
}
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// License text available at https://opensource.org/licenses/MIT

/*global module:false*/
'use strict';
module.exports = function(grunt) {
// Do not report warnings from unit-tests exercising deprecated paths
process.env.NO_DEPRECATION = 'loopback';
Expand Down Expand Up @@ -201,7 +202,7 @@ module.exports = function(grunt) {
},

// Add browserify to preprocessors
preprocessors: { 'test/e2e/*': ['browserify'] },
preprocessors: {'test/e2e/*': ['browserify']},
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion common/models/access-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Module Dependencies.
*/

'use strict';
var g = require('../../lib/globalize');
var loopback = require('../../lib/loopback');
var assert = require('assert');
Expand Down Expand Up @@ -47,7 +48,7 @@ module.exports = function(AccessToken) {
* ```
*/

AccessToken.ANONYMOUS = new AccessToken({ id: '$anonymous' });
AccessToken.ANONYMOUS = new AccessToken({id: '$anonymous'});

/**
* Create a cryptographically random access token id.
Expand Down
32 changes: 13 additions & 19 deletions common/models/acl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

'use strict';
/*!
Schema ACL options

Object level permissions, for example, an album owned by a user

Factors to be authorized against:

* model name: Album
* model instance properties: userId of the album, friends, shared
* methods
Expand All @@ -21,19 +19,15 @@
** none
** everyone
** relations: owner/friend/granted

Class level permissions, for example, Album
* model name: Album
* methods

URL/Route level permissions
* url pattern
* application id
* ip addresses
* http headers

Map to oAuth 2.0 scopes

*/

var g = require('../../lib/globalize');
Expand Down Expand Up @@ -331,10 +325,10 @@ module.exports = function(ACL) {
principalId = principalId.toString();
}
property = property || ACL.ALL;
var propertyQuery = (property === ACL.ALL) ? undefined : { inq: [property, ACL.ALL] };
var propertyQuery = (property === ACL.ALL) ? undefined : {inq: [property, ACL.ALL]};
accessType = accessType || ACL.ALL;
var accessTypeQuery = (accessType === ACL.ALL) ? undefined :
{ inq: [accessType, ACL.ALL, ACL.EXECUTE] };
{inq: [accessType, ACL.ALL, ACL.EXECUTE]};

var req = new AccessRequest(model, property, accessType);

Expand All @@ -352,8 +346,8 @@ module.exports = function(ACL) {
}

var self = this;
this.find({ where: { principalType: principalType, principalId: principalId,
model: model, property: propertyQuery, accessType: accessTypeQuery }},
this.find({where: {principalType: principalType, principalId: principalId,
model: model, property: propertyQuery, accessType: accessTypeQuery}},
function(err, dynACLs) {
if (err) {
if (callback) callback(err);
Expand Down Expand Up @@ -408,21 +402,21 @@ module.exports = function(ACL) {
var modelName = context.modelName;

var methodNames = context.methodNames;
var propertyQuery = (property === ACL.ALL) ? undefined : { inq: methodNames.concat([ACL.ALL]) };
var propertyQuery = (property === ACL.ALL) ? undefined : {inq: methodNames.concat([ACL.ALL])};

var accessTypeQuery = (accessType === ACL.ALL) ?
undefined :
(accessType === ACL.REPLICATE) ?
{ inq: [ACL.REPLICATE, ACL.WRITE, ACL.ALL] } :
{ inq: [accessType, ACL.ALL] };
{inq: [ACL.REPLICATE, ACL.WRITE, ACL.ALL]} :
{inq: [accessType, ACL.ALL]};

var req = new AccessRequest(modelName, property, accessType, ACL.DEFAULT, methodNames);

var effectiveACLs = [];
var staticACLs = self.getStaticACLs(model.modelName, property);

this.find({ where: { model: model.modelName, property: propertyQuery,
accessType: accessTypeQuery }}, function(err, acls) {
this.find({where: {model: model.modelName, property: propertyQuery,
accessType: accessTypeQuery}}, function(err, acls) {
if (err) {
if (callback) callback(err);
return;
Expand Down Expand Up @@ -525,15 +519,15 @@ module.exports = function(ACL) {
this.resolveRelatedModels();
switch (type) {
case ACL.ROLE:
this.roleModel.findOne({ where: { or: [{ name: id }, { id: id }] }}, cb);
this.roleModel.findOne({where: {or: [{name: id}, {id: id}]}}, cb);
break;
case ACL.USER:
this.userModel.findOne(
{ where: { or: [{ username: id }, { email: id }, { id: id }] }}, cb);
{where: {or: [{username: id}, {email: id}, {id: id}]}}, cb);
break;
case ACL.APP:
this.applicationModel.findOne(
{ where: { or: [{ name: id }, { email: id }, { id: id }] }}, cb);
{where: {or: [{name: id}, {email: id}, {id: id}]}}, cb);
break;
default:
process.nextTick(function() {
Expand Down
15 changes: 2 additions & 13 deletions common/models/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

'use strict';
var assert = require('assert');
var utils = require('../../lib/utils');

Expand Down Expand Up @@ -70,18 +71,6 @@ function generateKey(hmacKey, algorithm, encoding) {
*/

module.exports = function(Application) {
// Workaround for https://github.com/strongloop/loopback/issues/292
Application.definition.rawProperties.created.default =
Application.definition.properties.created.default = function() {
return new Date();
};

// Workaround for https://github.com/strongloop/loopback/issues/292
Application.definition.rawProperties.modified.default =
Application.definition.properties.modified.default = function() {
return new Date();
};

/*!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks suspicious to me, could you please explain which eslint rule is violated by this line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was giving this error:

>> Mocha exploded!
>> TypeError: Cannot create property 'default' on string 'date'
>>   at module.exports (/Users/loay/Desktop/NodeEE/loopback/common/models/application.js:75:56)

As you see, I removed the first line in application.js and role.js but I think the proper solution is in application.json and role.json

    "created": {
      "default": "date"
    },
    "modified": {
      "default": "date"
    }

I will update that in the next commit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

> Mocha exploded!
> TypeError: Cannot create property 'default' on string 'date'
>   at module.exports (/Users/loay/Desktop/NodeEE/loopback/common/models/application.js:75:56)

Ah, makes sense now.

 "created": {
      "default": "date"
    },
    "modified": {
      "default": "date"
    }

The correct solution is to use "defaultFn": "now", see loopbackio/loopback-datasource-juggler#458

* A hook to generate keys before creation
* @param next
Expand Down Expand Up @@ -126,7 +115,7 @@ module.exports = function(Application) {
}
cb = cb || utils.createPromiseCallback();

var props = { owner: owner, name: name };
var props = {owner: owner, name: name};
for (var p in options) {
if (!(p in props)) {
props[p] = options[p];
Expand Down
10 changes: 8 additions & 2 deletions common/models/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@
"description": "Status of the application, production/sandbox/disabled"
},

"created": "date",
"modified": "date"
"created": {
"type": "date",
"defaultFn": "now"
},
"modified": {
"type": "date",
"defaultFn": "now"
}
}
}
13 changes: 7 additions & 6 deletions common/models/change.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
* Module Dependencies.
*/

'use strict';
var g = require('../../lib/globalize');
var PersistedModel = require('../../lib/loopback').PersistedModel;
var loopback = require('../../lib/loopback');
var utils = require('../../lib/utils');
var crypto = require('crypto');
var CJSON = { stringify: require('canonical-json') };
var CJSON = {stringify: require('canonical-json')};
var async = require('async');
var assert = require('assert');
var debug = require('debug')('loopback:change');
Expand Down Expand Up @@ -113,7 +114,7 @@ module.exports = function(Change) {

var msg = g.f('Cannot rectify %s changes:\n%s', modelName, desc);
err = new Error(msg);
err.details = { errors: errors };
err.details = {errors: errors};
return callback(err);
}
callback();
Expand Down Expand Up @@ -404,7 +405,7 @@ module.exports = function(Change) {
callback = callback || utils.createPromiseCallback();

if (!Array.isArray(remoteChanges) || remoteChanges.length === 0) {
callback(null, { deltas: [], conflicts: [] });
callback(null, {deltas: [], conflicts: []});
return callback.promise;
}
var remoteChangeIndex = {};
Expand All @@ -419,7 +420,7 @@ module.exports = function(Change) {
this.find({
where: {
modelName: modelName,
modelId: { inq: modelIds },
modelId: {inq: modelIds},
},
}, function(err, allLocalChanges) {
if (err) return callback(err);
Expand Down Expand Up @@ -674,7 +675,7 @@ module.exports = function(Change) {
if (err) return cb(err);
conflict.SourceModel.updateLastChange(
conflict.modelId,
{ prev: targetChange.rev },
{prev: targetChange.rev},
cb);
});
};
Expand Down Expand Up @@ -708,7 +709,7 @@ module.exports = function(Change) {
}
var inst = new conflict.SourceModel(
target.toObject(),
{ persisted: true });
{persisted: true});
inst.save(done);
});

Expand Down
7 changes: 4 additions & 3 deletions common/models/checkpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Module Dependencies.
*/

'use strict';
var assert = require('assert');

/**
Expand Down Expand Up @@ -41,8 +42,8 @@ module.exports = function(Checkpoint) {
};

Checkpoint._getSingleton = function(cb) {
var query = { limit: 1 }; // match all instances, return only one
var initialData = { seq: 1 };
var query = {limit: 1}; // match all instances, return only one
var initialData = {seq: 1};
this.findOrCreate(query, initialData, cb);
};

Expand All @@ -59,7 +60,7 @@ module.exports = function(Checkpoint) {
var originalSeq = cp.seq;
cp.seq++;
// Update the checkpoint but only if it was not changed under our hands
Checkpoint.updateAll({ id: cp.id, seq: originalSeq }, { seq: cp.seq }, function(err, info) {
Checkpoint.updateAll({id: cp.id, seq: originalSeq}, {seq: cp.seq}, function(err, info) {
if (err) return cb(err);
// possible outcomes
// 1) seq was updated to seq+1 - exactly what we wanted!
Expand Down
25 changes: 13 additions & 12 deletions common/models/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

/**
* Email model. Extends LoopBack base [Model](#model-new-model).
* @property {String} to Email addressee. Required.
* @property {String} from Email sender address. Required.
* @property {String} subject Email subject string. Required.
* @property {String} text Text body of email.
* @property {String} html HTML body of email.
*
* @class Email
* @inherits {Model}
*/

'use strict';
var g = require('../../lib/globalize');

/**
* Email model. Extends LoopBack base [Model](#model-new-model).
* @property {String} to Email addressee. Required.
* @property {String} from Email sender address. Required.
* @property {String} subject Email subject string. Required.
* @property {String} text Text body of email.
* @property {String} html HTML body of email.
*
* @class Email
* @inherits {Model}
*/

module.exports = function(Email) {
/**
* Send an email with the given `options`.
Expand Down
Loading