Skip to content

Commit

Permalink
Tracking pull request to merge release-1.6.26 to master (#1785)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuanfandevops committed Jan 7, 2022
1 parent cc45fde commit 391e177
Show file tree
Hide file tree
Showing 34 changed files with 211 additions and 143 deletions.
2 changes: 1 addition & 1 deletion .pipeline/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const ocpName = 'apps.silver.devops'
const phases = {
build: { namespace:'0ab226-tools' , name: `${name}`, phase: 'build' , changeId:changeId, suffix: `-build-${changeId}` ,
instance: `${name}-build-${changeId}` , version:`${version}-${changeId}`, tag:`build-${version}-${changeId}`,
releaseBranch: 'release-1.6.25'
releaseBranch: 'release-1.6.26'
},
dev: {namespace:'0ab226-dev' , name: `${name}`, phase: 'dev' , changeId:changeId, suffix: `-dev-${changeId}` ,
instance: `${name}-dev-${changeId}` , version:`${version}-${changeId}`, tag:`dev-${version}-${changeId}`,
Expand Down
6 changes: 3 additions & 3 deletions backend/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from django.apps import AppConfig
from django.db.models.signals import post_migrate
from minio import Minio
from minio.error import MinioError, ResponseError

from api.services.KeycloakAPI import list_users, get_token
from db_comments.db_actions import create_db_comments, \
Expand Down Expand Up @@ -87,11 +86,12 @@ def check_external_services():
print('Minio bucket doesn\'t exist. Creating it')
try:
minio.make_bucket(MINIO['BUCKET_NAME'])
except ResponseError as _error:
except Exception as _error:
print(_error)
raise RuntimeError('Minio bucket creation failed')

except MinioError as _error:
except Exception as _error:
print(_error)
raise RuntimeError('Minio connection failed')

if KEYCLOAK['ENABLED']:
Expand Down
4 changes: 2 additions & 2 deletions backend/api/decorators/PermissionRequired.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@

def permission_required(permission):
def wrapper(func):
def wrapped(self, request, *args, **kwargs):
def wrapped(request, *args, **kwargs):
if not request.user.has_perm(permission):
raise exceptions.PermissionDenied(
'You do not have sufficient authorization to use this '
'functionality.'
)

return func(self, request, *args, **kwargs)
return func(request, *args, **kwargs)
return wrapped
return wrapper
13 changes: 9 additions & 4 deletions backend/api/models/ComplianceReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,35 @@ class ComplianceReportWorkflowState(Auditable):
# limit_choices_to=['Draft', 'Submitted', 'Deleted'],
related_name='+',
to_field='status',
default='Draft')
default='Draft',
on_delete=models.DO_NOTHING
)

analyst_status = models.ForeignKey(
ComplianceReportStatus,
null=False,
related_name='+',
to_field='status',
default='Unreviewed'
default='Unreviewed',
on_delete=models.DO_NOTHING
)

manager_status = models.ForeignKey(
ComplianceReportStatus,
null=False,
related_name='+',
to_field='status',
default='Unreviewed'
default='Unreviewed',
on_delete=models.DO_NOTHING
)

director_status = models.ForeignKey(
ComplianceReportStatus,
null=False,
related_name='+',
to_field='status',
default='Unreviewed'
default='Unreviewed',
on_delete=models.DO_NOTHING
)

class Meta:
Expand Down
5 changes: 3 additions & 2 deletions backend/api/models/ComplianceReportSnapshot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.contrib.postgres.fields import JSONField
from django.db.models import JSONField
from django.core.serializers.json import DjangoJSONEncoder
from django.db import models

Expand All @@ -20,7 +20,8 @@ class ComplianceReportSnapshot(Auditable):

compliance_report = models.OneToOneField(
'ComplianceReport',
related_name=None
related_name=None,
on_delete=models.DO_NOTHING
)

class Meta:
Expand Down
3 changes: 2 additions & 1 deletion backend/api/models/DocumentType.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class DocumentType(Auditable, EffectiveDates):
blank=False,
null=False,
unique=False,
related_name='types'
related_name='types',
on_delete=models.DO_NOTHING
)

objects = TheTypeManager()
Expand Down
3 changes: 2 additions & 1 deletion backend/api/nocache.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import re

from django.utils.cache import add_never_cache_headers
from django.utils.deprecation import MiddlewareMixin


class NoCacheMiddleware(object):
class NoCacheMiddleware(MiddlewareMixin):
"""Add No-cache headers to all responses if detect IE UA"""

IE_DETECTION_RE = [
Expand Down
14 changes: 12 additions & 2 deletions backend/api/services/ComplianceReportSpreadSheet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import xlwt

from collections import namedtuple, defaultdict
from decimal import Decimal

import xlwt
from api.models.FuelCode import FuelCode


class ComplianceReportSpreadsheet(object):
Expand Down Expand Up @@ -114,7 +116,15 @@ def add_schedule_b(self, schedule_b):
worksheet.write(row_index, 1, record['fuel_class'])
worksheet.write(row_index, 2, record['provision_of_the_act'])
if record['fuel_code'] is not None:
worksheet.write(row_index, 3, record['fuel_code'])
fuel_code_id = record['fuel_code']
fuel_code = FuelCode.objects.filter(id=fuel_code_id).first()
if fuel_code:
fuel_code_string = fuel_code.fuel_code + \
str(fuel_code.fuel_code_version) + '.' + \
str(fuel_code.fuel_code_version_minor)
worksheet.write(row_index, 3, fuel_code_string)
else:
worksheet.write(row_index, 3, record['fuel_code'])
else:
if record['schedule_d_sheet_index'] is not None:
worksheet.write(row_index, 3, 'From Schedule D')
Expand Down
6 changes: 3 additions & 3 deletions backend/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@
ROUTER.register(r'users', UserViewSet)
ROUTER.register(r'notifications',
NotificationViewSet,
base_name='notification')
basename='notification')

ROUTER.register(r'autocomplete',
AutocompleteViewSet,
base_name='autocomplete')
basename='autocomplete')

ROUTER.register(r'autosave',
AutosaveViewSet,
base_name='autosave')
basename='autosave')

if DOCUMENTS_API['ENABLED'] or TESTING:
ROUTER.register(r'documents', DocumentViewSet)
Expand Down
4 changes: 2 additions & 2 deletions backend/api/viewsets/Autosave.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.utils import timezone

from django.http import JsonResponse, HttpResponse
from rest_framework.decorators import list_route
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
from rest_framework.status import HTTP_200_OK, HTTP_202_ACCEPTED, HTTP_404_NOT_FOUND

Expand Down Expand Up @@ -32,7 +32,7 @@ def list(self, request):

return JsonResponse(serializer.data, status=HTTP_200_OK)

@list_route(methods=['post'])
@action(detail=False, methods=['post'])
def clear(self, request):
user = self.request.user
AutosavedFormData.objects.filter(user=user).all().delete()
Expand Down
12 changes: 6 additions & 6 deletions backend/api/viewsets/ComplianceReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.db.models import Count
from django.http import JsonResponse, HttpResponse
from rest_framework import viewsets, mixins, filters, status
from rest_framework.decorators import list_route, detail_route
from rest_framework.decorators import action
from rest_framework.permissions import AllowAny
from rest_framework.response import Response

Expand Down Expand Up @@ -162,7 +162,7 @@ def list(self, request, *args, **kwargs):
serializer = self.get_serializer(sorted_qs, many=True, context={'request': request})
return Response(serializer.data)

@list_route(methods=['get'], permission_classes=[AllowAny])
@action(detail=False, methods=['get'], permission_classes=[AllowAny])
def types(self, request):
"""
Gets the list of types that a compliance report can be
Expand All @@ -174,7 +174,7 @@ def types(self, request):

return Response(serializer.data)

@detail_route(methods=['post'])
@action(detail=True, methods=['post'])
def validate_partial(self, request, pk=None):
instance = self.get_object()

Expand All @@ -188,7 +188,7 @@ def validate_partial(self, request, pk=None):

return Response(serializer.errors)

@detail_route(methods=['GET'])
@action(detail=True, methods=['GET'])
def snapshot(self, request, pk=None):
obj = self.get_object()

Expand All @@ -198,7 +198,7 @@ def snapshot(self, request, pk=None):

return Response(snapshot.snapshot)

@detail_route(methods=['patch'])
@action(detail=True, methods=['patch'])
def compute_totals(self, request, pk=None):
"""
This works much like a regular PATCH, but rolls back the transaction
Expand Down Expand Up @@ -232,7 +232,7 @@ def compute_totals(self, request, pk=None):

return Response(result)

@detail_route(methods=['get'])
@action(detail=True, methods=['get'])
def xls(self, request, pk=None):
"""
Exports the compliance report as a spreadsheet
Expand Down
23 changes: 12 additions & 11 deletions backend/api/viewsets/CreditTrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

from django.db.models import Q
from django.http import HttpResponse
from django.utils.decorators import method_decorator
from django.shortcuts import get_object_or_404

from rest_framework import viewsets, permissions, status, mixins
from rest_framework.decorators import list_route, detail_route
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework import filters

Expand Down Expand Up @@ -76,7 +77,7 @@ def get_queryset(self):
return CreditTradeService.get_organization_credit_trades(
user.organization)

@permission_required('VIEW_CREDIT_TRANSFERS')
@method_decorator(permission_required('VIEW_CREDIT_TRANSFERS'))
def list(self, request, *args, **kwargs):
"""
Shows the credit transfers for the current organization.
Expand Down Expand Up @@ -151,7 +152,7 @@ def perform_update(self, serializer):
CreditTradeService.dispatch_notifications(
previous_state, credit_trade)

@detail_route(methods=['put'])
@action(detail=True, methods=['put'])
def delete(self, request, pk=None):
"""
Marks the Credit Trade as Cancelled
Expand All @@ -163,8 +164,8 @@ def delete(self, request, pk=None):

return Response(None, status=status.HTTP_200_OK)

@detail_route(methods=['put'])
@permission_required('APPROVE_CREDIT_TRANSFER')
@action(detail=True, methods=['put'])
@method_decorator(permission_required('APPROVE_CREDIT_TRANSFER'))
def approve(self, request, pk=None):
"""
Marks the Credit Trade as Approved
Expand Down Expand Up @@ -192,8 +193,8 @@ def approve(self, request, pk=None):

return Response(serializer.data, status=status.HTTP_200_OK)

@list_route(methods=['get'])
@permission_required('VIEW_APPROVED_CREDIT_TRANSFERS')
@action(detail=False, methods=['get'])
@method_decorator(permission_required('VIEW_APPROVED_CREDIT_TRANSFERS'))
def list_recorded(self, request):
"""
Returns a list of Recorded Credit Trades only
Expand All @@ -207,8 +208,8 @@ def list_recorded(self, request):

return Response(serializer.data)

@list_route(methods=['put'])
@permission_required('USE_HISTORICAL_DATA_ENTRY')
@action(detail=False, methods=['put'])
@method_decorator(permission_required('USE_HISTORICAL_DATA_ENTRY'))
def batch_process(self, request):
"""
Call the approve function on multiple Credit Trades
Expand All @@ -231,8 +232,8 @@ def batch_process(self, request):
"Approved credit transactions have been processed."},
status=status.HTTP_200_OK)

@list_route(methods=['get'])
@permission_required('VIEW_CREDIT_TRANSFERS')
@action(detail=False, methods=['get'])
@method_decorator(permission_required('VIEW_CREDIT_TRANSFERS'))
def xls(self, request):
"""
Exports the credit transfers and organizations table
Expand Down
2 changes: 1 addition & 1 deletion backend/api/viewsets/CreditTradeHistory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""
from django.db.models import Q
from rest_framework import filters, mixins, viewsets
from rest_framework.decorators import list_route
from rest_framework.decorators import action
from rest_framework.response import Response

from api.models.CreditTradeHistory import CreditTradeHistory
Expand Down
Loading

0 comments on commit 391e177

Please sign in to comment.