mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #3000 from overleaf/jpa-skip-requests-for-anonymous-users
[misc] skip requests for anonymous users GitOrigin-RevId: a459fc623c171ccc146ee0d31e8faca0b719d096
This commit is contained in:
parent
307e9345bb
commit
023f1c254f
5 changed files with 29 additions and 7 deletions
|
@ -1,8 +1,13 @@
|
||||||
const Settings = require('settings-sharelatex')
|
const Settings = require('settings-sharelatex')
|
||||||
|
const AuthenticationController = require('../Authentication/AuthenticationController')
|
||||||
const SystemMessageManager = require('./SystemMessageManager')
|
const SystemMessageManager = require('./SystemMessageManager')
|
||||||
|
|
||||||
const ProjectController = {
|
const ProjectController = {
|
||||||
getMessages(req, res, next) {
|
getMessages(req, res, next) {
|
||||||
|
if (!AuthenticationController.isUserLoggedIn(req)) {
|
||||||
|
// gracefully handle requests from anonymous users
|
||||||
|
return res.json([])
|
||||||
|
}
|
||||||
SystemMessageManager.getMessages((err, messages) => {
|
SystemMessageManager.getMessages((err, messages) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
next(err)
|
next(err)
|
||||||
|
|
|
@ -107,11 +107,8 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
webRouter.get(
|
// .getMessages will generate an empty response for anonymous users.
|
||||||
'/system/messages',
|
webRouter.get('/system/messages', SystemMessageController.getMessages)
|
||||||
AuthenticationController.requireLogin(),
|
|
||||||
SystemMessageController.getMessages
|
|
||||||
)
|
|
||||||
|
|
||||||
webRouter.get(
|
webRouter.get(
|
||||||
'/user/settings',
|
'/user/settings',
|
||||||
|
|
|
@ -85,6 +85,12 @@ export default App.factory('metadata', function($http, ide) {
|
||||||
})
|
})
|
||||||
|
|
||||||
metadata.scheduleLoadDocMetaFromServer = function(docId) {
|
metadata.scheduleLoadDocMetaFromServer = function(docId) {
|
||||||
|
if (ide.$scope.permissionsLevel === 'readOnly') {
|
||||||
|
// The POST request is blocked for users without write permission.
|
||||||
|
// The user will not be able to consume the meta data for edits anyways.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// De-bounce loading labels with a timeout
|
// De-bounce loading labels with a timeout
|
||||||
const existingTimeout = debouncer[docId]
|
const existingTimeout = debouncer[docId]
|
||||||
|
|
||||||
|
|
|
@ -195,6 +195,11 @@ export default App.controller('SettingsController', function(
|
||||||
if (typeof oldRootDoc_id === 'undefined') {
|
if (typeof oldRootDoc_id === 'undefined') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if ($scope.permissionsLevel === 'readOnly') {
|
||||||
|
// The user is unauthorized to persist rootDoc changes.
|
||||||
|
// Use the new value for this very editor session only.
|
||||||
|
return
|
||||||
|
}
|
||||||
// otherwise only save changes, null values are allowed
|
// otherwise only save changes, null values are allowed
|
||||||
if (rootDoc_id !== oldRootDoc_id) {
|
if (rootDoc_id !== oldRootDoc_id) {
|
||||||
settings.saveProjectSettings({ rootDocId: rootDoc_id }).catch(() => {
|
settings.saveProjectSettings({ rootDocId: rootDoc_id }).catch(() => {
|
||||||
|
|
|
@ -57,7 +57,16 @@ App.controller('ShareProjectModalController', function(
|
||||||
)
|
)
|
||||||
|
|
||||||
$scope.autocompleteContacts = []
|
$scope.autocompleteContacts = []
|
||||||
$http.get('/user/contacts').then(function(response) {
|
if ($scope.isRestrictedTokenMember) {
|
||||||
|
// Restricted token members are users who join via a read-only link.
|
||||||
|
// They will not be able to invite any users, so skip the lookup of
|
||||||
|
// their contacts. This request would result in a 403 for anonymous
|
||||||
|
// users, which in turn would redirect them to the /login.
|
||||||
|
} else {
|
||||||
|
$http.get('/user/contacts').then(processContactsResponse)
|
||||||
|
}
|
||||||
|
|
||||||
|
function processContactsResponse(response) {
|
||||||
const { data } = response
|
const { data } = response
|
||||||
$scope.autocompleteContacts = data.contacts || []
|
$scope.autocompleteContacts = data.contacts || []
|
||||||
for (let contact of $scope.autocompleteContacts) {
|
for (let contact of $scope.autocompleteContacts) {
|
||||||
|
@ -77,7 +86,7 @@ App.controller('ShareProjectModalController', function(
|
||||||
contact.display = contact.name
|
contact.display = contact.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
const getCurrentMemberEmails = () =>
|
const getCurrentMemberEmails = () =>
|
||||||
($scope.project.members || []).map(u => u.email)
|
($scope.project.members || []).map(u => u.email)
|
||||||
|
|
Loading…
Reference in a new issue