diff --git a/taiga/projects/settings/choices.py b/taiga/projects/settings/choices.py index 1e84323b..eac2b940 100644 --- a/taiga/projects/settings/choices.py +++ b/taiga/projects/settings/choices.py @@ -23,18 +23,20 @@ from django.utils.translation import ugettext_lazy as _ class Section(enum.IntEnum): timeline = 1 search = 2 - backlog = 3 - kanban = 4 - issues = 5 - wiki = 6 - team = 7 - meetup = 8 - admin = 9 + epics = 3 + backlog = 4 + kanban = 5 + issues = 6 + wiki = 7 + team = 8 + meetup = 9 + admin = 10 HOMEPAGE_CHOICES = ( (Section.timeline, _("Timeline")), (Section.search, _("Search")), + (Section.epics, _("Epics")), (Section.backlog, _("Backlog")), (Section.kanban, _("Kanban")), (Section.issues, _("Issues")), diff --git a/taiga/projects/settings/serializers.py b/taiga/projects/settings/serializers.py index b7175059..ce9ac582 100644 --- a/taiga/projects/settings/serializers.py +++ b/taiga/projects/settings/serializers.py @@ -20,13 +20,29 @@ from taiga.base.api import serializers from . import models +from taiga.projects.settings.choices import Section + class UserProjectSettingsSerializer(serializers.ModelSerializer): project_name = serializers.SerializerMethodField("get_project_name") + allowed_sections = serializers.SerializerMethodField("get_allowed_sections") class Meta: model = models.UserProjectSettings - fields = ('id', 'project', 'project_name', 'homepage') + fields = ('id', 'project', 'project_name', 'homepage', 'allowed_sections') def get_project_name(self, obj): return obj.project.name + + def get_allowed_sections(self, obj): + sections = [Section.timeline, Section.search, Section.team] + + active_modules = ['epics', 'backlog', 'kanban', 'wiki', 'issues'] + + for module in active_modules: + module_name = "is_{}_activated".format(module) + if getattr(obj.project, module_name): + sections.append(getattr(Section, module)) + if obj.project.videoconferences: + sections.append(Section.meetup) + return sections diff --git a/tests/integration/test_project_settings.py b/tests/integration/test_project_settings.py index 9846887c..3419432c 100644 --- a/tests/integration/test_project_settings.py +++ b/tests/integration/test_project_settings.py @@ -1,6 +1,7 @@ import pytest from django.apps import apps +from django.core.urlresolvers import reverse from .. import factories as f @@ -31,3 +32,37 @@ def test_create_retrieve_home_page_setting(): current_number = policy_model_cls.objects.all().count() assert current_number == 1 assert setting.homepage == Section.timeline + + +def test_retrieve_home_page_setting_with_allowed_sections(client): + # Default template has next configuration: + # "is_epics_activated": false, + # "is_backlog_activated": true, + # "is_kanban_activated": false, + # "is_wiki_activated": true, + # "is_issues_activated": true, + # "videoconferences": null, + user = f.UserFactory.create() + project = f.ProjectFactory.create(owner=user) + f.MembershipFactory.create(project=project, user=user, is_admin=True) + + url = reverse("user-project-settings-list") + + client.login(project.owner) + + response = client.get(url) + + assert response.status_code == 200 + assert 1 == len(response.data) + assert 1 == response.data[0].get("homepage") + + assert 6 == len(response.data[0].get("allowed_sections")) + + assert Section.timeline in response.data[0].get("allowed_sections") + assert Section.search in response.data[0].get("allowed_sections") + assert Section.team in response.data[0].get("allowed_sections") + assert Section.backlog in response.data[0].get("allowed_sections") + assert Section.issues in response.data[0].get("allowed_sections") + assert Section.wiki in response.data[0].get("allowed_sections") + + assert Section.epics not in response.data[0].get("allowed_sections")