Skip to content

Commit

Permalink
feature: retrict terminal access to unverified users
Browse files Browse the repository at this point in the history
  • Loading branch information
stackexpress-shivam committed Sep 29, 2016
1 parent 577ace9 commit 6058cfe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
8 changes: 8 additions & 0 deletions lib/middleware/harbourmaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ var harbourmaster = module.exports = {
);
},

setTermAccess: function (containerKey, allowTerm) {
return series(
hipacheHosts.create(),
hipacheHosts.model.setTermAccess(
'container', allowTerm)
);
},

listDocklets: function (containerKey) {
return series (
hipacheHosts.create(),
Expand Down
14 changes: 14 additions & 0 deletions lib/models/redis/HipacheHosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ HipacheHosts.prototype.extendContainerLife = function (container, cb) {
});
};

HipacheHosts.prototype.setTermAccess = function (container, allowTerm, cb) {
var serviceKey = ['frontend:', container.servicesToken, '.', configs.userContentDomain].join('');

redis.lrange(serviceKey, 0, 0, function(err, reply) {
serviceData = JSON.parse(reply[0]);
serviceData.allowTerm = allowTerm;
var strData = JSON.stringify(serviceData);

redis.multi()
.lset(serviceKey, 0, strData)
.exec(cb);
});
};

HipacheHosts.prototype.howMuchLife = function (container, cb) {
var serviceKey = ['frontend:', container.servicesToken, '.', configs.userContentDomain].join('');

Expand Down
19 changes: 10 additions & 9 deletions lib/rest/containers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ var utils = require('middleware/utils');
var mw = require('dat-middleware');
var error = require('error');

var flow = require('middleware-flow');
var mwIf = flow.mwIf.bind(flow);

var ternary = utils.ternary;
var unless = utils.unless;
var series = utils.series;
Expand All @@ -27,13 +30,6 @@ module.exports = function (baseUrl) {
app.use(require('rest/containers/files')(path.join(baseUrl, ':containerId')));
app.use(require('rest/containers/import')(path.join(baseUrl, 'import')));

var restrictUnverifiedUser =
series(
utils.unless(me.isVerified,
containers.model.unset('servicesToken'),
containers.model.unset('webToken') )
);

app.post(baseUrl,
me.isUser,
query.require('from'),
Expand All @@ -56,7 +52,6 @@ module.exports = function (baseUrl) {
containers.model.set('saved', true))),
containers.model.save(),
containers.model.unset('files'), // dont respond files
restrictUnverifiedUser,
containers.respond);

app.get(baseUrl,
Expand All @@ -73,7 +68,13 @@ module.exports = function (baseUrl) {
containers.findById('params.containerId', { files: 0 }),
containers.checkFound,
or(me.isOwnerOf('container'), me.isModerator),
restrictUnverifiedUser,
mwIf(me.isModerator)
.then( // allow terminal to verified user
harbourmaster.setTermAccess('container', true)
)
.else( // deny terminal to unverified user
harbourmaster.setTermAccess('container', false)
),
containers.respond);

// TODO: updateContainer needs rework, especially the commit interactions with harbourmaster..
Expand Down

0 comments on commit 6058cfe

Please sign in to comment.