ability to delete uploads from account page #6431
parent
8e822c7772
commit
b35bfb81ce
@ -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-url]');
|
||||
var url = el.attr('data-url');
|
||||
|
||||
socket.emit('user.deleteUpload', url, function (err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
el.remove();
|
||||
});
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
return AccountUploads;
|
||||
});
|
@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
|
||||
var db = require('../database');
|
||||
var file = require('../file');
|
||||
|
||||
module.exports = function (User) {
|
||||
User.deleteUpload = function (uid, url, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
isUsersUpload: function (next) {
|
||||
db.isSortedSetMember('uid:' + uid + ':uploads', url, next);
|
||||
},
|
||||
isAdminOrGlobalMod: function (next) {
|
||||
User.isAdminOrGlobalMod(uid, next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
if (!results.isAdminOrGlobalMod && !results.isUsersUpload) {
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
|
||||
file.delete(file.uploadUrlToPath(url), next);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue