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

Commit

Permalink
show unpublished info on web package page. fixes #381
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jul 23, 2014
1 parent 0bf1863 commit 081f0cb
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
24 changes: 24 additions & 0 deletions controllers/web/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var ModuleDeps = require('../../proxy/module_deps');
var setDownloadURL = require('../../lib/common').setDownloadURL;
var ModuleStar = require('../../proxy/module_star');
var packageService = require('../../services/package');
var ModuleUnpublished = require('../../proxy/module_unpublished');

exports.display = function* (next) {
var params = this.params;
Expand Down Expand Up @@ -63,6 +64,29 @@ exports.display = function* (next) {
}

if (!pkg || !pkg.package) {
// check if unpublished
var unpublishedInfo = yield* ModuleUnpublished.get(name);
debug('show unpublished %j', unpublishedInfo);
if (unpublishedInfo) {
var data = {
name: name,
unpublished: unpublishedInfo.package
};
data.unpublished.time = new Date(data.unpublished.time);
if (data.unpublished.maintainers) {
for (var i = 0; i < data.unpublished.maintainers.length; i++) {
var maintainer = data.unpublished.maintainers[i];
if (maintainer.email) {
maintainer.gravatar = gravatar.url(maintainer.email, {s: '50', d: 'retro'}, true);
}
}
}
yield this.render('package_unpublished', {
package: data
});
return;
}

return yield* next;
}

Expand Down
25 changes: 25 additions & 0 deletions test/controllers/web/package.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var mysql = require('../../../common/mysql');
var app = require('../../../servers/web');
var registry = require('../../../servers/registry');
var pkg = require('../../../controllers/web/package');
var SyncModuleWorker = require('../../../proxy/sync_module_worker');
var utils = require('../../utils');

var fixtures = path.join(path.dirname(path.dirname(__dirname)), 'fixtures');
Expand Down Expand Up @@ -212,4 +213,28 @@ describe('controllers/web/package.test.js', function () {
.expect(/Log/, done);
});
});

describe('unpublished package', function () {
before(function (done) {
var worker = new SyncModuleWorker({
name: ['browserjs'],
username: 'fengmk2'
});

worker.start();
worker.on('end', function () {
var names = worker.successes.concat(worker.fails);
names.sort();
names.should.eql(['browserjs']);
done();
});
});

it('should display unpublished info', function (done) {
request(app)
.get('/package/browserjs')
.expect(200)
.expect(/This package has been unpublished\./, done);
});
});
});
64 changes: 64 additions & 0 deletions view/web/package_unpublished.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<div id="package">
<h1>
<%= package.name %>
<small>
(<a href="/sync/<%= package.name %>" target="_blank">SYNC</a> again from source npm registry)
</small>
</h1>

<p class="description">This package has been unpublished.</p>

<ul class="nav nav-tabs">
<li class="active"><a href="#meta">package.json</a></li>
</ul>

<table class="metadata active">
<tr>
<th>Description</th>
<td>
<%= package.unpublished.description %>
</td>
</tr>

<tr>
<th>Unpublished By</th>
<td>
<span class="user">
<a class="username" href="/~<%= package.unpublished.name %>">
<%= package.unpublished.name %>
</a>
</span>
</td>
</tr>

<tr>
<th>Unpublished On</th>
<td>
<%- package.unpublished.time %>
</td>
</tr>

<tr>
<th>Maintainers</th>
<td>
<% package.unpublished.maintainers.forEach(function (m) { %>
<span class="user">
<a class="username" href="/~<%= m.name %>">
<% if (m.gravatar) { %>
<img src="<%- m.gravatar %>" class="avatar">
<% } %>
<%= m.name %>
</a>
</span>
<% }) %>
</td>

<tr>
<th>Versions (<%- package.unpublished.versions.length %>)</th>
<td>
<%- package.unpublished.versions.reverse().slice(0, 20).join(', ') %> ...
</td>
</tr>

</table>
</div>

0 comments on commit 081f0cb

Please sign in to comment.