From 0bd3b38a267be67cbe8b78fb0e8d9da82fa6bf50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Mon, 26 Nov 2018 18:41:20 +0100 Subject: [PATCH] Fix default homepage for public projects as guest --- app/coffee/modules/common/sections.coffee | 29 +++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/app/coffee/modules/common/sections.coffee b/app/coffee/modules/common/sections.coffee index a7cb9c16..ab0ec9a0 100644 --- a/app/coffee/modules/common/sections.coffee +++ b/app/coffee/modules/common/sections.coffee @@ -24,33 +24,38 @@ module = angular.module("taigaCommon") -SECTIONS = { - 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", "tgCurrentUserService"] + SECTIONS = { + 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'} + } + 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") + defaultHomePage = "timeline" + + projects = @currentUserService.projects?.get("all") project = projects.find (p) -> return p.get('slug') == projectSlug + if not project + return defaultHomePage + if not sectionId sectionId = project.get('my_homepage') - section = _.find(SECTIONS, {"id": sectionId}) + section = _.find(SECTIONS, {"id": sectionId}) if !section or project?.get(section.enabled) is not true - return "timeline" + return defaultHomePage return section.path