Add system-stats endpoint
parent
bc2d8ece7f
commit
03ff40ddd4
|
@ -283,6 +283,7 @@ INSTALLED_APPS = [
|
|||
"taiga.mdrender",
|
||||
"taiga.export_import",
|
||||
"taiga.feedback",
|
||||
"taiga.stats",
|
||||
"taiga.hooks.github",
|
||||
"taiga.hooks.gitlab",
|
||||
"taiga.hooks.bitbucket",
|
||||
|
@ -434,6 +435,9 @@ TAGS_PREDEFINED_COLORS = ["#fce94f", "#edd400", "#c4a000", "#8ae234",
|
|||
FEEDBACK_ENABLED = True
|
||||
FEEDBACK_EMAIL = "support@taiga.io"
|
||||
|
||||
# Stats module settings
|
||||
STATS_ENABLED = False
|
||||
|
||||
# 0 notifications will work in a synchronous way
|
||||
# >0 an external process will check the pending notifications and will send them
|
||||
# collapsed during that interval
|
||||
|
|
|
@ -63,6 +63,13 @@ DATABASES = {
|
|||
#GITHUB_API_CLIENT_ID = "yourgithubclientid"
|
||||
#GITHUB_API_CLIENT_SECRET = "yourgithubclientsecret"
|
||||
|
||||
# FEEDBACK MODULE (See config in taiga-front too)
|
||||
#FEEDBACK_ENABLED = True
|
||||
#FEEDBACK_EMAIL = "support@taiga.io"
|
||||
|
||||
# STATS MODULE
|
||||
#STATS_ENABLED = False
|
||||
|
||||
# SITEMAP
|
||||
# If is True /front/sitemap.xml show a valid sitemap of taiga-front client
|
||||
#FRONT_SITEMAP_ENABLED = False
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
|
||||
# Copyright (C) 2014 Jesús Espino <jespinog@gmail.com>
|
||||
# Copyright (C) 2014 David Barragán <bameda@dbarragan.com>
|
||||
|
@ -192,5 +193,9 @@ router.register(r"importer", ProjectImporterViewSet, base_name="importer")
|
|||
router.register(r"exporter", ProjectExporterViewSet, base_name="exporter")
|
||||
|
||||
|
||||
# feedback
|
||||
# Stats
|
||||
# - see taiga.stats.routers and taiga.stats.apps
|
||||
|
||||
|
||||
# Feedback
|
||||
# - see taiga.feedback.routers and taiga.feedback.apps
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
# Copyright (C) 2015 Taiga Agile LLC <support@taiga.io>
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
default_app_config = "taiga.stats.apps.StatsAppConfig"
|
|
@ -0,0 +1,33 @@
|
|||
# Copyright (C) 2015 Taiga Agile LLC <support@taiga.io>
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from taiga.base.api import viewsets
|
||||
from taiga.base import response
|
||||
|
||||
from . import permissions
|
||||
from . import services
|
||||
|
||||
|
||||
class SystemStatsViewSet(viewsets.ViewSet):
|
||||
permission_classes = (permissions.SystemStatsPermission,)
|
||||
|
||||
def list(self, request, **kwargs):
|
||||
stats = {
|
||||
"total_users": services.get_total_users(),
|
||||
"total_projects": services.get_total_projects(),
|
||||
"total_userstories": services.grt_total_user_stories(),
|
||||
"total_issues": services.get_total_issues(),
|
||||
}
|
||||
return response.Ok(stats)
|
|
@ -0,0 +1,30 @@
|
|||
# Copyright (C) 2015 Taiga Agile LLC <support@taiga.io>
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.apps import AppConfig
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.conf.urls import include, url
|
||||
|
||||
from .routers import router
|
||||
|
||||
|
||||
class StatsAppConfig(AppConfig):
|
||||
name = "taiga.stats"
|
||||
verbose_name = "Stats"
|
||||
|
||||
def ready(self):
|
||||
if settings.STATS_ENABLED:
|
||||
from taiga.urls import urlpatterns
|
||||
urlpatterns.append(url(r'^api/v1/', include(router.urls)))
|
|
@ -0,0 +1,20 @@
|
|||
# Copyright (C) 2015 Taiga Agile LLC <support@taiga.io>
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from taiga.base.api import permissions
|
||||
|
||||
|
||||
class SystemStatsPermission(permissions.TaigaResourcePermission):
|
||||
global_perms = permissions.AllowAny()
|
|
@ -0,0 +1,20 @@
|
|||
# Copyright (C) 2015 Taiga Agile LLC <support@taiga.io>
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from taiga.base import routers
|
||||
from . import api
|
||||
|
||||
|
||||
router = routers.DefaultRouter(trailing_slash=False)
|
||||
router.register(r"stats/system", api.SystemStatsViewSet, base_name="system-stats")
|
|
@ -0,0 +1,44 @@
|
|||
# Copyright (C) 2015 Taiga Agile LLC <support@taiga.io>
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from django.apps import apps
|
||||
|
||||
|
||||
def get_total_projects():
|
||||
model = apps.get_model("projects", "Project")
|
||||
queryset = model.objects.all()
|
||||
return queryset.count()
|
||||
|
||||
|
||||
def grt_total_user_stories():
|
||||
model = apps.get_model("userstories", "UserStory")
|
||||
queryset = model.objects.all()
|
||||
return queryset.count()
|
||||
|
||||
|
||||
def get_total_issues():
|
||||
model = apps.get_model("issues", "Issue")
|
||||
queryset = model.objects.all()
|
||||
return queryset.count()
|
||||
|
||||
|
||||
def get_total_users(only_active=True, no_system=True):
|
||||
model = apps.get_model("users", "User")
|
||||
queryset = model.objects.all()
|
||||
if only_active:
|
||||
queryset = queryset.filter(is_active=True)
|
||||
if no_system:
|
||||
queryset = queryset.filter(is_system=False)
|
||||
return queryset.count()
|
Loading…
Reference in New Issue