fix(prettier): Properly handle lint-stage files (#6970)
Now handles top level files and recursive files in folders. Set max line length to be 100
This commit is contained in:
114
src/Auth.js
114
src/Auth.js
@@ -29,7 +29,7 @@ function Auth({
|
||||
|
||||
// Whether this auth could possibly modify the given user id.
|
||||
// It still could be forbidden via ACLs even if this returns true.
|
||||
Auth.prototype.isUnauthenticated = function() {
|
||||
Auth.prototype.isUnauthenticated = function () {
|
||||
if (this.isMaster) {
|
||||
return false;
|
||||
}
|
||||
@@ -55,7 +55,7 @@ function nobody(config) {
|
||||
}
|
||||
|
||||
// Returns a promise that resolves to an Auth object
|
||||
const getAuthForSessionToken = async function({
|
||||
const getAuthForSessionToken = async function ({
|
||||
config,
|
||||
cacheController,
|
||||
sessionToken,
|
||||
@@ -85,37 +85,25 @@ const getAuthForSessionToken = async function({
|
||||
include: 'user',
|
||||
};
|
||||
|
||||
const query = new RestQuery(
|
||||
config,
|
||||
master(config),
|
||||
'_Session',
|
||||
{ sessionToken },
|
||||
restOptions
|
||||
);
|
||||
const query = new RestQuery(config, master(config), '_Session', { sessionToken }, restOptions);
|
||||
results = (await query.execute()).results;
|
||||
} else {
|
||||
results = (await new Parse.Query(Parse.Session)
|
||||
.limit(1)
|
||||
.include('user')
|
||||
.equalTo('sessionToken', sessionToken)
|
||||
.find({ useMasterKey: true })).map(obj => obj.toJSON());
|
||||
results = (
|
||||
await new Parse.Query(Parse.Session)
|
||||
.limit(1)
|
||||
.include('user')
|
||||
.equalTo('sessionToken', sessionToken)
|
||||
.find({ useMasterKey: true })
|
||||
).map(obj => obj.toJSON());
|
||||
}
|
||||
|
||||
if (results.length !== 1 || !results[0]['user']) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_SESSION_TOKEN,
|
||||
'Invalid session token'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'Invalid session token');
|
||||
}
|
||||
const now = new Date(),
|
||||
expiresAt = results[0].expiresAt
|
||||
? new Date(results[0].expiresAt.iso)
|
||||
: undefined;
|
||||
expiresAt = results[0].expiresAt ? new Date(results[0].expiresAt.iso) : undefined;
|
||||
if (expiresAt < now) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_SESSION_TOKEN,
|
||||
'Session token is expired.'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'Session token is expired.');
|
||||
}
|
||||
const obj = results[0]['user'];
|
||||
delete obj.password;
|
||||
@@ -134,28 +122,15 @@ const getAuthForSessionToken = async function({
|
||||
});
|
||||
};
|
||||
|
||||
var getAuthForLegacySessionToken = function({
|
||||
config,
|
||||
sessionToken,
|
||||
installationId,
|
||||
}) {
|
||||
var getAuthForLegacySessionToken = function ({ config, sessionToken, installationId }) {
|
||||
var restOptions = {
|
||||
limit: 1,
|
||||
};
|
||||
var query = new RestQuery(
|
||||
config,
|
||||
master(config),
|
||||
'_User',
|
||||
{ sessionToken },
|
||||
restOptions
|
||||
);
|
||||
var query = new RestQuery(config, master(config), '_User', { sessionToken }, restOptions);
|
||||
return query.execute().then(response => {
|
||||
var results = response.results;
|
||||
if (results.length !== 1) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_SESSION_TOKEN,
|
||||
'invalid legacy session token'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'invalid legacy session token');
|
||||
}
|
||||
const obj = results[0];
|
||||
obj.className = '_User';
|
||||
@@ -170,7 +145,7 @@ var getAuthForLegacySessionToken = function({
|
||||
};
|
||||
|
||||
// Returns a promise that resolves to an array of role names
|
||||
Auth.prototype.getUserRoles = function() {
|
||||
Auth.prototype.getUserRoles = function () {
|
||||
if (this.isMaster || !this.user) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
@@ -184,7 +159,7 @@ Auth.prototype.getUserRoles = function() {
|
||||
return this.rolePromise;
|
||||
};
|
||||
|
||||
Auth.prototype.getRolesForUser = async function() {
|
||||
Auth.prototype.getRolesForUser = async function () {
|
||||
//Stack all Parse.Role
|
||||
const results = [];
|
||||
if (this.config) {
|
||||
@@ -195,13 +170,9 @@ Auth.prototype.getRolesForUser = async function() {
|
||||
objectId: this.user.id,
|
||||
},
|
||||
};
|
||||
await new RestQuery(
|
||||
this.config,
|
||||
master(this.config),
|
||||
'_Role',
|
||||
restWhere,
|
||||
{}
|
||||
).each(result => results.push(result));
|
||||
await new RestQuery(this.config, master(this.config), '_Role', restWhere, {}).each(result =>
|
||||
results.push(result)
|
||||
);
|
||||
} else {
|
||||
await new Parse.Query(Parse.Role)
|
||||
.equalTo('users', this.user)
|
||||
@@ -211,7 +182,7 @@ Auth.prototype.getRolesForUser = async function() {
|
||||
};
|
||||
|
||||
// Iterates through the role tree and compiles a user's roles
|
||||
Auth.prototype._loadRoles = async function() {
|
||||
Auth.prototype._loadRoles = async function () {
|
||||
if (this.cacheController) {
|
||||
const cachedRoles = await this.cacheController.role.get(this.user.id);
|
||||
if (cachedRoles != null) {
|
||||
@@ -242,10 +213,7 @@ Auth.prototype._loadRoles = async function() {
|
||||
);
|
||||
|
||||
// run the recursive finding
|
||||
const roleNames = await this._getAllRolesNamesForRoleIds(
|
||||
rolesMap.ids,
|
||||
rolesMap.names
|
||||
);
|
||||
const roleNames = await this._getAllRolesNamesForRoleIds(rolesMap.ids, rolesMap.names);
|
||||
this.userRoles = roleNames.map(r => {
|
||||
return 'role:' + r;
|
||||
});
|
||||
@@ -255,7 +223,7 @@ Auth.prototype._loadRoles = async function() {
|
||||
return this.userRoles;
|
||||
};
|
||||
|
||||
Auth.prototype.cacheRoles = function() {
|
||||
Auth.prototype.cacheRoles = function () {
|
||||
if (!this.cacheController) {
|
||||
return false;
|
||||
}
|
||||
@@ -263,7 +231,7 @@ Auth.prototype.cacheRoles = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
Auth.prototype.getRolesByIds = async function(ins) {
|
||||
Auth.prototype.getRolesByIds = async function (ins) {
|
||||
const results = [];
|
||||
// Build an OR query across all parentRoles
|
||||
if (!this.config) {
|
||||
@@ -286,23 +254,15 @@ Auth.prototype.getRolesByIds = async function(ins) {
|
||||
};
|
||||
});
|
||||
const restWhere = { roles: { $in: roles } };
|
||||
await new RestQuery(
|
||||
this.config,
|
||||
master(this.config),
|
||||
'_Role',
|
||||
restWhere,
|
||||
{}
|
||||
).each(result => results.push(result));
|
||||
await new RestQuery(this.config, master(this.config), '_Role', restWhere, {}).each(result =>
|
||||
results.push(result)
|
||||
);
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
// Given a list of roleIds, find all the parent roles, returns a promise with all names
|
||||
Auth.prototype._getAllRolesNamesForRoleIds = function(
|
||||
roleIDs,
|
||||
names = [],
|
||||
queriedRoles = {}
|
||||
) {
|
||||
Auth.prototype._getAllRolesNamesForRoleIds = function (roleIDs, names = [], queriedRoles = {}) {
|
||||
const ins = roleIDs.filter(roleID => {
|
||||
const wasQueried = queriedRoles[roleID] !== true;
|
||||
queriedRoles[roleID] = true;
|
||||
@@ -332,18 +292,14 @@ Auth.prototype._getAllRolesNamesForRoleIds = function(
|
||||
// store the new found names
|
||||
names = names.concat(resultMap.names);
|
||||
// find the next ones, circular roles will be cut
|
||||
return this._getAllRolesNamesForRoleIds(
|
||||
resultMap.ids,
|
||||
names,
|
||||
queriedRoles
|
||||
);
|
||||
return this._getAllRolesNamesForRoleIds(resultMap.ids, names, queriedRoles);
|
||||
})
|
||||
.then(names => {
|
||||
return Promise.resolve([...new Set(names)]);
|
||||
});
|
||||
};
|
||||
|
||||
const createSession = function(
|
||||
const createSession = function (
|
||||
config,
|
||||
{ userId, createdWith, installationId, additionalSessionData }
|
||||
) {
|
||||
@@ -372,13 +328,7 @@ const createSession = function(
|
||||
return {
|
||||
sessionData,
|
||||
createSession: () =>
|
||||
new RestWrite(
|
||||
config,
|
||||
master(config),
|
||||
'_Session',
|
||||
null,
|
||||
sessionData
|
||||
).execute(),
|
||||
new RestWrite(config, master(config), '_Session', null, sessionData).execute(),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user