Skip to content

Commit

Permalink
Separated out the restricted use token to a separate branch so we can…
Browse files Browse the repository at this point in the history
… ship it - #70
  • Loading branch information
tiblu committed Jan 14, 2019
1 parent acf941a commit d87640d
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 174 deletions.
31 changes: 0 additions & 31 deletions db/migrations/20181113111601-create-topic-report.js

This file was deleted.

45 changes: 0 additions & 45 deletions db/models/TopicReport.js

This file was deleted.

1 change: 0 additions & 1 deletion libs/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = function (app) {
var path = require('path');
var moment = app.get('moment');
var url = app.get('url');
var jwt = app.get('jwt');
var cosJwt = app.get('cosJwt');

var User = models.User;
Expand Down
1 change: 0 additions & 1 deletion libs/middleware/authTokenRestrictedUse.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
module.exports = function (req, res, next) {
var app = req.app;
var config = app.get('config');
var logger = app.get('logger');
var jwt = app.get('jwt');
var cosJwt = app.get('cosJwt');
Expand Down
64 changes: 0 additions & 64 deletions routes/api/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ module.exports = function (app) {
var Topic = models.Topic;
var TopicMemberUser = models.TopicMemberUser;
var TopicMemberGroup = models.TopicMemberGroup;
var TopicReport = models.TopicReport;

var Report = models.Report;

Expand Down Expand Up @@ -3494,69 +3493,6 @@ module.exports = function (app) {
app.get('/api/users/:userId/topics/:topicId/attachments/:attachmentId', loginCheck(['partner']), hasPermission(TopicMemberUser.LEVELS.read, true), readAttachment);
app.get('/api/topics/:topicId/attachments/:attachmentId', hasVisibility(Topic.VISIBILITY.public), readAttachment);

var topicReportsCreate = function (req, res, next) {
var topicId = req.params.topicId;

db
.transaction(function (t) {
return Report
.create(
{
type: req.body.type,
text: req.body.text,
creatorId: req.user.id,
creatorIp: req.ip
},
{
transaction: t
}
)
.then(function (report) {
// FIXME: Topic report create activity!
return TopicReport
.create(
{
topicId: topicId,
reportId: report.id
},
{
transaction: t
}
)
.then(function () {
return report;
});
});
})
.then(function (report) {
//FIXME: Send TopicReport e-mail - emailLib.sendCommentReport(commentId, report); // Fire and forget

return res.ok(report);
})
.catch(next);
};

app.post(['/api/users/:userId/topics/:topicId/reports', '/api/topics/:topicId/reports'], loginCheck(['partner']), topicReportsCreate);

/**
* Read Topic Report
*/
app.get(['/api/topics/:topicId/reports/:reportId', '/api/users/:userId/topics/:topicId/reports/:reportId'], function (req, res, next) {
//FIXME Implement
return res.notImplemented();
});

/**
* Moderate a Topic
*/
app.post('/api/topics/:topicId/reports/:reportId/moderate', function (req, res, next) {
var reportType = req.body.type; // Delete reason type which is provided in case deleted/hidden by moderator due to a user report
var reportText = req.body.text; // Free text with reason why the comment was deleted/hidden

// FIXME: Implement
return res.notImplemented();
});

/**
* Create Topic Comment
*/
Expand Down
20 changes: 0 additions & 20 deletions test/api/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,26 +394,6 @@ var topicMembersGroupsList = function (agent, userId, topicId, callback) {
_topicMembersGroupsList(agent, userId, topicId, 200, callback);
};

var _topicReportCreate = function (agent, topicId, type, text, expectedHttpCode, callback) {
var path = '/api/topics/:topicId/reports'
.replace(':topicId', topicId);

agent
.post(path)
.set('Content-Type', 'application/json')
.send({
type: type,
text: text
})
.expect(expectedHttpCode)
.expect('Content-Type', /json/)
.end(callback);
};

var topicReportCreate = function (agent, topicId, type, text, callback) {
_topicReportCreate(agent, topicId, type, text, 200, callback);
};

var _topicCommentCreate = function (agent, userId, topicId, parentId, parentVersion, type, subject, text, expectedHttpCode, callback) {
var path = '/api/users/:userId/topics/:topicId/comments'
.replace(':userId', userId)
Expand Down
24 changes: 12 additions & 12 deletions test/utils/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ var closeDb = function () {
// BUT, as in the universe of these tests there is only one instance of Sequelize, thus if I call sequelize.close() in the suiteTearDown(), next tests will fail cause they cannot get a connection.
// Sequelize has pool.min, pool.idle and pool.evict which clean up the pool, but that by design does not exit Sequelize.
// So I have 2 options: this hack or in suiteSetup each test sets a new Sequelize connection and kills it later. Right now it's the hack.
//if (!interval) {
// interval = setInterval(function () {
// if (db.connectionManager.pool._allObjects.size === 0) {
// clearInterval(interval);
// db
// .close()
// .then(function () {
// logger.info('DB connection force closed from shared.closeDb as the pool was empty.');
// });
// }
// }, 5000);
//}
if (!interval) {
interval = setInterval(function () {
if (db.connectionManager.pool._allObjects.size === 0) {
clearInterval(interval);
db
.close()
.then(function () {
logger.info('DB connection force closed from shared.closeDb as the pool was empty.');
});
}
}, 5000);
}

return Promise.resolve();
};
Expand Down

0 comments on commit d87640d

Please sign in to comment.