From e7ea15427eae4346627d634373b22c0b0cdc1e42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lex=20Hermida?= Date: Fri, 23 Nov 2018 12:06:03 +0100 Subject: [PATCH] Avoid 403 custom homepages --- app/coffee/modules/base/navurls.coffee | 5 ++-- app/coffee/modules/common/sections.coffee | 24 ++++++++++++------- .../project/project-router.controller.coffee | 8 ++----- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/coffee/modules/base/navurls.coffee b/app/coffee/modules/base/navurls.coffee index e21b0464..1552dda1 100644 --- a/app/coffee/modules/base/navurls.coffee +++ b/app/coffee/modules/base/navurls.coffee @@ -119,9 +119,8 @@ NavigationUrlsDirective = ($navurls, $auth, $q, $location, lightboxService, tgSe options.user = user.username if user if options['section'] - sections = tgSections.list() - section = _.find(sections, {"id": options['section']}) - name = "#{name}-#{section.path}" + path = tgSections.getPath(options['project'], options['section']) + name = "#{name}-#{path}" url = $navurls.resolve(name) diff --git a/app/coffee/modules/common/sections.coffee b/app/coffee/modules/common/sections.coffee index f826d413..c04413a8 100644 --- a/app/coffee/modules/common/sections.coffee +++ b/app/coffee/modules/common/sections.coffee @@ -25,21 +25,29 @@ module = angular.module("taigaCommon") SECTIONS = { - 1: {id: 1, title: 'TIMELINE', path:'timeline'} - 2: {id: 2, title: 'EPICS', path:'epics'} - 3: {id: 3, title: 'BACKLOG', path:'backlog'} - 4: {id: 4, title: 'KANBAN', path:'kanban'} - 5: {id: 5, title: 'ISSUES', path:'issues'} - 6: {id: 6, title: 'WIKI', path:'wiki'} + 1: {id: 1, title: 'TIMELINE', path:'timeline', enabled: ''} + 2: {id: 2, title: 'EPICS', path:'epics', enabled: 'is_epics_activated'} + 3: {id: 3, title: 'BACKLOG', path:'backlog', enabled: 'is_backlog_activated'} + 4: {id: 4, title: 'KANBAN', path:'kanban', enabled: 'is_kanban_activated'} + 5: {id: 5, title: 'ISSUES', path:'issues', enabled: 'is_issues_activated'} + 6: {id: 6, title: 'WIKI', path:'wiki', enabled: 'is_wiki_activated'} } class SectionsService extends taiga.Service - @.$inject = ["$translate"] + @.$inject = ["$translate", "tgCurrentUserService"] - constructor: (@translate) -> + constructor: (@translate, @currentUserService) -> super() _.map(SECTIONS, (x) => x.title = @translate.instant("PROJECT.SECTION.#{x.title}")) list: () -> return SECTIONS + getPath: (projectSlug, sectionId) -> + projects = @currentUserService.projects.get("all") + project = projects.find (p) -> return p.get('slug') == projectSlug + section = _.find(SECTIONS, {"id": sectionId}) + if !section or project?.get(section.enabled) is not true + return "timeline" + + return section.path module.service("$tgSections", SectionsService) diff --git a/app/modules/projects/project/project-router.controller.coffee b/app/modules/projects/project/project-router.controller.coffee index 2650dc16..13f4e8c0 100644 --- a/app/modules/projects/project/project-router.controller.coffee +++ b/app/modules/projects/project/project-router.controller.coffee @@ -40,16 +40,12 @@ class ProjectRouterController @location.url("project/#{@routeParams.pslug}/timeline") getProjectHomepage: () -> - sections = @tgSections.list() project = @projectService.project.toJS() - @rs.userProjectSettings.list({project: project.id}).then (userProjectSettings) -> + @rs.userProjectSettings.list({project: project.id}).then (userProjectSettings) => settings = _.find(userProjectSettings, {"project": project.id}) return if !settings - section = _.find(sections, {"id": settings.homepage}) - return if !section - - return section.path + return @tgSections.getPath(project.slug, settings.homepage) angular.module("taigaProjects").controller("ProjectRouter", ProjectRouterController)