diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f05dcd6..1da0e824 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Features - Show a confirmation notice when you exit edit mode by pressing ESC in the markdown inputs. - Add the tribe button to link stories from tree.taiga.io with gigs in tribe.taiga.io. +- Errors (not found, server error, permissions and blocked project) don't change the current url. ### Misc - Lots of small and not so small bugfixes. diff --git a/app/coffee/app.coffee b/app/coffee/app.coffee index ac0d17ed..5a0b7370 100644 --- a/app/coffee/app.coffee +++ b/app/coffee/app.coffee @@ -443,7 +443,7 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven $routeProvider.when("/permission-denied", {templateUrl: "error/permission-denied.html"}) - $routeProvider.otherwise({redirectTo: "/not-found"}) + $routeProvider.otherwise({templateUrl: "error/not-found.html"}) $locationProvider.html5Mode({enabled: true, requireBase: false}) defaultHeaders = { @@ -465,12 +465,12 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven $tgEventsProvider.setSessionId(taiga.sessionId) # Add next param when user try to access to a secction need auth permissions. - authHttpIntercept = ($q, $location, $navUrls, $lightboxService) -> + authHttpIntercept = ($q, $location, $navUrls, $lightboxService, errorHandlingService) -> httpResponseError = (response) -> if response.status == 0 || (response.status == -1 && !response.config.cancelable) $lightboxService.closeAll() - $location.path($navUrls.resolve("error")) - $location.replace() + + errorHandlingService.error() else if response.status == 401 and $location.url().indexOf('/login') == -1 nextUrl = encodeURIComponent($location.url()) $location.url($navUrls.resolve("login")).search("next=#{nextUrl}") @@ -481,7 +481,7 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven responseError: httpResponseError } - $provide.factory("authHttpIntercept", ["$q", "$location", "$tgNavUrls", "lightboxService", + $provide.factory("authHttpIntercept", ["$q", "$location", "$tgNavUrls", "lightboxService", "tgErrorHandlingService", authHttpIntercept]) $httpProvider.interceptors.push("authHttpIntercept") @@ -536,7 +536,7 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven $httpProvider.interceptors.push("versionCheckHttpIntercept") - blockingIntercept = ($q, $routeParams, $location, $navUrls) -> + blockingIntercept = ($q, $routeParams, $location, $navUrls, errorHandlingService) -> # API calls can return blocked elements and in that situation the user will be redirected # to the blocked project page # This can happens in two scenarios @@ -544,10 +544,7 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven # - An error reponse when updating/creating/deleting including a 451 error code redirectToBlockedPage = -> pslug = $routeParams.pslug - blockedUrl = $navUrls.resolve("blocked-project", {project: pslug}) - currentUrl = $location.url() - if currentUrl.indexOf(blockedUrl) == -1 - $location.replace().path(blockedUrl) + errorHandlingService.block() responseOk = (response) -> if response.data.blocked_code @@ -566,7 +563,7 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven responseError: responseError } - $provide.factory("blockingIntercept", ["$q", "$routeParams", "$location", "$tgNavUrls", blockingIntercept]) + $provide.factory("blockingIntercept", ["$q", "$routeParams", "$location", "$tgNavUrls", "tgErrorHandlingService", blockingIntercept]) $httpProvider.interceptors.push("blockingIntercept") @@ -637,7 +634,7 @@ i18nInit = (lang, $translate) -> checksley.updateMessages('default', messages) -init = ($log, $rootscope, $auth, $events, $analytics, $translate, $location, $navUrls, appMetaService, projectService, loaderService, navigationBarService) -> +init = ($log, $rootscope, $auth, $events, $analytics, $translate, $location, $navUrls, appMetaService, projectService, loaderService, navigationBarService, errorHandlingService) -> $log.debug("Initialize application") $rootscope.$on '$translatePartialLoaderStructureChanged', () -> @@ -691,6 +688,8 @@ init = ($log, $rootscope, $auth, $events, $analytics, $translate, $location, $na un() $rootscope.$on '$routeChangeSuccess', (event, next) -> + errorHandlingService.init() + if next.loader loaderService.start(true) @@ -803,6 +802,6 @@ module.run([ "tgProjectService", "tgLoader", "tgNavigationBarService", - "$route", + "tgErrorHandlingService", init ]) diff --git a/app/coffee/classes.coffee b/app/coffee/classes.coffee index a3a74a31..89a12998 100644 --- a/app/coffee/classes.coffee +++ b/app/coffee/classes.coffee @@ -28,11 +28,9 @@ class TaigaController extends TaigaBase onInitialDataError: (xhr) => if xhr if xhr.status == 404 - @location.path(@navUrls.resolve("not-found")) - @location.replace() + @errorHandlingService.notfound() else if xhr.status == 403 - @location.path(@navUrls.resolve("permission-denied")) - @location.replace() + @errorHandlingService.permissionDenied() return @q.reject(xhr) diff --git a/app/coffee/modules/admin/memberships.coffee b/app/coffee/modules/admin/memberships.coffee index e0404170..261d2f3f 100644 --- a/app/coffee/modules/admin/memberships.coffee +++ b/app/coffee/modules/admin/memberships.coffee @@ -48,12 +48,13 @@ class MembershipsController extends mixOf(taiga.Controller, taiga.PageMixin, tai "$tgAnalytics", "tgAppMetaService", "$translate", - "$tgAuth" - "tgLightboxFactory" + "$tgAuth", + "tgLightboxFactory", + "tgErrorHandlingService" ] constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @navUrls, @analytics, - @appMetaService, @translate, @auth, @lightboxFactory) -> + @appMetaService, @translate, @auth, @lightboxFactory, @errorHandlingService) -> bindMethods(@) @scope.project = {} @@ -75,7 +76,7 @@ class MembershipsController extends mixOf(taiga.Controller, taiga.PageMixin, tai loadProject: -> return @rs.projects.getBySlug(@params.pslug).then (project) => if not project.i_am_admin - @location.path(@navUrls.resolve("permission-denied")) + @errorHandlingService.permissionDenied() @scope.projectId = project.id @scope.project = project diff --git a/app/coffee/modules/admin/project-profile.coffee b/app/coffee/modules/admin/project-profile.coffee index 7bc7efbf..4be5738b 100644 --- a/app/coffee/modules/admin/project-profile.coffee +++ b/app/coffee/modules/admin/project-profile.coffee @@ -53,11 +53,12 @@ class ProjectProfileController extends mixOf(taiga.Controller, taiga.PageMixin) "tgAppMetaService", "$translate", "$tgAuth", - "tgCurrentUserService" + "tgCurrentUserService", + "tgErrorHandlingService" ] constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @navUrls, - @appMetaService, @translate, @tgAuth, @currentUserService) -> + @appMetaService, @translate, @tgAuth, @currentUserService, @errorHandlingService) -> @scope.project = {} promise = @.loadInitialData() @@ -83,7 +84,7 @@ class ProjectProfileController extends mixOf(taiga.Controller, taiga.PageMixin) loadProject: -> return @rs.projects.getBySlug(@params.pslug).then (project) => if not project.i_am_admin - @location.path(@navUrls.resolve("permission-denied")) + @errorHandlingService.permissionDenied() @scope.projectId = project.id @scope.project = project diff --git a/app/coffee/modules/admin/project-values.coffee b/app/coffee/modules/admin/project-values.coffee index 1d9229ee..d76149d0 100644 --- a/app/coffee/modules/admin/project-values.coffee +++ b/app/coffee/modules/admin/project-values.coffee @@ -50,11 +50,12 @@ class ProjectValuesSectionController extends mixOf(taiga.Controller, taiga.PageM "$tgLocation", "$tgNavUrls", "tgAppMetaService", - "$translate" + "$translate", + "tgErrorHandlingService" ] constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @navUrls, - @appMetaService, @translate) -> + @appMetaService, @translate, @errorHandlingService) -> @scope.project = {} promise = @.loadInitialData() @@ -74,7 +75,7 @@ class ProjectValuesSectionController extends mixOf(taiga.Controller, taiga.PageM loadProject: -> return @rs.projects.getBySlug(@params.pslug).then (project) => if not project.i_am_admin - @location.path(@navUrls.resolve("permission-denied")) + @errorHandlingService.permissionDenied() @scope.projectId = project.id @scope.project = project diff --git a/app/coffee/modules/admin/roles.coffee b/app/coffee/modules/admin/roles.coffee index 9d4173a2..a8142907 100644 --- a/app/coffee/modules/admin/roles.coffee +++ b/app/coffee/modules/admin/roles.coffee @@ -48,11 +48,12 @@ class RolesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fil "$tgLocation", "$tgNavUrls", "tgAppMetaService", - "$translate" + "$translate", + "tgErrorHandlingService" ] constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @navUrls, - @appMetaService, @translate) -> + @appMetaService, @translate, @errorHandlingService) -> bindMethods(@) @scope.sectionName = "ADMIN.MENU.PERMISSIONS" @@ -71,7 +72,7 @@ class RolesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fil loadProject: -> return @rs.projects.getBySlug(@params.pslug).then (project) => if not project.i_am_admin - @location.path(@navUrls.resolve("permission-denied")) + @errorHandlingService.permissionDenied() @scope.projectId = project.id @scope.project = project diff --git a/app/coffee/modules/admin/third-parties.coffee b/app/coffee/modules/admin/third-parties.coffee index 9cc4eaf6..2d4ea15c 100644 --- a/app/coffee/modules/admin/third-parties.coffee +++ b/app/coffee/modules/admin/third-parties.coffee @@ -45,10 +45,11 @@ class WebhooksController extends mixOf(taiga.Controller, taiga.PageMixin, taiga. "$tgLocation", "$tgNavUrls", "tgAppMetaService", - "$translate" + "$translate", + "tgErrorHandlingService" ] - constructor: (@scope, @repo, @rs, @params, @location, @navUrls, @appMetaService, @translate) -> + constructor: (@scope, @repo, @rs, @params, @location, @navUrls, @appMetaService, @translate, @errorHandlingService) -> bindMethods(@) @scope.sectionName = "ADMIN.WEBHOOKS.SECTION_NAME" @@ -72,7 +73,7 @@ class WebhooksController extends mixOf(taiga.Controller, taiga.PageMixin, taiga. loadProject: -> return @rs.projects.getBySlug(@params.pslug).then (project) => if not project.i_am_admin - @location.path(@navUrls.resolve("permission-denied")) + @errorHandlingService.permissionDenied() @scope.projectId = project.id @scope.project = project diff --git a/app/coffee/modules/backlog/main.coffee b/app/coffee/modules/backlog/main.coffee index de1f7807..ea9a256a 100644 --- a/app/coffee/modules/backlog/main.coffee +++ b/app/coffee/modules/backlog/main.coffee @@ -56,11 +56,12 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F "$translate", "$tgLoading", "tgResources", - "$tgQueueModelTransformation" + "$tgQueueModelTransformation", + "tgErrorHandlingService" ] - constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, - @location, @appMetaService, @navUrls, @events, @analytics, @translate, @loading, @rs2, @modelTransform) -> + constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @appMetaService, @navUrls, + @events, @analytics, @translate, @loading, @rs2, @modelTransform, @errorHandlingService) -> bindMethods(@) @.page = 1 @@ -317,7 +318,7 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F loadProject: -> return @rs.projects.getBySlug(@params.pslug).then (project) => if not project.is_backlog_activated - @location.path(@navUrls.resolve("permission-denied")) + @errorHandlingService.permissionDenied() @scope.projectId = project.id @scope.project = project diff --git a/app/coffee/modules/issues/detail.coffee b/app/coffee/modules/issues/detail.coffee index 1448c28a..bb65f413 100644 --- a/app/coffee/modules/issues/detail.coffee +++ b/app/coffee/modules/issues/detail.coffee @@ -52,11 +52,12 @@ class IssueDetailController extends mixOf(taiga.Controller, taiga.PageMixin) "$tgAnalytics", "$tgNavUrls", "$translate", - "$tgQueueModelTransformation" + "$tgQueueModelTransformation", + "tgErrorHandlingService" ] constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, - @log, @appMetaService, @analytics, @navUrls, @translate, @modelTransform) -> + @log, @appMetaService, @analytics, @navUrls, @translate, @modelTransform, @errorHandlingService) -> bindMethods(@) @scope.issueRef = @params.issueref diff --git a/app/coffee/modules/issues/list.coffee b/app/coffee/modules/issues/list.coffee index 21ab8c3a..b555393a 100644 --- a/app/coffee/modules/issues/list.coffee +++ b/app/coffee/modules/issues/list.coffee @@ -54,11 +54,12 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi "$tgNavUrls", "$tgEvents", "$tgAnalytics", - "$translate" + "$translate", + "tgErrorHandlingService" ] constructor: (@scope, @rootscope, @repo, @confirm, @rs, @urls, @params, @q, @location, @appMetaService, - @navUrls, @events, @analytics, @translate) -> + @navUrls, @events, @analytics, @translate, @errorHandlingService) -> @scope.sectionName = "Issues" @scope.filters = {} @@ -98,7 +99,7 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi loadProject: -> return @rs.projects.getBySlug(@params.pslug).then (project) => if not project.is_issues_activated - @location.path(@navUrls.resolve("permission-denied")) + @errorHandlingService.permissionDenied() @scope.projectId = project.id @scope.project = project diff --git a/app/coffee/modules/kanban/main.coffee b/app/coffee/modules/kanban/main.coffee index c23f4f28..8b99feba 100644 --- a/app/coffee/modules/kanban/main.coffee +++ b/app/coffee/modules/kanban/main.coffee @@ -61,11 +61,12 @@ class KanbanController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi "$tgNavUrls", "$tgEvents", "$tgAnalytics", - "$translate" + "$translate", + "tgErrorHandlingService" ] constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, - @appMetaService, @navUrls, @events, @analytics, @translate) -> + @appMetaService, @navUrls, @events, @analytics, @translate, @errorHandlingService) -> bindMethods(@) @@ -193,7 +194,7 @@ class KanbanController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi loadProject: -> return @rs.projects.getBySlug(@params.pslug).then (project) => if not project.is_kanban_activated - @location.path(@navUrls.resolve("permission-denied")) + @errorHandlingService.permissionDenied() @scope.projectId = project.id @scope.project = project diff --git a/app/coffee/modules/search.coffee b/app/coffee/modules/search.coffee index 1c154887..895a7d55 100644 --- a/app/coffee/modules/search.coffee +++ b/app/coffee/modules/search.coffee @@ -48,10 +48,11 @@ class SearchController extends mixOf(taiga.Controller, taiga.PageMixin) "$tgLocation", "tgAppMetaService", "$tgNavUrls", - "$translate" + "$translate", + "tgErrorHandlingService" ] - constructor: (@scope, @repo, @rs, @params, @q, @location, @appMetaService, @navUrls, @translate) -> + constructor: (@scope, @repo, @rs, @params, @q, @location, @appMetaService, @navUrls, @translate, @errorHandlingService) -> @scope.sectionName = "Search" promise = @.loadInitialData() diff --git a/app/coffee/modules/taskboard/main.coffee b/app/coffee/modules/taskboard/main.coffee index d32b159f..68620f62 100644 --- a/app/coffee/modules/taskboard/main.coffee +++ b/app/coffee/modules/taskboard/main.coffee @@ -52,11 +52,12 @@ class TaskboardController extends mixOf(taiga.Controller, taiga.PageMixin) "$tgNavUrls" "$tgEvents" "$tgAnalytics", - "$translate" + "$translate", + "tgErrorHandlingService" ] constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @appMetaService, @location, @navUrls, - @events, @analytics, @translate) -> + @events, @analytics, @translate, @errorHandlingService) -> bindMethods(@) @scope.sectionName = @translate.instant("TASKBOARD.SECTION_NAME") @@ -124,7 +125,7 @@ class TaskboardController extends mixOf(taiga.Controller, taiga.PageMixin) loadProject: -> return @rs.projects.get(@scope.projectId).then (project) => if not project.is_backlog_activated - @location.path(@navUrls.resolve("permission-denied")) + @errorHandlingService.permissionDenied() @scope.project = project # Not used at this momment diff --git a/app/coffee/modules/tasks/detail.coffee b/app/coffee/modules/tasks/detail.coffee index 05e6aff4..2e9ae523 100644 --- a/app/coffee/modules/tasks/detail.coffee +++ b/app/coffee/modules/tasks/detail.coffee @@ -50,11 +50,12 @@ class TaskDetailController extends mixOf(taiga.Controller, taiga.PageMixin) "$tgNavUrls", "$tgAnalytics", "$translate", - "$tgQueueModelTransformation" + "$tgQueueModelTransformation", + "tgErrorHandlingService" ] constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, - @log, @appMetaService, @navUrls, @analytics, @translate, @modelTransform) -> + @log, @appMetaService, @navUrls, @analytics, @translate, @modelTransform, @errorHandlingService) -> bindMethods(@) @scope.taskRef = @params.taskref diff --git a/app/coffee/modules/team/main.coffee b/app/coffee/modules/team/main.coffee index a90b6181..e11a4769 100644 --- a/app/coffee/modules/team/main.coffee +++ b/app/coffee/modules/team/main.coffee @@ -45,11 +45,12 @@ class TeamController extends mixOf(taiga.Controller, taiga.PageMixin) "tgAppMetaService", "$tgAuth", "$translate", - "tgProjectService" + "tgProjectService", + "tgErrorHandlingService" ] constructor: (@scope, @rootscope, @repo, @rs, @params, @q, @location, @navUrls, @appMetaService, @auth, - @translate, @projectService) -> + @translate, @projectService, @errorHandlingService) -> @scope.sectionName = "TEAM.SECTION_NAME" promise = @.loadInitialData() diff --git a/app/coffee/modules/user-settings/main.coffee b/app/coffee/modules/user-settings/main.coffee index 98348150..e1ac9139 100644 --- a/app/coffee/modules/user-settings/main.coffee +++ b/app/coffee/modules/user-settings/main.coffee @@ -45,19 +45,19 @@ class UserSettingsController extends mixOf(taiga.Controller, taiga.PageMixin) "$tgLocation", "$tgNavUrls", "$tgAuth", - "$translate" + "$translate", + "tgErrorHandlingService" ] constructor: (@scope, @rootscope, @config, @repo, @confirm, @rs, @params, @q, @location, @navUrls, - @auth, @translate) -> + @auth, @translate, @errorHandlingService) -> @scope.sectionName = "USER_SETTINGS.MENU.SECTION_TITLE" @scope.project = {} @scope.user = @auth.getUser() if !@scope.user - @location.path(@navUrls.resolve("permission-denied")) - @location.replace() + @errorHandlingService.permissionDenied() @scope.lang = @getLan() @scope.theme = @getTheme() diff --git a/app/coffee/modules/user-settings/notifications.coffee b/app/coffee/modules/user-settings/notifications.coffee index c089c542..0cb25f4c 100644 --- a/app/coffee/modules/user-settings/notifications.coffee +++ b/app/coffee/modules/user-settings/notifications.coffee @@ -44,10 +44,11 @@ class UserNotificationsController extends mixOf(taiga.Controller, taiga.PageMixi "$q", "$tgLocation", "$tgNavUrls", - "$tgAuth" + "$tgAuth", + "tgErrorHandlingService" ] - constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @navUrls, @auth) -> + constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @navUrls, @auth, @errorHandlingService) -> @scope.sectionName = "USER_SETTINGS.NOTIFICATIONS.SECTION_NAME" @scope.user = @auth.getUser() promise = @.loadInitialData() diff --git a/app/coffee/modules/userstories/detail.coffee b/app/coffee/modules/userstories/detail.coffee index db09821d..5f80cdaf 100644 --- a/app/coffee/modules/userstories/detail.coffee +++ b/app/coffee/modules/userstories/detail.coffee @@ -50,12 +50,13 @@ class UserStoryDetailController extends mixOf(taiga.Controller, taiga.PageMixin) "$tgNavUrls", "$tgAnalytics", "$translate", - "$tgConfig", - "$tgQueueModelTransformation" + "$tgQueueModelTransformation", + "tgErrorHandlingService", + "$tgConfig" ] - constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @log, @appMetaService, - @navUrls, @analytics, @translate, @configService, @modelTransform) -> + constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, + @log, @appMetaService, @navUrls, @analytics, @translate, @modelTransform, @errorHandlingService, @configService) -> bindMethods(@) @scope.usRef = @params.usref diff --git a/app/coffee/modules/wiki/main.coffee b/app/coffee/modules/wiki/main.coffee index 40c69277..7d237ea2 100644 --- a/app/coffee/modules/wiki/main.coffee +++ b/app/coffee/modules/wiki/main.coffee @@ -51,11 +51,12 @@ class WikiDetailController extends mixOf(taiga.Controller, taiga.PageMixin) "tgAppMetaService", "$tgNavUrls", "$tgAnalytics", - "$translate" + "$translate", + "tgErrorHandlingService" ] constructor: (@scope, @rootscope, @repo, @model, @confirm, @rs, @params, @q, @location, - @filter, @log, @appMetaService, @navUrls, @analytics, @translate) -> + @filter, @log, @appMetaService, @navUrls, @analytics, @translate, @errorHandlingService) -> @scope.projectSlug = @params.pslug @scope.wikiSlug = @params.slug @scope.wikiTitle = @scope.wikiSlug @@ -86,7 +87,7 @@ class WikiDetailController extends mixOf(taiga.Controller, taiga.PageMixin) loadProject: -> return @rs.projects.getBySlug(@params.pslug).then (project) => if not project.is_wiki_activated - @location.path(@navUrls.resolve("permission-denied")) + @errorHandlingService.permissionDenied() @scope.projectId = project.id @scope.project = project diff --git a/app/index.jade b/app/index.jade index 66d7d234..6f5cd237 100644 --- a/app/index.jade +++ b/app/index.jade @@ -20,9 +20,13 @@ html(lang="en") window.prerenderReady = false; body(tg-main) - div(tg-navigation-bar) + div(tg-navigation-bar, ng-if="!errorHandling.showingError") + div.master(ng-view, ng-if="!errorHandling.showingError") - div.master(ng-view) + div(ng-if="errorHandling.notfound", ng-include="'error/not-found.html'") + div(ng-if="errorHandling.error", ng-include="'error/error.html'") + div(ng-if="errorHandling.permissionDenied", ng-include="'error/permission-denied.html'") + div(ng-if="errorHandling.blocked", ng-include="'projects/project/blocked-project.html'") div.lightbox.lightbox-generic-ask include partials/includes/modules/lightbox-generic-ask diff --git a/app/modules/projects/transfer/transfer-project.controller.coffee b/app/modules/projects/transfer/transfer-project.controller.coffee index 715d45b3..b7bed191 100644 --- a/app/modules/projects/transfer/transfer-project.controller.coffee +++ b/app/modules/projects/transfer/transfer-project.controller.coffee @@ -28,10 +28,11 @@ class TransferProject "tgCurrentUserService", "$tgNavUrls", "$translate", - "$tgConfirm" + "$tgConfirm", + "tgErrorHandlingService" ] - constructor: (@routeParams, @projectService, @location, @authService, @currentUserService, @navUrls, @translate, @confirmService) -> + constructor: (@routeParams, @projectService, @location, @authService, @currentUserService, @navUrls, @translate, @confirmService, @errorHandlingService) -> initialize: () -> @.projectId = @.project.get("id") @@ -41,7 +42,7 @@ class TransferProject _validateToken: () -> return @projectService.transferValidateToken(@.projectId, @.token).then null, (data, status) => - @location.path(@navUrls.resolve("not-found")) + @errorHandlingService.notfound() _refreshUserData: () -> return @authService.refresh().then () => diff --git a/app/modules/projects/transfer/transfer-project.controller.spec.coffee b/app/modules/projects/transfer/transfer-project.controller.spec.coffee index 812b67b8..c87baecb 100644 --- a/app/modules/projects/transfer/transfer-project.controller.spec.coffee +++ b/app/modules/projects/transfer/transfer-project.controller.spec.coffee @@ -28,6 +28,13 @@ describe "TransferProject", -> mocks.routeParams = {} provide.value "$routeParams", mocks.routeParams + _mockErrorHandlingService = () -> + mocks.errorHandlingService = { + notfound: sinon.stub() + } + + provide.value "tgErrorHandlingService", mocks.errorHandlingService + _mockProjectsService = () -> mocks.projectsService = { transferValidateToken: sinon.stub() @@ -90,6 +97,7 @@ describe "TransferProject", -> _mockTgNavUrls() _mockTranslate() _mockTgConfirm() + _mockErrorHandlingService() return null _inject = (callback) -> @@ -119,7 +127,7 @@ describe "TransferProject", -> ctrl = $controller("TransferProjectController") ctrl.project = project ctrl.initialize().then () -> - expect(mocks.location.path).to.be.calledWith("/not-found") + expect(mocks.errorHandlingService.notfound).have.been.called; done() it "valid token private project with max projects for user", (done) -> diff --git a/app/modules/services/error-handling.service.coffee b/app/modules/services/error-handling.service.coffee new file mode 100644 index 00000000..a3ceef53 --- /dev/null +++ b/app/modules/services/error-handling.service.coffee @@ -0,0 +1,48 @@ +### +# Copyright (C) 2014-2016 Taiga Agile LLC +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# File: error-handling.service.coffee +### + +taiga = @.taiga + +class ErrorHandlingService + @.$inject = [ + "$rootScope" + ] + + constructor: (@rootScope) -> + + init: () -> + @rootScope.errorHandling = {}; + + notfound: -> + @rootScope.errorHandling.showingError = true + @rootScope.errorHandling.notfound = true + + error: -> + @rootScope.errorHandling.showingError = true + @rootScope.errorHandling.error = true + + permissionDenied: -> + @rootScope.errorHandling.showingError = true + @rootScope.errorHandling.permissionDenied = true + + block: -> + @rootScope.errorHandling.showingError = true + @rootScope.errorHandling.blocked = true + +angular.module("taigaCommon").service("tgErrorHandlingService", ErrorHandlingService) diff --git a/app/modules/services/xhrError.service.coffee b/app/modules/services/xhrError.service.coffee index 9015e858..42de3515 100644 --- a/app/modules/services/xhrError.service.coffee +++ b/app/modules/services/xhrError.service.coffee @@ -20,19 +20,16 @@ class xhrError extends taiga.Service @.$inject = [ "$q", - "$location", - "$tgNavUrls" + "tgErrorHandlingService" ] - constructor: (@q, @location, @navUrls) -> + constructor: (@q, @errorHandlingService) -> notFound: () -> - @location.path(@navUrls.resolve("not-found")) - @location.replace() + @errorHandlingService.notfound() permissionDenied: () -> - @location.path(@navUrls.resolve("permission-denied")) - @location.replace() + @errorHandlingService.permissionDenied() response: (xhr) -> if xhr diff --git a/app/modules/services/xhrError.service.spec.coffee b/app/modules/services/xhrError.service.spec.coffee index f69ef84a..2efc12ef 100644 --- a/app/modules/services/xhrError.service.spec.coffee +++ b/app/modules/services/xhrError.service.spec.coffee @@ -28,20 +28,14 @@ describe "tgXhrErrorService", -> provide.value "$q", mocks.q - _mockLocation = () -> - mocks.location = { - path: sinon.spy(), - replace: sinon.spy() + + _mockErrorHandling = () -> + mocks.errorHandling = { + notfound: sinon.stub(), + permissionDenied: sinon.stub() } - provide.value "$location", mocks.location - - _mockNavUrls = () -> - mocks.navUrls = { - resolve: sinon.stub() - } - - provide.value "$tgNavUrls", mocks.navUrls + provide.value "tgErrorHandlingService", mocks.errorHandling _inject = (callback) -> inject (_tgXhrErrorService_) -> @@ -52,8 +46,7 @@ describe "tgXhrErrorService", -> module ($provide) -> provide = $provide _mockQ() - _mockLocation() - _mockNavUrls() + _mockErrorHandling() return null @@ -70,23 +63,17 @@ describe "tgXhrErrorService", -> status: 404 } - mocks.navUrls.resolve.withArgs("not-found").returns("not-found") - xhrErrorService.response(xhr) expect(mocks.q.reject.withArgs(xhr)).to.be.calledOnce - expect(mocks.location.path.withArgs("not-found")).to.be.calledOnce - expect(mocks.location.replace).to.be.calledOnce + expect(mocks.errorHandling.notfound).to.be.calledOnce it "403 status redirect to permission-denied page", () -> xhr = { status: 403 } - mocks.navUrls.resolve.withArgs("permission-denied").returns("permission-denied") - xhrErrorService.response(xhr) expect(mocks.q.reject.withArgs(xhr)).to.be.calledOnce - expect(mocks.location.path.withArgs("permission-denied")).to.be.calledOnce - expect(mocks.location.replace).to.be.calledOnce + expect(mocks.errorHandling.permissionDenied).to.be.calledOnce