Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
Merge branch 'vNext_aaladev_4' of github.com:thaliproject/salti into …
Browse files Browse the repository at this point in the history
…vNext_aaladev_10
  • Loading branch information
andrew-aladev committed Aug 8, 2016
2 parents a0c3b1e + c6969aa commit 1293fdb
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,13 @@ Salti.prototype.handler = function (request, response, nextHandler) {

// Next section deals with
// /{:db}/{:id}, /{:db}/_local/{:id} and /{:db}/{:id}/attachment stuff.
if (!this.cutDBPrefix()) {
var cuttedPath = this.getPathWithoutPrefix();
if (!cuttedPath) {
// Required DB Prefix is not valid.
return this.unauthorized(3);
}

var pathParts = this.path.split('/');
var pathParts = cuttedPath.split('/');
if (pathParts[0] !== '') {
// Sanity check, the first element should always be empty.
return this.unauthorized(4);
Expand All @@ -140,7 +141,7 @@ Salti.prototype.handler = function (request, response, nextHandler) {

else if (pathParts.length === 3 && pathParts[1] === '_local') {
// Is this a thali {:id}?
var isThaliPrefix = this.path.startsWith(Salti.THALI_PREFIX);
var isThaliPrefix = cuttedPath.startsWith(Salti.THALI_PREFIX);
if (isThaliPrefix) {
// Is /_local/thali_{:id} authorized?
lookupPath = this.dbPrefix + Salti.THALI_PREFIX +
Expand All @@ -149,7 +150,7 @@ Salti.prototype.handler = function (request, response, nextHandler) {
debug('unauthorized thali prefix');
return this.unauthorized(6);
}
var thaliId = this.path.substring(Salti.THALI_PREFIX.length);
var thaliId = cuttedPath.substring(Salti.THALI_PREFIX.length);
if (!this.resolveThaliId(thaliId)) {
debug('unauthorized thali id');
return this.unauthorized(7);
Expand Down Expand Up @@ -229,13 +230,12 @@ Salti.stripTrailingSlash = function (path) {
return path;
};

Salti.prototype.cutDBPrefix = function () {
Salti.prototype.getPathWithoutPrefix = function () {
var isDbPath = this.path.startsWith(this.dbPrefix);
if (!isDbPath) {
return false;
return null;
}
this.path = this.path.substring(this.dbPrefix.length);
return true;
return this.path.substring(this.dbPrefix.length);
};

Salti.prototype.authorized = function () {
Expand Down

0 comments on commit 1293fdb

Please sign in to comment.