mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
decaffeinate: Convert coffee files to JS
This commit is contained in:
parent
d152a79810
commit
efd16d99d6
4 changed files with 899 additions and 677 deletions
|
@ -1,216 +1,311 @@
|
|||
coffee = require("coffee-script")
|
||||
fs = require "fs"
|
||||
spawn = require("child_process").spawn
|
||||
exec = require("child_process").exec
|
||||
rimraf = require "rimraf"
|
||||
Path = require "path"
|
||||
semver = require "semver"
|
||||
knox = require "knox"
|
||||
crypto = require "crypto"
|
||||
async = require "async"
|
||||
settings = require("settings-sharelatex")
|
||||
_ = require("underscore")
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS101: Remove unnecessary use of Array.from
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS103: Rewrite code to no longer use __guard__, or convert again using --optional-chaining
|
||||
* DS205: Consider reworking code to avoid use of IIFEs
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const coffee = require("coffee-script");
|
||||
const fs = require("fs");
|
||||
const {
|
||||
spawn
|
||||
} = require("child_process");
|
||||
const {
|
||||
exec
|
||||
} = require("child_process");
|
||||
const rimraf = require("rimraf");
|
||||
const Path = require("path");
|
||||
const semver = require("semver");
|
||||
const knox = require("knox");
|
||||
const crypto = require("crypto");
|
||||
const async = require("async");
|
||||
const settings = require("settings-sharelatex");
|
||||
const _ = require("underscore");
|
||||
|
||||
|
||||
SERVICES = require("./config/services")
|
||||
const SERVICES = require("./config/services");
|
||||
|
||||
module.exports = (grunt) ->
|
||||
grunt.loadNpmTasks 'grunt-bunyan'
|
||||
grunt.loadNpmTasks 'grunt-execute'
|
||||
grunt.loadNpmTasks 'grunt-available-tasks'
|
||||
grunt.loadNpmTasks 'grunt-concurrent'
|
||||
grunt.loadNpmTasks "grunt-contrib-coffee"
|
||||
grunt.loadNpmTasks "grunt-shell"
|
||||
module.exports = function(grunt) {
|
||||
let Helpers;
|
||||
let service;
|
||||
grunt.loadNpmTasks('grunt-bunyan');
|
||||
grunt.loadNpmTasks('grunt-execute');
|
||||
grunt.loadNpmTasks('grunt-available-tasks');
|
||||
grunt.loadNpmTasks('grunt-concurrent');
|
||||
grunt.loadNpmTasks("grunt-contrib-coffee");
|
||||
grunt.loadNpmTasks("grunt-shell");
|
||||
|
||||
grunt.task.loadTasks "./tasks"
|
||||
grunt.task.loadTasks("./tasks");
|
||||
|
||||
execute = {}
|
||||
for service in SERVICES
|
||||
const execute = {};
|
||||
for (service of Array.from(SERVICES)) {
|
||||
execute[service.name] =
|
||||
src: "#{service.name}/app.js"
|
||||
{src: `${service.name}/app.js`};
|
||||
}
|
||||
|
||||
grunt.initConfig
|
||||
execute: execute
|
||||
grunt.initConfig({
|
||||
execute,
|
||||
|
||||
concurrent:
|
||||
all:
|
||||
tasks: ("run:#{service.name}" for service in SERVICES)
|
||||
options:
|
||||
limit: SERVICES.length
|
||||
concurrent: {
|
||||
all: {
|
||||
tasks: (((() => {
|
||||
const result = [];
|
||||
for (service of Array.from(SERVICES)) { result.push(`run:${service.name}`);
|
||||
}
|
||||
return result;
|
||||
})())),
|
||||
options: {
|
||||
limit: SERVICES.length,
|
||||
logConcurrentOutput: true
|
||||
|
||||
availabletasks:
|
||||
tasks:
|
||||
options:
|
||||
availabletasks: {
|
||||
tasks: {
|
||||
options: {
|
||||
filter: 'exclude',
|
||||
tasks: [
|
||||
'concurrent'
|
||||
'execute'
|
||||
'bunyan'
|
||||
'concurrent',
|
||||
'execute',
|
||||
'bunyan',
|
||||
'availabletasks'
|
||||
]
|
||||
groups:
|
||||
],
|
||||
groups: {
|
||||
"Run tasks": [
|
||||
"run"
|
||||
"run:all"
|
||||
"run",
|
||||
"run:all",
|
||||
"default"
|
||||
].concat ("run:#{service.name}" for service in SERVICES)
|
||||
].concat(((() => {
|
||||
const result1 = [];
|
||||
for (service of Array.from(SERVICES)) { result1.push(`run:${service.name}`);
|
||||
}
|
||||
return result1;
|
||||
})())),
|
||||
"Misc": [
|
||||
"help"
|
||||
]
|
||||
"Install tasks": ("install:#{service.name}" for service in SERVICES).concat(["install:all", "install"])
|
||||
"Update tasks": ("update:#{service.name}" for service in SERVICES).concat(["update:all", "update"])
|
||||
],
|
||||
"Install tasks": ((() => {
|
||||
const result2 = [];
|
||||
for (service of Array.from(SERVICES)) { result2.push(`install:${service.name}`);
|
||||
}
|
||||
return result2;
|
||||
})()).concat(["install:all", "install"]),
|
||||
"Update tasks": ((() => {
|
||||
const result3 = [];
|
||||
for (service of Array.from(SERVICES)) { result3.push(`update:${service.name}`);
|
||||
}
|
||||
return result3;
|
||||
})()).concat(["update:all", "update"]),
|
||||
"Checks": ["check", "check:redis", "check:latexmk", "check:s3", "check:make", "check:mongo"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}});
|
||||
|
||||
for service in SERVICES
|
||||
do (service) ->
|
||||
grunt.registerTask "install:#{service.name}", "Download and set up the #{service.name} service", () ->
|
||||
done = @async()
|
||||
Helpers.installService(service, done)
|
||||
for (service of Array.from(SERVICES)) {
|
||||
((service => grunt.registerTask(`install:${service.name}`, `Download and set up the ${service.name} service`, function() {
|
||||
const done = this.async();
|
||||
return Helpers.installService(service, done);
|
||||
})))(service);
|
||||
}
|
||||
|
||||
|
||||
|
||||
grunt.registerTask 'install:all', "Download and set up all ShareLaTeX services",
|
||||
grunt.registerTask('install:all', "Download and set up all ShareLaTeX services",
|
||||
[].concat(
|
||||
("install:#{service.name}" for service in SERVICES)
|
||||
((() => {
|
||||
const result4 = [];
|
||||
for (service of Array.from(SERVICES)) { result4.push(`install:${service.name}`);
|
||||
}
|
||||
return result4;
|
||||
})())
|
||||
).concat(['postinstall'])
|
||||
);
|
||||
|
||||
grunt.registerTask 'install', 'install:all'
|
||||
grunt.registerTask 'postinstall', 'Explain postinstall steps', () ->
|
||||
Helpers.postinstallMessage @async()
|
||||
grunt.registerTask('install', 'install:all');
|
||||
grunt.registerTask('postinstall', 'Explain postinstall steps', function() {
|
||||
return Helpers.postinstallMessage(this.async());
|
||||
});
|
||||
|
||||
grunt.registerTask 'update:all', "Checkout and update all ShareLaTeX services",
|
||||
grunt.registerTask('update:all', "Checkout and update all ShareLaTeX services",
|
||||
["check:make"].concat(
|
||||
("update:#{service.name}" for service in SERVICES)
|
||||
((() => {
|
||||
const result5 = [];
|
||||
for (service of Array.from(SERVICES)) { result5.push(`update:${service.name}`);
|
||||
}
|
||||
return result5;
|
||||
})())
|
||||
)
|
||||
grunt.registerTask 'update', 'update:all'
|
||||
grunt.registerTask 'run', "Run all of the sharelatex processes", ['concurrent:all']
|
||||
grunt.registerTask 'run:all', 'run'
|
||||
);
|
||||
grunt.registerTask('update', 'update:all');
|
||||
grunt.registerTask('run', "Run all of the sharelatex processes", ['concurrent:all']);
|
||||
grunt.registerTask('run:all', 'run');
|
||||
|
||||
grunt.registerTask 'help', 'Display this help list', 'availabletasks'
|
||||
grunt.registerTask 'default', 'run'
|
||||
grunt.registerTask('help', 'Display this help list', 'availabletasks');
|
||||
grunt.registerTask('default', 'run');
|
||||
|
||||
grunt.registerTask "check:redis", "Check that redis is installed and running", () ->
|
||||
Helpers.checkRedisConnect @async()
|
||||
grunt.registerTask("check:redis", "Check that redis is installed and running", function() {
|
||||
return Helpers.checkRedisConnect(this.async());
|
||||
});
|
||||
|
||||
grunt.registerTask "check:mongo", "Check that mongo is installed", () ->
|
||||
Helpers.checkMongoConnect @async()
|
||||
grunt.registerTask("check:mongo", "Check that mongo is installed", function() {
|
||||
return Helpers.checkMongoConnect(this.async());
|
||||
});
|
||||
|
||||
grunt.registerTask "check", "Check that you have the required dependencies installed", ["check:redis", "check:mongo", "check:make"]
|
||||
grunt.registerTask("check", "Check that you have the required dependencies installed", ["check:redis", "check:mongo", "check:make"]);
|
||||
|
||||
grunt.registerTask "check:make", "Check that make is installed", () ->
|
||||
Helpers.checkMake @async()
|
||||
grunt.registerTask("check:make", "Check that make is installed", function() {
|
||||
return Helpers.checkMake(this.async());
|
||||
});
|
||||
|
||||
|
||||
Helpers =
|
||||
installService: (service, callback = (error) ->) ->
|
||||
console.log "Installing #{service.name}"
|
||||
Helpers.cloneGitRepo service, (error) ->
|
||||
if error?
|
||||
callback(error)
|
||||
else
|
||||
callback()
|
||||
return Helpers = {
|
||||
installService(service, callback) {
|
||||
if (callback == null) { callback = function(error) {}; }
|
||||
console.log(`Installing ${service.name}`);
|
||||
return Helpers.cloneGitRepo(service, function(error) {
|
||||
if (error != null) {
|
||||
return callback(error);
|
||||
} else {
|
||||
return callback();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
cloneGitRepo: (service, callback = (error) ->) ->
|
||||
repo_src = service.repo
|
||||
dir = service.name
|
||||
if !fs.existsSync(dir)
|
||||
proc = spawn "git", [
|
||||
cloneGitRepo(service, callback) {
|
||||
if (callback == null) { callback = function(error) {}; }
|
||||
const repo_src = service.repo;
|
||||
const dir = service.name;
|
||||
if (!fs.existsSync(dir)) {
|
||||
const proc = spawn("git", [
|
||||
"clone",
|
||||
repo_src,
|
||||
dir
|
||||
], stdio: "inherit"
|
||||
proc.on "close", () ->
|
||||
Helpers.checkoutVersion service, callback
|
||||
else
|
||||
console.log "#{dir} already installed, skipping."
|
||||
callback()
|
||||
], {stdio: "inherit"});
|
||||
return proc.on("close", () => Helpers.checkoutVersion(service, callback));
|
||||
} else {
|
||||
console.log(`${dir} already installed, skipping.`);
|
||||
return callback();
|
||||
}
|
||||
},
|
||||
|
||||
checkoutVersion: (service, callback = (error) ->) ->
|
||||
dir = service.name
|
||||
grunt.log.write "checking out #{service.name} #{service.version}"
|
||||
proc = spawn "git", ["checkout", service.version], stdio: "inherit", cwd: dir
|
||||
proc.on "close", () ->
|
||||
callback()
|
||||
checkoutVersion(service, callback) {
|
||||
if (callback == null) { callback = function(error) {}; }
|
||||
const dir = service.name;
|
||||
grunt.log.write(`checking out ${service.name} ${service.version}`);
|
||||
const proc = spawn("git", ["checkout", service.version], {stdio: "inherit", cwd: dir});
|
||||
return proc.on("close", () => callback());
|
||||
},
|
||||
|
||||
postinstallMessage: (callback = (error) ->) ->
|
||||
grunt.log.write """
|
||||
Services cloned:
|
||||
#{service.name for service in SERVICES}
|
||||
To install services run:
|
||||
postinstallMessage(callback) {
|
||||
if (callback == null) { callback = function(error) {}; }
|
||||
grunt.log.write(`\
|
||||
Services cloned:
|
||||
${(() => {
|
||||
const result6 = [];
|
||||
for (service of Array.from(SERVICES)) { result6.push(service.name);
|
||||
}
|
||||
return result6;
|
||||
})()}
|
||||
To install services run:
|
||||
$ source bin/install-services
|
||||
This will install the required node versions and run `npm install` for each service.
|
||||
See https://github.com/sharelatex/sharelatex/pull/549 for more info.
|
||||
"""
|
||||
callback()
|
||||
This will install the required node versions and run \`npm install\` for each service.
|
||||
See https://github.com/sharelatex/sharelatex/pull/549 for more info.\
|
||||
`
|
||||
);
|
||||
return callback();
|
||||
},
|
||||
|
||||
checkMake: (callback = (error) ->) ->
|
||||
grunt.log.write "Checking make is installed... "
|
||||
exec "make --version", (error, stdout, stderr) ->
|
||||
if error? and error.message.match("not found")
|
||||
grunt.log.error "FAIL."
|
||||
grunt.log.errorlns """
|
||||
Either make is not installed or is not in your path.
|
||||
checkMake(callback) {
|
||||
if (callback == null) { callback = function(error) {}; }
|
||||
grunt.log.write("Checking make is installed... ");
|
||||
return exec("make --version", function(error, stdout, stderr) {
|
||||
if ((error != null) && error.message.match("not found")) {
|
||||
grunt.log.error("FAIL.");
|
||||
grunt.log.errorlns(`\
|
||||
Either make is not installed or is not in your path.
|
||||
|
||||
On Ubuntu you can install make with:
|
||||
On Ubuntu you can install make with:
|
||||
|
||||
sudo apt-get install build-essential
|
||||
\
|
||||
`
|
||||
);
|
||||
return callback(error);
|
||||
} else if (error != null) {
|
||||
return callback(error);
|
||||
} else {
|
||||
grunt.log.write("OK.");
|
||||
return callback();
|
||||
}
|
||||
});
|
||||
},
|
||||
checkMongoConnect(callback) {
|
||||
if (callback == null) { callback = function(error) {}; }
|
||||
grunt.log.write("Checking can connect to mongo");
|
||||
const mongojs = require("mongojs");
|
||||
const db = mongojs(settings.mongo.url, ["tags"]);
|
||||
db.runCommand({ ping: 1 }, function(err, res) {
|
||||
if (!err && res.ok) {
|
||||
grunt.log.write("OK.");
|
||||
}
|
||||
return callback();
|
||||
});
|
||||
return db.on('error', function(err){
|
||||
err = "Can not connect to mongodb";
|
||||
grunt.log.error("FAIL.");
|
||||
grunt.log.errorlns(`\
|
||||
!!!!!!!!!!!!!! MONGO ERROR !!!!!!!!!!!!!!
|
||||
|
||||
"""
|
||||
return callback(error)
|
||||
else if error?
|
||||
return callback(error)
|
||||
else
|
||||
grunt.log.write "OK."
|
||||
return callback()
|
||||
checkMongoConnect: (callback = (error) ->) ->
|
||||
grunt.log.write "Checking can connect to mongo"
|
||||
mongojs = require("mongojs")
|
||||
db = mongojs(settings.mongo.url, ["tags"])
|
||||
db.runCommand { ping: 1 }, (err, res) ->
|
||||
if !err and res.ok
|
||||
grunt.log.write "OK."
|
||||
return callback()
|
||||
db.on 'error', (err)->
|
||||
err = "Can not connect to mongodb"
|
||||
grunt.log.error "FAIL."
|
||||
grunt.log.errorlns """
|
||||
!!!!!!!!!!!!!! MONGO ERROR !!!!!!!!!!!!!!
|
||||
ShareLaTeX can not talk to the mongodb instance
|
||||
|
||||
ShareLaTeX can not talk to the mongodb instance
|
||||
Check the mongodb instance is running and accessible on env var SHARELATEX_MONGO_URL
|
||||
|
||||
Check the mongodb instance is running and accessible on env var SHARELATEX_MONGO_URL
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
|
||||
`
|
||||
);
|
||||
throw new Error("Can not connect to Mongodb");
|
||||
return callback(err);
|
||||
});
|
||||
},
|
||||
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
"""
|
||||
throw new Error("Can not connect to Mongodb")
|
||||
return callback(err)
|
||||
checkRedisConnect(callback) {
|
||||
if (callback == null) { callback = function(error) {}; }
|
||||
grunt.log.write("Checking can connect to redis\n");
|
||||
const rclient = require("redis").createClient(settings.redis.web);
|
||||
|
||||
checkRedisConnect: (callback = (error) ->) ->
|
||||
grunt.log.write "Checking can connect to redis\n"
|
||||
rclient = require("redis").createClient(settings.redis.web)
|
||||
rclient.ping(function(err, res) {
|
||||
if ((err == null)) {
|
||||
grunt.log.write("OK.");
|
||||
} else {
|
||||
throw new Error("Can not connect to redis");
|
||||
}
|
||||
return callback();
|
||||
});
|
||||
const errorHandler = _.once(function(err){
|
||||
err = "Can not connect to redis";
|
||||
grunt.log.error("FAIL.");
|
||||
grunt.log.errorlns(`\
|
||||
!!!!!!!!!!!!!! REDIS ERROR !!!!!!!!!!!!!!
|
||||
|
||||
rclient.ping (err, res) ->
|
||||
if !err?
|
||||
grunt.log.write "OK."
|
||||
else
|
||||
throw new Error("Can not connect to redis")
|
||||
return callback()
|
||||
errorHandler = _.once (err)->
|
||||
err = "Can not connect to redis"
|
||||
grunt.log.error "FAIL."
|
||||
grunt.log.errorlns """
|
||||
!!!!!!!!!!!!!! REDIS ERROR !!!!!!!!!!!!!!
|
||||
ShareLaTeX can not talk to the redis instance
|
||||
|
||||
ShareLaTeX can not talk to the redis instance
|
||||
Check the redis instance is running and accessible on env var SHARELATEX_REDIS_HOST
|
||||
|
||||
Check the redis instance is running and accessible on env var SHARELATEX_REDIS_HOST
|
||||
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
"""
|
||||
throw new Error("Can not connect to redis")
|
||||
return callback(err)
|
||||
rclient.on 'error', errorHandler
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
|
||||
`
|
||||
);
|
||||
throw new Error("Can not connect to redis");
|
||||
return callback(err);
|
||||
});
|
||||
return rclient.on('error', errorHandler);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
function __guard__(value, transform) {
|
||||
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,60 +1,79 @@
|
|||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
|
||||
module.exports = (grunt) ->
|
||||
module.exports = function(grunt) {
|
||||
|
||||
grunt.registerTask 'user:create-admin', "Create a user with the given email address and make them an admin. Update in place if the user already exists. Usage: grunt user:create-admin --email joe@example.com", () ->
|
||||
done = @async()
|
||||
email = grunt.option("email")
|
||||
if !email?
|
||||
console.error "Usage: grunt user:create-admin --email=joe@example.com"
|
||||
process.exit(1)
|
||||
grunt.registerTask('user:create-admin', "Create a user with the given email address and make them an admin. Update in place if the user already exists. Usage: grunt user:create-admin --email joe@example.com", function() {
|
||||
const done = this.async();
|
||||
const email = grunt.option("email");
|
||||
if ((email == null)) {
|
||||
console.error("Usage: grunt user:create-admin --email=joe@example.com");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
settings = require "settings-sharelatex"
|
||||
mongodb = require "../web/app/src/infrastructure/mongodb"
|
||||
UserRegistrationHandler = require "../web/app/src/Features/User/UserRegistrationHandler"
|
||||
OneTimeTokenHandler = require "../web/app/src/Features/Security/OneTimeTokenHandler"
|
||||
mongodb.waitForDb().then () ->
|
||||
UserRegistrationHandler.registerNewUser {
|
||||
email: email
|
||||
const settings = require("settings-sharelatex");
|
||||
const mongodb = require("../web/app/src/infrastructure/mongodb");
|
||||
const UserRegistrationHandler = require("../web/app/src/Features/User/UserRegistrationHandler");
|
||||
const OneTimeTokenHandler = require("../web/app/src/Features/Security/OneTimeTokenHandler");
|
||||
return mongodb.waitForDb().then(() => UserRegistrationHandler.registerNewUser({
|
||||
email,
|
||||
password: require("crypto").randomBytes(32).toString("hex")
|
||||
}, (error, user) ->
|
||||
if error? and error?.message != "EmailAlreadyRegistered"
|
||||
throw error
|
||||
user.isAdmin = true
|
||||
user.save (error) ->
|
||||
throw error if error?
|
||||
ONE_WEEK = 7 * 24 * 60 * 60 # seconds
|
||||
OneTimeTokenHandler.getNewToken "password", { expiresIn: ONE_WEEK, email:user.email, user_id: user._id.toString() }, (err, token)->
|
||||
return next(err) if err?
|
||||
}, function(error, user) {
|
||||
if ((error != null) && ((error != null ? error.message : undefined) !== "EmailAlreadyRegistered")) {
|
||||
throw error;
|
||||
}
|
||||
user.isAdmin = true;
|
||||
return user.save(function(error) {
|
||||
if (error != null) { throw error; }
|
||||
const ONE_WEEK = 7 * 24 * 60 * 60; // seconds
|
||||
return OneTimeTokenHandler.getNewToken("password", { expiresIn: ONE_WEEK, email:user.email, user_id: user._id.toString() }, function(err, token){
|
||||
if (err != null) { return next(err); }
|
||||
|
||||
console.log ""
|
||||
console.log """
|
||||
Successfully created #{email} as an admin user.
|
||||
console.log("");
|
||||
console.log(`\
|
||||
Successfully created ${email} as an admin user.
|
||||
|
||||
Please visit the following URL to set a password for #{email} and log in:
|
||||
Please visit the following URL to set a password for ${email} and log in:
|
||||
|
||||
#{settings.siteUrl}/user/password/set?passwordResetToken=#{token}
|
||||
${settings.siteUrl}/user/password/set?passwordResetToken=${token}
|
||||
\
|
||||
`
|
||||
);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
"""
|
||||
done()
|
||||
|
||||
grunt.registerTask 'user:delete', "deletes a user and all their data, Usage: grunt user:delete --email joe@example.com", () ->
|
||||
done = @async()
|
||||
email = grunt.option("email")
|
||||
if !email?
|
||||
console.error "Usage: grunt user:delete --email=joe@example.com"
|
||||
process.exit(1)
|
||||
settings = require "settings-sharelatex"
|
||||
mongodb = require "../web/app/src/infrastructure/mongodb"
|
||||
UserGetter = require "../web/app/src/Features/User/UserGetter"
|
||||
UserDeleter = require "../web/app/src/Features/User/UserDeleter"
|
||||
mongodb.waitForDb().then () ->
|
||||
UserGetter.getUser email:email, (error, user) ->
|
||||
if error?
|
||||
throw error
|
||||
if !user?
|
||||
console.log("user #{email} not in database, potentially already deleted")
|
||||
return done()
|
||||
UserDeleter.deleteUser user._id, (err)->
|
||||
if err?
|
||||
throw err
|
||||
done()
|
||||
return grunt.registerTask('user:delete', "deletes a user and all their data, Usage: grunt user:delete --email joe@example.com", function() {
|
||||
const done = this.async();
|
||||
const email = grunt.option("email");
|
||||
if ((email == null)) {
|
||||
console.error("Usage: grunt user:delete --email=joe@example.com");
|
||||
process.exit(1);
|
||||
}
|
||||
const settings = require("settings-sharelatex");
|
||||
const mongodb = require("../web/app/src/infrastructure/mongodb");
|
||||
const UserGetter = require("../web/app/src/Features/User/UserGetter");
|
||||
const UserDeleter = require("../web/app/src/Features/User/UserDeleter");
|
||||
return mongodb.waitForDb().then(() => UserGetter.getUser({email}, function(error, user) {
|
||||
if (error != null) {
|
||||
throw error;
|
||||
}
|
||||
if ((user == null)) {
|
||||
console.log(`user ${email} not in database, potentially already deleted`);
|
||||
return done();
|
||||
}
|
||||
return UserDeleter.deleteUser(user._id, function(err){
|
||||
if (err != null) {
|
||||
throw err;
|
||||
}
|
||||
return done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
# require("coffee-script")
|
||||
// require("coffee-script")
|
||||
|
||||
# fs = require("fs")
|
||||
# _ = require("underscore")
|
||||
// fs = require("fs")
|
||||
// _ = require("underscore")
|
||||
|
||||
# if not process.argv[2]
|
||||
# console.log "Usage: coffee project_size.coffee user_files_path"
|
||||
# else
|
||||
# dirPath = process.argv[2]
|
||||
# if not fs.lstatSync(dirPath).isDirectory()
|
||||
# console.log dirPath + " directory not exist"
|
||||
# else
|
||||
# fs.readdir dirPath, (err, files)->
|
||||
# projects = []
|
||||
# files.forEach (file)->
|
||||
# project_id = file.split("_")[0]
|
||||
# if !projects[project_id]
|
||||
# projects[project_id] = 0
|
||||
# projects[project_id] += fs.lstatSync(dirPath+"/"+file).size
|
||||
// if not process.argv[2]
|
||||
// console.log "Usage: coffee project_size.coffee user_files_path"
|
||||
// else
|
||||
// dirPath = process.argv[2]
|
||||
// if not fs.lstatSync(dirPath).isDirectory()
|
||||
// console.log dirPath + " directory not exist"
|
||||
// else
|
||||
// fs.readdir dirPath, (err, files)->
|
||||
// projects = []
|
||||
// files.forEach (file)->
|
||||
// project_id = file.split("_")[0]
|
||||
// if !projects[project_id]
|
||||
// projects[project_id] = 0
|
||||
// projects[project_id] += fs.lstatSync(dirPath+"/"+file).size
|
||||
|
||||
# ids = _.keys projects
|
||||
# console.log "project \t size"
|
||||
# ids.forEach (id)->
|
||||
# console.log id + "\t" + projects[id]
|
||||
// ids = _.keys projects
|
||||
// console.log "project \t size"
|
||||
// ids.forEach (id)->
|
||||
// console.log id + "\t" + projects[id]
|
||||
|
|
Loading…
Reference in a new issue