From 4189f2e6ec3f15631364c19d8c4b8bc7a4881369 Mon Sep 17 00:00:00 2001 From: Ersun Warncke Date: Mon, 13 May 2019 11:35:10 -0400 Subject: [PATCH] Revert "complete v2 collabratec api" This reverts commit 9c75b657c11f98e3f927dd01a422157f53a5672d. GitOrigin-RevId: 378825fae46cef6f19c8f908a1d6cf9c837cd1d6 --- services/web/Makefile | 6 ++-- .../AuthenticationController.coffee | 7 ++--- .../Subscription/V1SubscriptionManager.coffee | 2 +- .../User/ThirdPartyIdentityManager.coffee | 29 +++++-------------- .../AuthenticationControllerTests.coffee | 1 - 5 files changed, 13 insertions(+), 32 deletions(-) diff --git a/services/web/Makefile b/services/web/Makefile index 489ff125d0..a4d3bbe9bb 100644 --- a/services/web/Makefile +++ b/services/web/Makefile @@ -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: diff --git a/services/web/app/coffee/Features/Authentication/AuthenticationController.coffee b/services/web/app/coffee/Features/Authentication/AuthenticationController.coffee index 408ae43400..de29316df5 100644 --- a/services/web/app/coffee/Features/Authentication/AuthenticationController.coffee +++ b/services/web/app/coffee/Features/Authentication/AuthenticationController.coffee @@ -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() diff --git a/services/web/app/coffee/Features/Subscription/V1SubscriptionManager.coffee b/services/web/app/coffee/Features/Subscription/V1SubscriptionManager.coffee index 10c1a7983b..0ebb3317a9 100644 --- a/services/web/app/coffee/Features/Subscription/V1SubscriptionManager.coffee +++ b/services/web/app/coffee/Features/Subscription/V1SubscriptionManager.coffee @@ -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}") diff --git a/services/web/app/coffee/Features/User/ThirdPartyIdentityManager.coffee b/services/web/app/coffee/Features/User/ThirdPartyIdentityManager.coffee index 9e5ad1ca2d..30686fd2bf 100644 --- a/services/web/app/coffee/Features/User/ThirdPartyIdentityManager.coffee +++ b/services/web/app/coffee/Features/User/ThirdPartyIdentityManager.coffee @@ -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 diff --git a/services/web/test/unit/coffee/Authentication/AuthenticationControllerTests.coffee b/services/web/test/unit/coffee/Authentication/AuthenticationControllerTests.coffee index 70e667af58..4c9502fb58 100644 --- a/services/web/test/unit/coffee/Authentication/AuthenticationControllerTests.coffee +++ b/services/web/test/unit/coffee/Authentication/AuthenticationControllerTests.coffee @@ -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", ->