Add homepage allowed sections

remotes/origin/4.0rc
Álex Hermida 2018-09-21 12:46:14 +02:00 committed by Alex Hermida
parent 0619ce72ef
commit 6eb9a67859
3 changed files with 61 additions and 8 deletions

View File

@ -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")),

View File

@ -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

View File

@ -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")