Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
remove session access in /name and /name/version, fixed #274
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse committed Mar 15, 2014
1 parent 5aa84b0 commit 7dab569
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
14 changes: 4 additions & 10 deletions controllers/registry/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,18 @@ exports.show = function *(next) {
userMap[users[i]] = true;
}
users = userMap;
var session = yield *this.session;
debug('show module, user: %s, allowSync: %s, isAdmin: %s',
session.name, session.allowSync, session.isAdmin);
// if module not exist in this registry,
// sync the module backend and return package info from official registry
if (rows.length === 0) {
if (!session.allowSync) {
if (!this.allowSync) {
this.status = 404;
this.body = {
error: 'not_found',
reason: 'document not found'
};
return;
}
var username = (session && session.name) || 'anonymous';
var result = yield SyncModuleWorker.sync(name, username);
var result = yield SyncModuleWorker.sync(name, 'sync-by-install');
this.status = result.ok ? 200 : result.statusCode;
this.body = result.pkg;
return;
Expand Down Expand Up @@ -187,9 +183,8 @@ exports.get = function *(next) {
this.body = mod.package;
return;
}
var session = yield *this.session;
// if not fond, sync from source registry
if (!session.allowSync) {
if (!this.allowSync) {
this.status = 404;
this.body = {
error: 'not exist',
Expand All @@ -198,8 +193,7 @@ exports.get = function *(next) {
return;
}

var username = (session && session.username) || 'anonymous';
var result = yield SyncModuleWorker.sync(name, username);
var result = yield SyncModuleWorker.sync(name, 'sync-by-install');
var pkg = result.pkg && result.pkg.versions[version];
if (!pkg) {
this.status = 404;
Expand Down
16 changes: 4 additions & 12 deletions middleware/sync_by_install.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,11 @@ module.exports = function *syncByInstall(next) {
if (this.get('user-agent') && this.get('user-agent').indexOf('node') !== 0) {
return yield *next;
}
var session = {};
try {
session = yield *this.session;
session.allowSync = true;
} catch (err) {
console.warn('get session error in syncByInstall');
yield *next;
}
if (session.isAdmin) {
// if current user is admin, should not enable auto sync on install, because it would be unpublish
session.allowSync = false;

if (this.query.write) {
return yield *next;
}

debug('%s allowSync: %s', session.name, session.allowSync);
this.allowSync = true;
yield *next;
};

0 comments on commit 7dab569

Please sign in to comment.