Revert "complete v2 collabratec api"

This reverts commit 9c75b657c11f98e3f927dd01a422157f53a5672d.

GitOrigin-RevId: 378825fae46cef6f19c8f908a1d6cf9c837cd1d6
This commit is contained in:
Ersun Warncke 2019-05-13 11:35:10 -04:00 committed by sharelatex
parent 65cbfbaeae
commit 4189f2e6ec
5 changed files with 13 additions and 32 deletions

View file

@ -254,9 +254,9 @@ test_acceptance_modules_run:
test_acceptance_module_run: $(MODULE_MAKEFILES)
@if [ -e $(MODULE)/test/acceptance ]; then \
COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME)_$(MODULE) $(DOCKER_COMPOSE) down -v -t 0 \
&& cd $(MODULE) && COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME)_$(MODULE) $(MAKE) test_acceptance \
&& cd $(CURDIR) && COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME)_$(MODULE) $(DOCKER_COMPOSE) down -v -t 0; \
COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME)_$(MODULE) $(DOCKER_COMPOSE) down -v -t 0; \
cd $(MODULE) && COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME)_$(MODULE) $(MAKE) test_acceptance; \
cd $(CURDIR) && COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME)_$(MODULE) $(DOCKER_COMPOSE) down -v -t 0; \
fi
ci:

View file

@ -186,10 +186,7 @@ module.exports = AuthenticationController =
return doRequest
# access tokens might be associated with user stubs if the user is
# not yet migrated to v2. if api can work with user stubs then set
# allowUserStub true when adding middleware to route.
requireOauth: (allowUserStub=false) ->
requireOauth: () ->
# require this here because module may not be included in some versions
Oauth2Server = require "../../../../modules/oauth2-server/app/js/Oauth2Server"
return (req, res, next = (error) ->) ->
@ -203,7 +200,6 @@ module.exports = AuthenticationController =
return AuthenticationController._requireOauthV1Fallback req, res, next if err.code == 401
# send all other errors
return res.status(err.code).json({error: err.name, error_description: err.message})
return res.sendStatus 401 if token.user.constructor.modelName == "UserStub" and !allowUserStub
req.oauth =
access_token: token.accessToken
req.oauth_token = token
@ -225,6 +221,7 @@ module.exports = AuthenticationController =
return res.status(401).json({error: "invalid_token"}) unless user?
req.oauth =
access_token: body.access_token
user.collabratec_id = body.collabratec_customer_id unless user.collabratec_id?
req.oauth_user = user
next()

View file

@ -100,4 +100,4 @@ module.exports = V1SubscriptionManager =
if response.statusCode == 404
return callback new NotFoundError("v1 user not found: #{userId}")
else
return callback new Error("non-success code from v1: #{response.statusCode} #{options.method} #{options.url(v1Id)}")
return callback new Error("non-success code from v1: #{response.statusCode}")

View file

@ -5,20 +5,14 @@ UserUpdater = require "./UserUpdater"
_ = require "lodash"
module.exports = ThirdPartyIdentityManager =
getUser: (providerId, externalUserId, callback) ->
login: (providerId, externalUserId, externalData, callback) ->
return callback(new Error "invalid arguments") unless providerId? and externalUserId?
query = ThirdPartyIdentityManager._getUserQuery providerId, externalUserId
query = ThirdPartyIdentityManager._loginQuery providerId, externalUserId
User.findOne query, (err, user) ->
return callback err if err?
return callback(new Errors.ThirdPartyUserNotFoundError()) unless user
callback null, user
login: (providerId, externalUserId, externalData, callback) ->
ThirdPartyIdentityManager.getUser providerId, externalUserId, (err, user) ->
return callback err if err?
return callback(null, user) unless externalData
query = ThirdPartyIdentityManager._getUserQuery providerId, externalUserId
update = ThirdPartyIdentityManager._thirdPartyIdentifierUpdate user, providerId, externalUserId, externalData
update = ThirdPartyIdentityManager._loginUpdate user, providerId, externalUserId, externalData
User.findOneAndUpdate query, update, {new: true}, callback
# attempt to login normally but check for user stub if user not found
@ -26,15 +20,15 @@ module.exports = ThirdPartyIdentityManager =
ThirdPartyIdentityManager.login providerId, externalUserId, externalData, (err, user) ->
return callback null, user unless err?
return callback err unless err.name == "ThirdPartyUserNotFoundError"
query = ThirdPartyIdentityManager._getUserQuery providerId, externalUserId
query = ThirdPartyIdentityManager._loginQuery providerId, externalUserId
UserStub.findOne query, (err, userStub) ->
return callback err if err?
return callback(new Errors.ThirdPartyUserNotFoundError()) unless userStub
return callback(null, userStub) unless externalData
update = ThirdPartyIdentityManager._thirdPartyIdentifierUpdate userStub, providerId, externalUserId, externalData
update = ThirdPartyIdentityManager._loginUpdate userStub, providerId, externalUserId, externalData
UserStub.findOneAndUpdate query, update, {new: true}, callback
_getUserQuery: (providerId, externalUserId) ->
_loginQuery: (providerId, externalUserId) ->
externalUserId = externalUserId.toString()
providerId = providerId.toString()
query =
@ -42,7 +36,7 @@ module.exports = ThirdPartyIdentityManager =
"thirdPartyIdentifiers.providerId": providerId
return query
_thirdPartyIdentifierUpdate: (user, providerId, externalUserId, externalData) ->
_loginUpdate: (user, providerId, externalUserId, externalData) ->
providerId = providerId.toString()
# get third party identifier object from array
thirdPartyIdentifier = user.thirdPartyIdentifiers.find (tpi) ->
@ -80,12 +74,3 @@ module.exports = ThirdPartyIdentityManager =
update = $pull: thirdPartyIdentifiers:
providerId: providerId
UserUpdater.updateUser user_id, update, callback
# attempt to unlink user but unlink user stub if not linked to user
unlinkUserStub: (user_id, providerId, callback) ->
ThirdPartyIdentityManager.unlink user_id, providerId, (err, res) ->
return callback err if err?
return callback null, res if res.nModified == 1
update = $pull: thirdPartyIdentifiers:
providerId: providerId
UserStub.update { _id: user_id }, update, callback

View file

@ -409,7 +409,6 @@ describe "AuthenticationController", ->
@res.sendStatus = sinon.stub()
@res.send = sinon.stub()
@res.status = sinon.stub().returns(@res)
@res.sendStatus = sinon.stub()
@middleware = @AuthenticationController.requireOauth()
describe "when Oauth2Server authenticates", ->