diff --git a/app/modules/profile/profile.controller.coffee b/app/modules/profile/profile.controller.coffee index d2a0e7bb..558afb60 100644 --- a/app/modules/profile/profile.controller.coffee +++ b/app/modules/profile/profile.controller.coffee @@ -15,11 +15,16 @@ class ProfileController @userService .getUserByUserName(@routeParams.slug) .then (user) => - @.user = user - @.isCurrentUser = false - @._setMeta(@.user) + if !user.get('is_active') + @xhrError.notFound() + else + @.user = user + @.isCurrentUser = false + @._setMeta(@.user) + + return user .catch (xhr) => - @xhrError.response(xhr) + return @xhrError.response(xhr) else @.user = @currentUserService.getUser() diff --git a/app/modules/profile/profile.controller.spec.coffee b/app/modules/profile/profile.controller.spec.coffee index 72cf392c..26a4fdf9 100644 --- a/app/modules/profile/profile.controller.spec.coffee +++ b/app/modules/profile/profile.controller.spec.coffee @@ -43,7 +43,8 @@ describe "ProfileController", -> _mockXhrErrorService = () -> mocks.xhrErrorService = { - response: sinon.spy() + response: sinon.spy(), + notFound: sinon.spy() } provide.value "tgXhrErrorService", mocks.xhrErrorService @@ -76,9 +77,10 @@ describe "ProfileController", -> mocks.routeParams.slug = "user-slug" user = Immutable.fromJS({ - username: "username" - full_name_display: "full-name-display" - bio: "bio" + username: "username", + full_name_display: "full-name-display", + bio: "bio", + is_active: true }) mocks.translate @@ -121,9 +123,10 @@ describe "ProfileController", -> $scope = $rootScope.$new() user = Immutable.fromJS({ - username: "username" - full_name_display: "full-name-display" - bio: "bio" + username: "username", + full_name_display: "full-name-display", + bio: "bio", + is_active: true }) mocks.translate @@ -143,3 +146,24 @@ describe "ProfileController", -> expect(mocks.appMetaService.setAll.withArgs("user-profile-page-title", "bio")).to.be.calledOnce done() ) + + it "non-active user", (done) -> + $scope = $rootScope.$new() + + mocks.routeParams.slug = "user-slug" + + user = Immutable.fromJS({ + username: "username", + full_name_display: "full-name-display", + bio: "bio", + is_active: false + }) + + mocks.userService.getUserByUserName.withArgs(mocks.routeParams.slug).promise().resolve(user) + + ctrl = $controller("Profile") + + setTimeout ( -> + expect(mocks.xhrErrorService.notFound).to.be.calledOnce + done() + ) diff --git a/app/modules/services/xhrError.service.coffee b/app/modules/services/xhrError.service.coffee index 4b662977..3f8f2e5b 100644 --- a/app/modules/services/xhrError.service.coffee +++ b/app/modules/services/xhrError.service.coffee @@ -7,14 +7,21 @@ class xhrError extends taiga.Service constructor: (@q, @location, @navUrls) -> + notFound: () -> + @location.path(@navUrls.resolve("not-found")) + @location.replace() + + permissionDenied: () -> + @location.path(@navUrls.resolve("permission-denied")) + @location.replace() + response: (xhr) -> if xhr if xhr.status == 404 - @location.path(@navUrls.resolve("not-found")) - @location.replace() + @.notFound() + else if xhr.status == 403 - @location.path(@navUrls.resolve("permission-denied")) - @location.replace() + @.permissionDenied() return @q.reject(xhr)