Add homepage allowed sections
parent
0619ce72ef
commit
6eb9a67859
|
@ -23,18 +23,20 @@ from django.utils.translation import ugettext_lazy as _
|
||||||
class Section(enum.IntEnum):
|
class Section(enum.IntEnum):
|
||||||
timeline = 1
|
timeline = 1
|
||||||
search = 2
|
search = 2
|
||||||
backlog = 3
|
epics = 3
|
||||||
kanban = 4
|
backlog = 4
|
||||||
issues = 5
|
kanban = 5
|
||||||
wiki = 6
|
issues = 6
|
||||||
team = 7
|
wiki = 7
|
||||||
meetup = 8
|
team = 8
|
||||||
admin = 9
|
meetup = 9
|
||||||
|
admin = 10
|
||||||
|
|
||||||
|
|
||||||
HOMEPAGE_CHOICES = (
|
HOMEPAGE_CHOICES = (
|
||||||
(Section.timeline, _("Timeline")),
|
(Section.timeline, _("Timeline")),
|
||||||
(Section.search, _("Search")),
|
(Section.search, _("Search")),
|
||||||
|
(Section.epics, _("Epics")),
|
||||||
(Section.backlog, _("Backlog")),
|
(Section.backlog, _("Backlog")),
|
||||||
(Section.kanban, _("Kanban")),
|
(Section.kanban, _("Kanban")),
|
||||||
(Section.issues, _("Issues")),
|
(Section.issues, _("Issues")),
|
||||||
|
|
|
@ -20,13 +20,29 @@ from taiga.base.api import serializers
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|
||||||
|
from taiga.projects.settings.choices import Section
|
||||||
|
|
||||||
|
|
||||||
class UserProjectSettingsSerializer(serializers.ModelSerializer):
|
class UserProjectSettingsSerializer(serializers.ModelSerializer):
|
||||||
project_name = serializers.SerializerMethodField("get_project_name")
|
project_name = serializers.SerializerMethodField("get_project_name")
|
||||||
|
allowed_sections = serializers.SerializerMethodField("get_allowed_sections")
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.UserProjectSettings
|
model = models.UserProjectSettings
|
||||||
fields = ('id', 'project', 'project_name', 'homepage')
|
fields = ('id', 'project', 'project_name', 'homepage', 'allowed_sections')
|
||||||
|
|
||||||
def get_project_name(self, obj):
|
def get_project_name(self, obj):
|
||||||
return obj.project.name
|
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
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
|
|
||||||
from .. import factories as f
|
from .. import factories as f
|
||||||
|
|
||||||
|
@ -31,3 +32,37 @@ def test_create_retrieve_home_page_setting():
|
||||||
current_number = policy_model_cls.objects.all().count()
|
current_number = policy_model_cls.objects.all().count()
|
||||||
assert current_number == 1
|
assert current_number == 1
|
||||||
assert setting.homepage == Section.timeline
|
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")
|
||||||
|
|
Loading…
Reference in New Issue