Merge branch 'master' into user-blocking
commit
dc386b5b23
@ -0,0 +1,4 @@
|
||||
*
|
||||
*/
|
||||
!export
|
||||
!.gitignore
|
@ -0,0 +1,3 @@
|
||||
.
|
||||
!.gitignore
|
||||
!README
|
@ -0,0 +1,5 @@
|
||||
This directory contains archives of user uploads that are prepared on-demand
|
||||
when a user wants to retrieve a copy of their uploaded content.
|
||||
|
||||
You can delete the files in here at will. They will just be regenerated if
|
||||
requested again.
|
@ -1,6 +1,8 @@
|
||||
{
|
||||
"upload-file": "Upload File",
|
||||
"filename": "Filename",
|
||||
"usage": "Post Usage",
|
||||
"orphaned": "Orphaned",
|
||||
"size/filecount": "Size / Filecount",
|
||||
"confirm-delete": "Do you really want to delete this file?",
|
||||
"filecount": "%1 files"
|
||||
|
@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
define('forum/account/consent', ['forum/account/header'], function (header) {
|
||||
var Consent = {};
|
||||
|
||||
Consent.init = function () {
|
||||
header.init();
|
||||
|
||||
$('[data-action="consent"]').on('click', function () {
|
||||
socket.emit('user.gdpr.consent', {}, function (err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
ajaxify.refresh();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return Consent;
|
||||
});
|
@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
define('forum/account/uploads', ['forum/account/header'], function (header) {
|
||||
var AccountUploads = {};
|
||||
|
||||
AccountUploads.init = function () {
|
||||
header.init();
|
||||
|
||||
$('[data-action="delete"]').on('click', function () {
|
||||
var el = $(this).parents('[data-name]');
|
||||
var name = el.attr('data-name');
|
||||
|
||||
socket.emit('user.deleteUpload', { name: name, uid: ajaxify.data.uid }, function (err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
el.remove();
|
||||
});
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
return AccountUploads;
|
||||
});
|
@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
|
||||
var db = require('../../database');
|
||||
var meta = require('../../meta');
|
||||
var helpers = require('../helpers');
|
||||
var accountHelpers = require('./helpers');
|
||||
|
||||
var consentController = {};
|
||||
|
||||
consentController.get = function (req, res, next) {
|
||||
var userData;
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
|
||||
},
|
||||
function (_userData, next) {
|
||||
userData = _userData;
|
||||
if (!userData) {
|
||||
return next();
|
||||
}
|
||||
|
||||
// Direct database call is used here because `gdpr_consent` is a protected user field and is automatically scrubbed from standard user data retrieval calls
|
||||
db.getObjectField('user:' + userData.uid, 'gdpr_consent', function (err, consented) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
userData.gdpr_consent = !!parseInt(consented, 10);
|
||||
|
||||
next(null, userData);
|
||||
});
|
||||
},
|
||||
], function (err, userData) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
userData.digest = {
|
||||
frequency: meta.config.dailyDigestFreq,
|
||||
enabled: meta.config.dailyDigestFreq !== 'off',
|
||||
};
|
||||
|
||||
userData.title = '[[user:consent.title]]';
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[user:consent.title]]' }]);
|
||||
|
||||
res.render('account/consent', userData);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = consentController;
|
@ -0,0 +1,57 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
var async = require('async');
|
||||
var nconf = require('nconf');
|
||||
|
||||
var db = require('../../database');
|
||||
var helpers = require('../helpers');
|
||||
var meta = require('../../meta');
|
||||
var pagination = require('../../pagination');
|
||||
var accountHelpers = require('./helpers');
|
||||
|
||||
var uploadsController = module.exports;
|
||||
|
||||
uploadsController.get = function (req, res, callback) {
|
||||
var userData;
|
||||
|
||||
var page = Math.max(1, parseInt(req.query.page, 10) || 1);
|
||||
var itemsPerPage = 25;
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
|
||||
},
|
||||
function (_userData, next) {
|
||||
userData = _userData;
|
||||
if (!userData) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
var start = (page - 1) * itemsPerPage;
|
||||
var stop = start + itemsPerPage - 1;
|
||||
async.parallel({
|
||||
itemCount: function (next) {
|
||||
db.sortedSetCard('uid:' + userData.uid + ':uploads', next);
|
||||
},
|
||||
uploadNames: function (next) {
|
||||
db.getSortedSetRevRange('uid:' + userData.uid + ':uploads', start, stop, next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results) {
|
||||
userData.uploads = results.uploadNames.map(function (uploadName) {
|
||||
return {
|
||||
name: uploadName,
|
||||
url: nconf.get('upload_url') + uploadName,
|
||||
};
|
||||
});
|
||||
var pageCount = Math.ceil(results.itemCount / itemsPerPage);
|
||||
userData.pagination = pagination.create(page, pageCount, req.query);
|
||||
userData.privateUploads = parseInt(meta.config.privateUploads, 10) === 1;
|
||||
userData.title = '[[pages:account/uploads, ' + userData.username + ']]';
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[global:uploads]]' }]);
|
||||
res.render('account/uploads', userData);
|
||||
},
|
||||
], callback);
|
||||
};
|
@ -0,0 +1,110 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var crypto = require('crypto');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var db = require('../database');
|
||||
|
||||
module.exports = function (Posts) {
|
||||
Posts.uploads = {};
|
||||
|
||||
const md5 = filename => crypto.createHash('md5').update(filename).digest('hex');
|
||||
const pathPrefix = path.join(__dirname, '../../public/uploads/files');
|
||||
|
||||
Posts.uploads.sync = function (pid, callback) {
|
||||
// Scans a post and updates sorted set of uploads
|
||||
const searchRegex = /\/assets\/uploads\/files\/([^\s")]+\.?[\w]*)/g;
|
||||
|
||||
async.parallel({
|
||||
content: async.apply(Posts.getPostField, pid, 'content'),
|
||||
uploads: async.apply(Posts.uploads.list, pid),
|
||||
}, function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
// Extract upload file paths from post content
|
||||
let match = searchRegex.exec(data.content);
|
||||
const uploads = [];
|
||||
while (match) {
|
||||
uploads.push(match[1].replace('-resized', ''));
|
||||
match = searchRegex.exec(data.content);
|
||||
}
|
||||
|
||||
// Create add/remove sets
|
||||
const add = uploads.filter(path => !data.uploads.includes(path));
|
||||
const remove = data.uploads.filter(path => !uploads.includes(path));
|
||||
|
||||
async.parallel([
|
||||
async.apply(Posts.uploads.associate, pid, add),
|
||||
async.apply(Posts.uploads.dissociate, pid, remove),
|
||||
], function (err) {
|
||||
// Strictly return only err
|
||||
callback(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Posts.uploads.list = function (pid, callback) {
|
||||
// Returns array of this post's uploads
|
||||
db.getSortedSetRange('post:' + pid + ':uploads', 0, -1, callback);
|
||||
};
|
||||
|
||||
Posts.uploads.isOrphan = function (filePath, callback) {
|
||||
// Returns bool indicating whether a file is still CURRENTLY included in any posts
|
||||
db.sortedSetCard('upload:' + md5(filePath) + ':pids', function (err, length) {
|
||||
callback(err, length === 0);
|
||||
});
|
||||
};
|
||||
|
||||
Posts.uploads.getUsage = function (filePaths, callback) {
|
||||
// Given an array of file names, determines which pids they are used in
|
||||
if (!Array.isArray(filePaths)) {
|
||||
filePaths = [filePaths];
|
||||
}
|
||||
|
||||
const keys = filePaths.map(fileObj => 'upload:' + md5(fileObj.name.replace('-resized', '')) + ':pids');
|
||||
async.map(keys, function (key, next) {
|
||||
db.getSortedSetRange(key, 0, -1, next);
|
||||
}, callback);
|
||||
};
|
||||
|
||||
Posts.uploads.associate = function (pid, filePaths, callback) {
|
||||
// Adds an upload to a post's sorted set of uploads
|
||||
const now = Date.now();
|
||||
filePaths = !Array.isArray(filePaths) ? [filePaths] : filePaths;
|
||||
const scores = filePaths.map(() => now);
|
||||
|
||||
async.filter(filePaths, function (filePath, next) {
|
||||
// Only process files that exist
|
||||
fs.access(path.join(pathPrefix, filePath), fs.constants.F_OK | fs.constants.R_OK, function (err) {
|
||||
next(null, !err);
|
||||
});
|
||||
}, function (err, filePaths) {
|
||||
let methods = [async.apply(db.sortedSetAdd.bind(db), 'post:' + pid + ':uploads', scores, filePaths)];
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
methods = methods.concat(filePaths.map(path => async.apply(db.sortedSetAdd.bind(db), 'upload:' + md5(path) + ':pids', now, pid)));
|
||||
async.parallel(methods, function (err) {
|
||||
// Strictly return only err
|
||||
callback(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Posts.uploads.dissociate = function (pid, filePaths, callback) {
|
||||
// Removes an upload from a post's sorted set of uploads
|
||||
filePaths = !Array.isArray(filePaths) ? [filePaths] : filePaths;
|
||||
let methods = [async.apply(db.sortedSetRemove.bind(db), 'post:' + pid + ':uploads', filePaths)];
|
||||
methods = methods.concat(filePaths.map(path => async.apply(db.sortedSetRemove.bind(db), 'upload:' + md5(path) + ':pids', pid)));
|
||||
|
||||
async.parallel(methods, function (err) {
|
||||
// Strictly return only err
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
};
|
@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
var privileges = require('../../privileges');
|
||||
|
||||
module.exports = {
|
||||
name: 'Give registered users signature privilege',
|
||||
timestamp: Date.UTC(2018, 1, 28),
|
||||
method: function (callback) {
|
||||
privileges.global.give(['signature'], 'registered-users', callback);
|
||||
},
|
||||
};
|
@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var posts = require('../../posts');
|
||||
|
||||
module.exports = {
|
||||
name: 'Refresh post-upload associations',
|
||||
timestamp: Date.UTC(2018, 3, 16),
|
||||
method: function (callback) {
|
||||
var progress = this.progress;
|
||||
|
||||
require('../../batch').processSortedSet('posts:pid', function (pids, next) {
|
||||
async.each(pids, function (pid, next) {
|
||||
posts.uploads.sync(pid, next);
|
||||
progress.incr();
|
||||
}, next);
|
||||
}, {
|
||||
progress: this.progress,
|
||||
}, callback);
|
||||
},
|
||||
};
|
@ -0,0 +1,50 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var path = require('path');
|
||||
var nconf = require('nconf');
|
||||
|
||||
var db = require('../database');
|
||||
var file = require('../file');
|
||||
var batch = require('../batch');
|
||||
|
||||
module.exports = function (User) {
|
||||
User.deleteUpload = function (callerUid, uid, uploadName, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
isUsersUpload: function (next) {
|
||||
db.isSortedSetMember('uid:' + callerUid + ':uploads', uploadName, next);
|
||||
},
|
||||
isAdminOrGlobalMod: function (next) {
|
||||
User.isAdminOrGlobalMod(callerUid, next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
if (!results.isAdminOrGlobalMod && !results.isUsersUpload) {
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
|
||||
file.delete(path.join(nconf.get('upload_path'), uploadName), next);
|
||||
},
|
||||
function (next) {
|
||||
db.sortedSetRemove('uid:' + uid + ':uploads', uploadName, next);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
User.collateUploads = function (uid, archive, callback) {
|
||||
batch.processSortedSet('uid:' + uid + ':uploads', function (files, next) {
|
||||
files.forEach(function (file) {
|
||||
archive.file(path.join(nconf.get('upload_path'), file), {
|
||||
name: path.basename(file),
|
||||
});
|
||||
});
|
||||
|
||||
setImmediate(next);
|
||||
}, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
};
|
@ -0,0 +1,23 @@
|
||||
<div class="form-group">
|
||||
<p class="lead">[[user:consent.lead]]</p>
|
||||
<p>[[user:consent.intro]]</p>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name="gdpr_agree_data" id="gdpr_agree_data"> <strong>[[register:gdpr_agree_data]]</strong>
|
||||
</label>
|
||||
</div>
|
||||
<p>
|
||||
[[user:consent.email_intro]]
|
||||
<!-- IF digestEnabled -->
|
||||
[[user:consent.digest_frequency, {digestFrequency}]]
|
||||
<!-- ELSE -->
|
||||
[[user:consent.digest_off]]
|
||||
<!-- END -->
|
||||
</p>
|
||||
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name="gdpr_agree_email" id="gdpr_agree_email"> <strong>[[register:gdpr_agree_email]]</strong>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue