fix issues in first commit

This commit is contained in:
Henrique Santos 2016-01-22 03:41:22 -02:00
parent 476eaa8b84
commit 2d11705837
3 changed files with 31 additions and 16 deletions

View file

@ -8,8 +8,8 @@ metrics = require('../../infrastructure/Metrics')
Project = require('../../models/Project').Project
User = require('../../models/User').User
TagsHandler = require("../Tags/TagsHandler")
NotificationsHandler = require("../Notifications/NotificationsHandler")
SubscriptionLocator = require("../Subscription/SubscriptionLocator")
NotificationsHandler = require("../Notifications/NotificationsHandler")
LimitationsManager = require("../Subscription/LimitationsManager")
_ = require("underscore")
Settings = require("settings-sharelatex")
@ -17,6 +17,8 @@ SecurityManager = require("../../managers/SecurityManager")
fs = require "fs"
InactiveProjectManager = require("../InactiveData/InactiveProjectManager")
ProjectUpdateHandler = require("./ProjectUpdateHandler")
ReferencesSearchHandler = require("../ReferencesSearch/ReferencesSearchHandler")
module.exports = ProjectController =
@ -173,15 +175,15 @@ module.exports = ProjectController =
return res.render("general/closed", {title:"updating_site"})
if req.session.user?
user_id = req.session.user._id
user_id = req.session.user._id
anonymous = false
else
anonymous = true
user_id = 'openUser'
project_id = req.params.Project_id
logger.log project_id:project_id, "loading editor"
async.parallel {
project: (cb)->
Project.findPopulatedById project_id, cb
@ -198,7 +200,7 @@ module.exports = ProjectController =
SubscriptionLocator.getUsersSubscription user_id, cb
activate: (cb)->
InactiveProjectManager.reactivateProjectIfRequired project_id, cb
markAsOpened: (cb)->
markAsOpened: (cb)->
#don't need to wait for this to complete
ProjectUpdateHandler.markAsOpened project_id, ->
cb()
@ -210,6 +212,7 @@ module.exports = ProjectController =
user = results.user
subscription = results.subscription
daysSinceLastUpdated = (new Date() - project.lastUpdated) /86400000
logger.log project_id:project_id, daysSinceLastUpdated:daysSinceLastUpdated, "got db results for loading editor"
@ -219,6 +222,10 @@ module.exports = ProjectController =
if subscription? and subscription.freeTrial? and subscription.freeTrial.expiresAt?
allowedFreeTrial = !!subscription.freeTrial.allowed || true
# HACK: don't do it for now
ReferencesSearchHandler.indexProjectReferences project, -> # don't need to wait on this
logger.log project_id:project_id, "rendering editor page"
res.render 'project/editor',
title: project.name
@ -315,5 +322,4 @@ do generateThemeList = () ->
for file in files
if file.slice(-2) == "js" and file.match(/^theme-/)
cleanName = file.slice(0,-3).slice(6)
THEME_LIST.push cleanName
THEME_LIST.push cleanName

View file

@ -38,6 +38,7 @@ RateLimiterMiddlewear = require('./Features/Security/RateLimiterMiddlewear')
RealTimeProxyRouter = require('./Features/RealTimeProxy/RealTimeProxyRouter')
InactiveProjectController = require("./Features/InactiveData/InactiveProjectController")
ContactRouter = require("./Features/Contacts/ContactRouter")
ReferencesSearchController = require('./Features/ReferencesSearch/ReferencesSearchController')
logger = require("logger-sharelatex")
_ = require("underscore")
@ -47,7 +48,7 @@ module.exports = class Router
if !Settings.allowPublicAccess
webRouter.all '*', AuthenticationController.requireGlobalLogin
webRouter.get '/login', UserPagesController.loginPage
AuthenticationController.addEndpointToLoginWhitelist '/login'
@ -68,18 +69,18 @@ module.exports = class Router
StaticPagesRouter.apply(webRouter, apiRouter)
RealTimeProxyRouter.apply(webRouter, apiRouter)
ContactRouter.apply(webRouter, apiRouter)
Modules.applyRouter(webRouter, apiRouter)
if Settings.enableSubscriptions
webRouter.get '/user/bonus', AuthenticationController.requireLogin(), ReferalMiddleware.getUserReferalId, ReferalController.bonus
webRouter.get '/blog', BlogController.getIndexPage
webRouter.get '/blog/*', BlogController.getPage
webRouter.get '/user/activate', UserPagesController.activateAccountPage
webRouter.get '/user/settings', AuthenticationController.requireLogin(), UserPagesController.settingsPage
webRouter.post '/user/settings', AuthenticationController.requireLogin(), UserController.updateUserSettings
webRouter.post '/user/password/update', AuthenticationController.requireLogin(), UserController.changePassword
@ -162,7 +163,7 @@ module.exports = class Router
apiRouter.post '/user/:user_id/update/*', AuthenticationController.httpAuth, TpdsController.mergeUpdate
apiRouter.delete '/user/:user_id/update/*', AuthenticationController.httpAuth, TpdsController.deleteUpdate
apiRouter.post '/project/:project_id/contents/*', AuthenticationController.httpAuth, TpdsController.updateProjectContents
apiRouter.delete '/project/:project_id/contents/*', AuthenticationController.httpAuth, TpdsController.deleteProjectContents
@ -171,9 +172,12 @@ module.exports = class Router
webRouter.get "/project/:Project_id/messages", SecurityManager.requestCanAccessProject, ChatController.getMessages
webRouter.post "/project/:Project_id/messages", SecurityManager.requestCanAccessProject, ChatController.sendMessage
webRouter.get /learn(\/.*)?/, WikiController.getPage
webRouter.post "/project/:Project_id/references", SecurityManager.requestCanAccessProject, ReferencesSearchController.indexFile
webRouter.get "/project/:Project_id/references/keys", SecurityManager.requestCanAccessProject, ReferencesSearchController.getKeys
#Admin Stuff
webRouter.get '/admin', SecurityManager.requestIsAdmin, AdminController.index
webRouter.get '/admin/user', SecurityManager.requestIsAdmin, (req, res)-> res.redirect("/admin/register") #this gets removed by admin-panel addon
@ -192,7 +196,7 @@ module.exports = class Router
apiRouter.get '/status', (req,res)->
res.send("websharelatex is up")
webRouter.get '/health_check', HealthCheckController.check
webRouter.get '/health_check/redis', HealthCheckController.checkRedis
@ -228,4 +232,4 @@ module.exports = class Router
logger.error err: req.body.error, meta: req.body.meta, "client side error"
res.sendStatus(204)
webRouter.get '*', ErrorController.notFound
webRouter.get '*', ErrorController.notFound

View file

@ -33,6 +33,8 @@ describe "ProjectController", ->
userHasSubscriptionOrIsGroupMember: sinon.stub()
@TagsHandler =
getAllTags: sinon.stub()
@NotificationsHandler =
getUserNotifications: sinon.stub()
@ProjectModel =
findAllUsersProjects: sinon.stub()
findPopulatedById: sinon.stub()
@ -60,6 +62,7 @@ describe "ProjectController", ->
"../Subscription/SubscriptionLocator": @SubscriptionLocator
"../Subscription/LimitationsManager": @LimitationsManager
"../Tags/TagsHandler":@TagsHandler
"../Notifications/NotificationsHandler":@NotificationsHandler
'../../models/Project': Project:@ProjectModel
"../../models/User":User:@UserModel
"../../managers/SecurityManager":@SecurityManager
@ -198,6 +201,7 @@ describe "ProjectController", ->
beforeEach ->
@tags = [{name:1, project_ids:["1","2","3"]}, {name:2, project_ids:["a","1"]}, {name:3, project_ids:["a", "b", "c", "d"]}]
@notifications = [{_id:'1',user_id:'2',templateKey:'3',messageOpts:'4',key:'5'}]
@projects = [{lastUpdated:1, _id:1, owner_ref: "user-1"}, {lastUpdated:2, _id:2, owner_ref: "user-2"}]
@collabertions = [{lastUpdated:5, _id:5, owner_ref: "user-1"}]
@readOnly = [{lastUpdated:3, _id:3, owner_ref: "user-1"}]
@ -213,6 +217,7 @@ describe "ProjectController", ->
@LimitationsManager.userHasSubscriptionOrIsGroupMember.callsArgWith(1, null, false)
@TagsHandler.getAllTags.callsArgWith(1, null, @tags, {})
@NotificationsHandler.getUserNotifications = sinon.stub().callsArgWith(1, null, @notifications, {})
@ProjectModel.findAllUsersProjects.callsArgWith(2, null, @projects, @collabertions, @readOnly)
it "should render the project/list page", (done)->