2017-05-10 05:05:48 -04:00
|
|
|
RedisWrapper = require('../../infrastructure/RedisWrapper')
|
|
|
|
rclient = RedisWrapper.client('sudomode')
|
|
|
|
logger = require('logger-sharelatex')
|
|
|
|
|
|
|
|
|
2017-05-10 06:35:47 -04:00
|
|
|
TIMEOUT_IN_SECONDS = 60 * 60
|
2017-05-10 05:05:48 -04:00
|
|
|
|
|
|
|
|
|
|
|
module.exports = SudoModeHandler =
|
|
|
|
|
|
|
|
_buildKey: (userId) ->
|
|
|
|
"SudoMode:{#{userId}}"
|
|
|
|
|
|
|
|
activateSudoMode: (userId, callback=(err)->) ->
|
|
|
|
if !userId?
|
2017-05-10 06:36:05 -04:00
|
|
|
return callback(new Error('[SudoMode] user must be supplied'))
|
2017-05-10 05:05:48 -04:00
|
|
|
duration = TIMEOUT_IN_SECONDS
|
|
|
|
logger.log {userId, duration}, "[SudoMode] activating sudo mode for user"
|
|
|
|
rclient.set SudoModeHandler._buildKey(userId), '1', 'EX', duration, callback
|
|
|
|
|
|
|
|
isSudoModeActive: (userId, callback=(err, isActive)->) ->
|
|
|
|
if !userId?
|
2017-05-10 06:36:05 -04:00
|
|
|
return callback(new Error('[SudoMode] user must be supplied'))
|
2017-05-10 05:05:48 -04:00
|
|
|
rclient.get SudoModeHandler._buildKey(userId), (err, result) ->
|
|
|
|
if err?
|
|
|
|
return callback(err)
|
|
|
|
callback(null, result == '1')
|