Skip to content

Commit

Permalink
[Issue #n/a] tried to fix the travis conditional command again
Browse files Browse the repository at this point in the history
[Issue #190] Resolved issue by adding a setting and make the login_required decorator in the view conditional with this setting
  • Loading branch information
scaphilo committed Aug 4, 2018
1 parent ab8c9f8 commit 179f706
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -10,7 +10,7 @@ before_install:

install:
- python setup.py install
- pip install -r requirements/heroku_requirements.txte
- pip install -r requirements/heroku_requirements.txt

script:
- pytest --cov=koalixcrm --cov-report xml --cov-report term -m "not version_increase"
Expand Down
22 changes: 11 additions & 11 deletions koalixcrm/crm/views/restinterface.py
Expand Up @@ -9,13 +9,15 @@

from koalixcrm.crm.documents.contract import Contract, ContractJSONSerializer
from koalixcrm.crm.reporting.task import Task, TaskSerializer
from koalixcrm.crm.reporting.taskstatus import TaskStatus, TaskStatusJSONSerializer
from koalixcrm.crm.reporting.taskstatus import TaskStatus
from koalixcrm.crm.reporting.project import Project, ProjectJSONSerializer
from koalixcrm.crm.product.product import Product, ProductJSONSerializer
from koalixcrm.crm.product.unit import Unit, UnitJSONSerializer
from koalixcrm.crm.product.tax import Tax, TaxJSONSerializer
from koalixcrm.crm.product.currency import CurrencyJSONSerializer, Currency
from koalixcrm.crm.views.renderer import XSLFORenderer
from koalixcrm.globalSupportFunctions import ConditionalMethodDecorator
from django.conf import settings


class TaskAsJSON(viewsets.ModelViewSet):
Expand All @@ -27,7 +29,7 @@ class TaskAsJSON(viewsets.ModelViewSet):
renderer_classes = (BrowsableAPIRenderer, JSONRenderer, XMLRenderer)
filter_fields = ('project',)

@method_decorator(login_required)
@ConditionalMethodDecorator(method_decorator(login_required), settings.KOALIXCRM_REST_API_AUTH)
def dispatch(self, *args, **kwargs):
return super(TaskAsJSON, self).dispatch(*args, **kwargs)

Expand All @@ -40,7 +42,7 @@ class ContractAsJSON(viewsets.ModelViewSet):
serializer_class = ContractJSONSerializer
renderer_classes = (BrowsableAPIRenderer, JSONRenderer, XMLRenderer)

@method_decorator(login_required)
@ConditionalMethodDecorator(method_decorator(login_required), settings.KOALIXCRM_REST_API_AUTH)
def dispatch(self, *args, **kwargs):
return super(ContractAsJSON, self).dispatch(*args, **kwargs)

Expand All @@ -53,7 +55,7 @@ class TaskStatusAsJSON(viewsets.ModelViewSet):
serializer_class = TaskSerializer
renderer_classes = (BrowsableAPIRenderer, JSONRenderer, XMLRenderer)

@method_decorator(login_required)
@ConditionalMethodDecorator(method_decorator(login_required), settings.KOALIXCRM_REST_API_AUTH)
def dispatch(self, *args, **kwargs):
return super(TaskStatusAsJSON, self).dispatch(*args, **kwargs)

Expand All @@ -66,7 +68,7 @@ class CurrencyAsJSON(viewsets.ModelViewSet):
serializer_class = CurrencyJSONSerializer
renderer_classes = (BrowsableAPIRenderer, JSONRenderer, XMLRenderer)

@method_decorator(login_required)
@ConditionalMethodDecorator(method_decorator(login_required), settings.KOALIXCRM_REST_API_AUTH)
def dispatch(self, *args, **kwargs):
return super(CurrencyAsJSON, self).dispatch(*args, **kwargs)

Expand All @@ -79,7 +81,7 @@ class TaxAsJSON(viewsets.ModelViewSet):
serializer_class = TaxJSONSerializer
renderer_classes = (BrowsableAPIRenderer, JSONRenderer, XMLRenderer)

@method_decorator(login_required)
@ConditionalMethodDecorator(method_decorator(login_required), settings.KOALIXCRM_REST_API_AUTH)
def dispatch(self, *args, **kwargs):
return super(TaxAsJSON, self).dispatch(*args, **kwargs)

Expand All @@ -92,7 +94,7 @@ class UnitAsJSON(viewsets.ModelViewSet):
serializer_class = UnitJSONSerializer
renderer_classes = (BrowsableAPIRenderer, JSONRenderer, XMLRenderer)

@method_decorator(login_required)
@ConditionalMethodDecorator(method_decorator(login_required), settings.KOALIXCRM_REST_API_AUTH)
def dispatch(self, *args, **kwargs):
return super(UnitAsJSON, self).dispatch(*args, **kwargs)

Expand All @@ -105,7 +107,7 @@ class ProductAsJSON(viewsets.ModelViewSet):
serializer_class = ProductJSONSerializer
renderer_classes = (BrowsableAPIRenderer, JSONRenderer, XMLRenderer)

@method_decorator(login_required)
@ConditionalMethodDecorator(method_decorator(login_required), settings.KOALIXCRM_REST_API_AUTH)
def dispatch(self, *args, **kwargs):
return super(ProductAsJSON, self).dispatch(*args, **kwargs)

Expand All @@ -119,9 +121,7 @@ class ProjectAsJSON(viewsets.ModelViewSet):
renderer_classes = (BrowsableAPIRenderer, JSONRenderer, XMLRenderer, XSLFORenderer)
file_name = "this_is_the_ProjectList.xml"



@method_decorator(login_required)
@ConditionalMethodDecorator(method_decorator(login_required), settings.KOALIXCRM_REST_API_AUTH)
def dispatch(self, *args, **kwargs):
return super(ProjectAsJSON, self).dispatch(*args, **kwargs)

12 changes: 12 additions & 0 deletions koalixcrm/globalSupportFunctions.py
Expand Up @@ -21,3 +21,15 @@ def xstr(s):
return ""
else:
return str(s)


class ConditionalMethodDecorator(object):
def __init__(self, dec, condition):
self.decorator = dec
self.condition = condition

def __call__(self, func):
if not self.condition:
# Return the function unchanged, not decorated.
return func
return self.decorator(func)
2 changes: 1 addition & 1 deletion projectsettings/settings/base_settings.py
Expand Up @@ -144,4 +144,4 @@

REST_FRAMEWORK = {
'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',)
}
}
4 changes: 3 additions & 1 deletion projectsettings/settings/development_settings.py
Expand Up @@ -15,4 +15,6 @@
}

FOP_EXECUTABLE = "/usr/bin/fop"
GRAPPELLI_INDEX_DASHBOARD = 'projectsettings.dashboard.CustomIndexDashboard'
GRAPPELLI_INDEX_DASHBOARD = 'projectsettings.dashboard.CustomIndexDashboard'

KOALIXCRM_REST_API_AUTH = False
4 changes: 3 additions & 1 deletion projectsettings/settings/development_sqlite_settings.py
Expand Up @@ -14,4 +14,6 @@
}

FOP_EXECUTABLE = "/usr/bin/fop-2.2/fop/fop"
GRAPPELLI_INDEX_DASHBOARD = 'projectsettings.dashboard.CustomIndexDashboard'
GRAPPELLI_INDEX_DASHBOARD = 'projectsettings.dashboard.CustomIndexDashboard'

KOALIXCRM_REST_API_AUTH = True
2 changes: 2 additions & 0 deletions projectsettings/settings/heroku_settings.py
Expand Up @@ -17,3 +17,5 @@
FOP_EXECUTABLE = "/usr/bin/fop"
GRAPPELLI_INDEX_DASHBOARD = 'projectsettings.dashboard.CustomIndexDashboard'
ALLOWED_HOSTS = ['koalix-crm.herokuapp.com']

KOALIXCRM_REST_API_AUTH = True
3 changes: 2 additions & 1 deletion projectsettings/settings/production_settings.py
Expand Up @@ -15,4 +15,5 @@
}

FOP_EXECUTABLE = "/usr/bin/fop"
GRAPPELLI_INDEX_DASHBOARD = 'projectsettings.dashboard.CustomIndexDashboard'
GRAPPELLI_INDEX_DASHBOARD = 'projectsettings.dashboard.CustomIndexDashboard'
KOALIXCRM_REST_API_AUTH = True

0 comments on commit 179f706

Please sign in to comment.