Skip to content

Commit

Permalink
Remove flags backend and frontend (#448)
Browse files Browse the repository at this point in the history
* Minor changes

* Created API endpoints for escalation and notes

* "Removed" all referenes to flag in the backend

* Update table.html

* Add files via upload

* Remove all references to flag in backend

* Add files via upload

* Update report.js

* Update report-query.js

* Attempt to merge flag removals #1

* Attempt merge #1

* Attempting to debug merge issue

* Remove accidental crowdtangle data

* Found a few extra.

Co-authored-by: Ameya Jadhav <jadhavameyak@gmail.com>
Co-authored-by: Matthew Lim <limmat@gatech.edu>
  • Loading branch information
3 people committed Mar 14, 2021
1 parent 6f636ee commit 6d34951
Show file tree
Hide file tree
Showing 28 changed files with 1,735 additions and 2,002 deletions.
9 changes: 5 additions & 4 deletions config/crowdtangle_list.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"crowdtangle_list_account_pairs": {},
"crowdtangle_saved_searches": {}
}
{ "crowdtangle_list_account_pairs": {
},
"crowdtangle_saved_searches": {
}
}
1 change: 0 additions & 1 deletion lib/analytics/stats-master.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var StatsMaster = function() {
this.stats = {
totalReports: 0,
totalReportsUnread: 0,
totalReportsFlagged: 0,
totalReportsPerMinute: 0,
totalIncidents: 0,
totalEscalatedIncidents: 0
Expand Down
1 change: 0 additions & 1 deletion lib/analytics/stats-queryer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ StatsQueryer.prototype._countAllReports = function(callback) {
totalReports: this._countReports,
totalReportsUnread: this._countReports.bind(this, { read: false }),
totalReportsPerMinute: this._countReports.bind(this, { storedAt: { $gte: minuteAgo() } }),
totalReportsFlagged: this._countReports.bind(this, { flagged: true })
}, callback);
};

Expand Down
27 changes: 2 additions & 25 deletions lib/api/v1/report-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,14 @@ module.exports = function(app, user) {
if (err) return res.send(err.status, err.message);
if (!report) return res.send(404);
// Update the actual value
_.each(_.pick(req.body, ['flagged', '_incident', 'read', 'smtcTags', 'notes', 'escalated', 'veracity']), function(val, key) {
_.each(_.pick(req.body, ['_incident', 'read', 'smtcTags', 'notes', 'escalated', 'veracity']), function(val, key) {
report[key] = val;
});
// Save report
report.save(function(err, numberAffected) {
if (err) res.send(err.status, err.message);
else if (!numberAffected) res.send(404);
else {
writelog.writeReport(req, report, 'flag/unflag/removeFromIncident/updateTags');
res.send(200);
}
});
Expand Down Expand Up @@ -147,7 +146,7 @@ module.exports = function(app, user) {
if (!res.headersSent) res.send(err.status, err.message)
return;
}
writelog.writeReport(req, report, 'flagReport');
writelog.writeReport(req, report, 'changeVeracityReport');
if (--remaining === 0) return res.send(200);
});
});
Expand Down Expand Up @@ -176,28 +175,6 @@ module.exports = function(app, user) {
});
});

// Flag selected reports
app.patch('/api/v1/report/_flag', user.can('edit data'), function(req, res) {
if (!req.body.ids || !req.body.ids.length) return res.send(200);
Report.find({ _id: { $in: req.body.ids } }, function(err, reports) {
if (err) return res.send(err.status, err.message);
if (reports.length === 0) return res.send(200);
var remaining = reports.length;
reports.forEach(function(report) {
// Mark each report as flagged to catch it in model
report.toggleFlagged(req.body.flagged);
report.save(function(err) {
if (err) {
if (!res.headersSent) res.send(err.status, err.message)
return;
}
writelog.writeReport(req, report, 'flagReport');
if (--remaining === 0) return res.send(200);
});
});
});
});

// Link selected reports to one incident
app.patch('/api/v1/report/_link', user.can('edit data'), function(req, res) {
if (!req.body.ids || !req.body.ids.length) return res.send(200);
Expand Down
16 changes: 2 additions & 14 deletions lib/fetching/content-services/twitter-content-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ var tweetMatches = require('tweet-matches');
var Promise = require('promise');

function TwitterContentService() {
this._twit = new Twit(_.clone(
{
consumer_key: config.get().twitter.API_key,
consumer_secret: config.get().twitter.API_key_secret,
access_token: config.get().twitter.access_token,
access_token_secret: config.get().twitter.access_token_secret
}));
this._twit = new Twit(_.clone(config.get().twitter));
this._connectedSources = {};
this._compiledQueries = {};
this.fetchType = 'subscribe';
Expand Down Expand Up @@ -168,13 +162,7 @@ TwitterContentService.prototype.reloadSettings = function() {
delete this._stream;
delete this._twit;

this._twit = new Twit(_.clone(
{
consumer_key: config.get().twitter.API_key,
consumer_secret: config.get().twitter.API_key_secret,
access_token: config.get().twitter.access_token,
access_token_secret: config.get().twitter.access_token_secret
}));
this._twit = new Twit(_.clone(config.get().twitter));
this._start();
};

Expand Down
1 change: 0 additions & 1 deletion lib/writeLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ writer.writeReport = function(req, report, action, query) {
} else logDetails.actionRef = {};
if (action === 'flag/unflag/removeFromIncident') {
logDetails.actionRef.reportFlags = {
flagged: report.flagged,
read: report.read,
linkedToIncident: report._incident ? true : false
};
Expand Down
14 changes: 2 additions & 12 deletions models/query/report-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ ReportQuery.prototype.toMongooseFilter = function() {
_media: this.media,
_incident: this.incidentId,
read: this.read,
flagged: this.flagged,
commentTo: this.commentTo,
escalated: this.escalated,
notes: this.notes,
notes: this.notes
}
if (this.escalated === 'unescalated') filter.escalated= false;
if (this.escalated === 'escalated') filter.escalated = true;
Expand All @@ -67,27 +66,18 @@ ReportQuery.prototype.toMongooseFilter = function() {
if (this.keywords) filter.$and.push({"content": {$regex: this.keywords, $options: 'i'}});
if (this.tags) filter.smtcTags = { $all: this.tags }
if (this.list) filter["metadata.ct_tag"] = {$in: [this.list] }
console.log(filter)
return filter;
};

ReportQuery.prototype._parseStatus = function(status) {
switch (status) {
case 'Flagged':
this.flagged = true;
break;
case 'Unflagged':
this.unflagged = true;
break;
case 'Read':
this.read = true;
break;
case 'Unread':
this.read = false;
break;
case 'Read & Unflagged':
this.read = true;
this.flagged = false;
break;
}
};

Expand Down
18 changes: 9 additions & 9 deletions models/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var SchemaTypes = mongoose.SchemaTypes;
var logger = require('../lib/logger');
var SMTCTag = require('../models/tag');
var { addPost, removePost } = require('../lib/comments');
var _= require('lodash')

var schema = new Schema({
authoredAt: {type: Date, index: true},
Expand All @@ -22,7 +23,6 @@ var schema = new Schema({
tags: { type: [String], default: [] },
smtcTags: {type: [{type: SchemaTypes.ObjectId, ref: 'SMTCTag'}], default: []},
read: { type: Boolean, default: false, required: true, index: true },
flagged: { type: Boolean, default: false, required: true, index: true },
_sources: [{ type: String, ref: 'Source', index: true }],
_media: { type: [String], index: true },
_sourceNicknames: [String],
Expand Down Expand Up @@ -68,21 +68,14 @@ schema.post('save', function() {
}
});

schema.methods.toggleFlagged = function(flagged) {
this.flagged = flagged;

if (flagged) {
this.read = true;
}
};

schema.methods.toggleRead = function(read) {
this.read = read;
};

schema.methods.toggleVeracity = function(veracity) {
this.veracity = veracity;
};

schema.methods.toggleEscalated = function(escalated) {
this.escalated = escalated;
};
Expand Down Expand Up @@ -204,9 +197,16 @@ Report.queryReports = function(query, page, callback) {
// Re-set search timestamp
query.since = new Date();

if (query.veracity === 'confirmed true') filter.veracity = true;
if (query.veracity === 'confirmed false') filter.veracity = false;
if (query.veracity === 'unconfirmed') filter.veracity = null;
if (_.isBoolean(query.veracity)) filter.veracity = query.veracity;

Report.findSortedPage(filter, page, callback);
};



Report.findSortedPage = function(filter, page, callback) {
Report.findPage(filter, page, { sort: '-storedAt' }, function(err, reports) {
if (err) return callback(err);
Expand Down
2 changes: 1 addition & 1 deletion public/angular/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ angular.module('Aggie')

.value('widgetSettingsOptions', ['incident map'])

.value('statusOptions', ['Read', 'Unread', 'Flagged', 'Unflagged', 'Read & Unflagged'])
.value('statusOptions', ['Read', 'Unread'])

.value('linkedtoIncidentOptions', [{ _id: 'any', title: '* Any Incident' },
{ _id: 'none', title: '* Without Incident' }])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,6 @@ angular.module('Aggie')
});
};

$scope.toggleFlagged = function(report) {
report.flagged = !report.flagged;
if (report.flagged) {
report.read = report.flagged;
}
$scope.saveReport(report);
};

$scope.isFirstPage = function() {
return $scope.pagination.page === 1;
Expand Down
9 changes: 0 additions & 9 deletions public/angular/js/controllers/incidents/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,6 @@ angular.module('Aggie')
});
};

$scope.toggleFlagged = function(report) {
report.flagged = !report.flagged;

if (report.flagged) {
report.read = report.flagged;
}

$scope.saveReport(report);
};

$scope.saveReport = function(report) {
Report.save({ id: report._id }, report, function() {
Expand Down
Loading

0 comments on commit 6d34951

Please sign in to comment.