diff options
Diffstat (limited to 'django/engagementmanager/rest')
29 files changed, 461 insertions, 320 deletions
diff --git a/django/engagementmanager/rest/__init__.py b/django/engagementmanager/rest/__init__.py index 1726c13..16f81cb 100644 --- a/django/engagementmanager/rest/__init__.py +++ b/django/engagementmanager/rest/__init__.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/engagementmanager/rest/activation.py b/django/engagementmanager/rest/activation.py index 3499b95..ed6c4d5 100644 --- a/django/engagementmanager/rest/activation.py +++ b/django/engagementmanager/rest/activation.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -48,8 +48,10 @@ from engagementmanager.decorator.log_func_entry import logFuncEntry from engagementmanager.models import IceUserProfile from engagementmanager.rest.vvp_api_view import VvpApiView from engagementmanager.utils.constants import Constants -from engagementmanager.utils.vvp_exceptions import VvpObjectNotAvailable, VvpGeneralException, VvpBadRequest -from engagementmanager.views_helper import generateActivationLink, getFirstEngByUser +from engagementmanager.utils.vvp_exceptions \ + import VvpObjectNotAvailable, VvpGeneralException, VvpBadRequest +from engagementmanager.views_helper \ + import generateActivationLink, getFirstEngByUser from engagementmanager.vm_integration import vm_client from engagementmanager.service.logging_service import LoggingServiceFactory @@ -63,8 +65,9 @@ class ResendActivationMail(VvpApiView): def get(self, request, user_uuid, format=None): ice_user_obj = IceUserProfile.objects.get(uuid=user_uuid) - data = {'activation_link': generateActivationLink(ice_user_obj.user.activation_token, ice_user_obj), - 'full_name': ice_user_obj.full_name} + data = {'activation_link': generateActivationLink( + ice_user_obj.user.activation_token, ice_user_obj), + 'full_name': ice_user_obj.full_name} # updating the activation time ice_user_obj.user.activation_token_create_time = timezone.now() @@ -72,10 +75,12 @@ class ResendActivationMail(VvpApiView): ice_user_obj.save() self.logger.debug("Activation Link: " + data['activation_link']) - body = get_template("{activate_template_dir}activate_mail_body.html".format( - activate_template_dir=Constants.activate_template_dir)) - subject = get_template("{activate_template_dir}activate_mail_subject.html".format( - activate_template_dir=Constants.activate_template_dir)) + body = get_template( + "{activate_template_dir}activate_mail_body.html".format( + activate_template_dir=Constants.activate_template_dir)) + subject = get_template( + "{activate_template_dir}activate_mail_subject.html".format( + activate_template_dir=Constants.activate_template_dir)) mail.sendMail(ice_user_obj.email, data, body, subject) return Response() @@ -98,18 +103,22 @@ class ActivateUser(VvpApiView): if user.activation_token != kwargs['token']: raise VvpBadRequest( - "User's activation token is not equal to the token in the activation path param.") + "User's activation token is not equal to the \ + token in the activation path param.") created = user.activation_token_create_time current = timezone.now() - if created.year == current.year and created.month == current.month and (created.day == current.day or - created.day == current.day - 1): + if created.year == current.year and created.month == current.month \ + and (created.day == current.day or + created.day == current.day - 1): delta = current - created - if abs(delta).total_seconds() / 3600.0 <= settings.TOKEN_EXPIRATION_IN_HOURS: + if abs(delta).total_seconds() / 3600.0 <= \ + settings.TOKEN_EXPIRATION_IN_HOURS: user.is_active = True user.save() self.logger.debug( - "User " + user_profile.full_name + " is activated successfully, redirecting to Login") + "User " + user_profile.full_name + " is activated successfully, \ + redirecting to Login") user = IceUserProfile.objects.get(email=user.email) eng = getFirstEngByUser(user) result = {'activation_success': True, } @@ -119,5 +128,5 @@ class ActivateUser(VvpApiView): return Response(result) else: raise SignatureExpired("User's activation token expired.") - + return Response({'activation_success': False, }) diff --git a/django/engagementmanager/rest/activity.py b/django/engagementmanager/rest/activity.py index 47b4cc7..e2502da 100644 --- a/django/engagementmanager/rest/activity.py +++ b/django/engagementmanager/rest/activity.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -60,6 +60,7 @@ class PullActivities(VvpApiView): if not num: num = settings.NUMBER_OF_POLLED_ACTIVITIES eng = Engagement.objects.get(uuid=request_data_mgr.get_eng_uuid()) - activities = self.activities_service.pull_recent_activities(eng, recent_activities_limit=num) + activities = self.activities_service.pull_recent_activities( + eng, recent_activities_limit=num) serializer = ActivityModelSerializer(activities, many=True) return Response(serializer.data) diff --git a/django/engagementmanager/rest/checklist.py b/django/engagementmanager/rest/checklist.py index 200dcaa..daa69e2 100644 --- a/django/engagementmanager/rest/checklist.py +++ b/django/engagementmanager/rest/checklist.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -36,8 +36,6 @@ # ============LICENSE_END============================================ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. -import json - from rest_framework.response import Response from rest_framework.status import HTTP_400_BAD_REQUEST,\ HTTP_500_INTERNAL_SERVER_ERROR @@ -71,8 +69,9 @@ class NewCheckList(VvpApiView): data = request.data if ('checkListName' not in data or not data['checkListName'] or - 'checkListTemplateUuid' not in data or not data['checkListTemplateUuid'] or - 'checkListAssociatedFiles' not in data): + 'checkListTemplateUuid' not in data or + not data['checkListTemplateUuid'] or + 'checkListAssociatedFiles' not in data): msg = "One of the CheckList's input parameters is missing" self.logger.error(msg) return Response(msg, status=HTTP_400_BAD_REQUEST) @@ -83,7 +82,8 @@ class NewCheckList(VvpApiView): return Response(msg, status=HTTP_400_BAD_REQUEST) data = CheckListSvc().createOrUpdateChecklist( - data['checkListName'], data['checkListTemplateUuid'], data['checkListAssociatedFiles'], None) + data['checkListName'], data['checkListTemplateUuid'], + data['checkListAssociatedFiles'], None) return Response(data) @@ -107,9 +107,10 @@ class ExistingCheckList(VvpApiView): def put(self, request, checklistUuid): data = request.data if ('checklistUuid' not in data or not data['checklistUuid'] or - 'checkListName' not in data or not data['checkListName'] or - 'checkListTemplateUuid' not in data or not data['checkListTemplateUuid'] or - 'checkListAssociatedFiles' not in data): + 'checkListName' not in data or not data['checkListName'] or + 'checkListTemplateUuid' not in data or + not data['checkListTemplateUuid'] or + 'checkListAssociatedFiles' not in data): msg = "One of the CheckList's input parameters is missing" self.logger.error(msg) return Response(msg, status=HTTP_400_BAD_REQUEST) @@ -119,7 +120,8 @@ class ExistingCheckList(VvpApiView): return Response(msg, status=HTTP_400_BAD_REQUEST) data = CheckListSvc().createOrUpdateChecklist( - data['checkListName'], data['checkListTemplateUuid'], data['checkListAssociatedFiles'], data['checklistUuid']) + data['checkListName'], data['checkListTemplateUuid'], + data['checkListAssociatedFiles'], data['checklistUuid']) return Response(data) diff --git a/django/engagementmanager/rest/checklist_audit_log.py b/django/engagementmanager/rest/checklist_audit_log.py index 4b86a33..62aafdf 100644 --- a/django/engagementmanager/rest/checklist_audit_log.py +++ b/django/engagementmanager/rest/checklist_audit_log.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -36,7 +36,6 @@ # ============LICENSE_END============================================ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. -import json from rest_framework.response import Response @@ -46,8 +45,9 @@ from engagementmanager.decorator.log_func_entry import logFuncEntry from engagementmanager.models import ChecklistDecision, Checklist from engagementmanager.rest.vvp_api_view import VvpApiView from engagementmanager.service.authorization_service import Permissions -from engagementmanager.service.checklist_audit_log_service import getAuditLogsWithChecklist, \ - addAuditLogToChecklist, getAuditLogsWithDecision, addAuditLogToDecision +from engagementmanager.service.checklist_audit_log_service \ + import getAuditLogsWithChecklist, addAuditLogToChecklist, \ + getAuditLogsWithDecision, addAuditLogToDecision from engagementmanager.utils.request_data_mgr import request_data_mgr @@ -68,7 +68,8 @@ class ChecklistAuditLog(VvpApiView): checklistUuid = request_data_mgr.get_cl_uuid() if ('description' not in data or not data['description']): - msg = "description for the audit log is not provided in the request's body" + msg = "description for the audit log is " +\ + "not provided in the request's body" self.logger.error(msg) raise KeyError(msg) description = data['description'] diff --git a/django/engagementmanager/rest/checklist_decision.py b/django/engagementmanager/rest/checklist_decision.py index a0cfe01..5a965de 100644 --- a/django/engagementmanager/rest/checklist_decision.py +++ b/django/engagementmanager/rest/checklist_decision.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -46,7 +46,8 @@ from engagementmanager.decorator.class_decorator import classDecorator from engagementmanager.decorator.log_func_entry import logFuncEntry from engagementmanager.rest.vvp_api_view import VvpApiView from engagementmanager.service.authorization_service import Permissions -from engagementmanager.service.checklist_decision_service import setDecision, getDecision +from engagementmanager.service.checklist_decision_service import setDecision, \ + getDecision from engagementmanager.utils.request_data_mgr import request_data_mgr diff --git a/django/engagementmanager/rest/checklist_set_state.py b/django/engagementmanager/rest/checklist_set_state.py index e9c6eb3..ceadf18 100644 --- a/django/engagementmanager/rest/checklist_set_state.py +++ b/django/engagementmanager/rest/checklist_set_state.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -59,9 +59,13 @@ class ChecklistState(VvpApiView): decline = data['decline'] if decline == "True": checklist = set_state(True, request_data_mgr.get_cl_uuid(), - isMoveToAutomation=False, description=data['description']) + isMoveToAutomation=False, + description=data['description']) else: - checklist = set_state(False, request_data_mgr.get_cl_uuid(), description=data['description']) + checklist = set_state( + False, request_data_mgr.get_cl_uuid(), + description=data['description']) - cldata = json.dumps(SuperThinChecklistModelSerializer(checklist).data, ensure_ascii=False) + cldata = json.dumps(SuperThinChecklistModelSerializer( + checklist).data, ensure_ascii=False) return Response(cldata) diff --git a/django/engagementmanager/rest/cms/__init__.py b/django/engagementmanager/rest/cms/__init__.py index 1726c13..16f81cb 100644 --- a/django/engagementmanager/rest/cms/__init__.py +++ b/django/engagementmanager/rest/cms/__init__.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/engagementmanager/rest/cms/pages.py b/django/engagementmanager/rest/cms/pages.py index efe0b4e..bef4962 100644 --- a/django/engagementmanager/rest/cms/pages.py +++ b/django/engagementmanager/rest/cms/pages.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/engagementmanager/rest/cms/posts.py b/django/engagementmanager/rest/cms/posts.py index 17e33fb..d808156 100644 --- a/django/engagementmanager/rest/cms/posts.py +++ b/django/engagementmanager/rest/cms/posts.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -47,11 +47,12 @@ from engagementmanager.service.cms.posts_service import CMSPostsService @classDecorator([logFuncEntry]) class Posts(VvpApiView): - def get(self, request, format=None, **kwargs): + def get(self, request): categoryParam = request.GET.get('category', "") limitParam = request.GET.get('limit', 5) offsetParam = request.GET.get('offset', 0) fromLastDaysParam = request.GET.get('fromLastDays', None) - posts = CMSPostsService().getPosts(offsetParam, limitParam, fromLastDaysParam, categoryParam) + posts = CMSPostsService().getPosts(offsetParam, limitParam, + fromLastDaysParam, categoryParam) return Response(posts) diff --git a/django/engagementmanager/rest/csrf_exempt_session_authentication.py b/django/engagementmanager/rest/csrf_exempt_session_authentication.py index 89a6243..ac26492 100644 --- a/django/engagementmanager/rest/csrf_exempt_session_authentication.py +++ b/django/engagementmanager/rest/csrf_exempt_session_authentication.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/engagementmanager/rest/data_loader.py b/django/engagementmanager/rest/data_loader.py index 11e8dfc..7ee7e70 100644 --- a/django/engagementmanager/rest/data_loader.py +++ b/django/engagementmanager/rest/data_loader.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -36,7 +36,6 @@ # ============LICENSE_END============================================ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. -import json from uuid import uuid4 from django.utils import timezone @@ -56,17 +55,27 @@ class EngLeadsDataLoader(VvpApiView): def get(self, request): data = request.data - service_provider_company = Vendor.objects.get(name=Constants.service_provider_company_name) + service_provider_company = Vendor.objects.get( + name=Constants.service_provider_company_name) el_role = Role.objects.get(name="el") for el in data: user_object = CustomUser.objects.create_user( - username=el['full_name'], email=el['full_name'], password=el['password'], is_active=False, activation_token=uuid4(), activation_token_create_time=timezone.now()) - data = createUserTemplate(service_provider_company, el['full_name'], el_role, '', True, None, True, user_object) - el_user, is_profile_created = IceUserProfile.objects.update_or_create( - email=user_object.email, defaults=data) + username=el['full_name'], email=el['full_name'], + password=el['password'], is_active=False, + activation_token=uuid4(), + activation_token_create_time=timezone.now()) + data = createUserTemplate( + service_provider_company, el['full_name'], el_role, '', + True, None, True, user_object) + el_user, is_profile_created = \ + IceUserProfile.objects.update_or_create( + email=user_object.email, defaults=data) self.logger.info("User: " + el_user.full_name + - " was created successfully during bulk_load_engagement_leads function") - self.logger.info("All users were created successfully during bulk_load_engagement_leads function") + " was created successfully during \ + bulk_load_engagement_leads function") + self.logger.info( + "All users were created successfully during \ + bulk_load_engagement_leads function") return Response() @@ -76,7 +85,12 @@ class CompaniesDataLoader(VvpApiView): def get(self, request): data = request.data for vendor in data: - Vendor.objects.get_or_create(name=vendor['name'], defaults={'public': True}) - self.logger.info('Company found or created during bulk load vendors: ' + logEncoding(vendor)) - self.logger.info("All companies were created successfully during bulk_load_companies function") + Vendor.objects.get_or_create( + name=vendor['name'], defaults={'public': True}) + self.logger.info( + 'Company found or created during bulk load vendors: ' + + logEncoding(vendor)) + self.logger.info( + "All companies were created successfully during \ + bulk_load_companies function") return Response() diff --git a/django/engagementmanager/rest/deployment_target.py b/django/engagementmanager/rest/deployment_target.py index c52d9b9..4eaa625 100644 --- a/django/engagementmanager/rest/deployment_target.py +++ b/django/engagementmanager/rest/deployment_target.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -45,7 +45,8 @@ from engagementmanager.decorator.log_func_entry import logFuncEntry from engagementmanager.models import DeploymentTarget from engagementmanager.rest.vvp_api_view import VvpApiView from engagementmanager.serializers import DeploymentTargetModelSerializer -from engagementmanager.service.deploment_target_service import update_deployment_target +from engagementmanager.service.deploment_target_service \ + import update_deployment_target @classDecorator([logFuncEntry]) @@ -58,12 +59,16 @@ class DeploymentTargetRESTMethods(VvpApiView): update_deployment_target(engagement_uuid, dt_uuid) return Response(msg) else: - msg = "DTarget PUT Request failed, engagement_uuid wasn't found in kwargs or its content is empty, therefore cannot filter by it to find the required VF" + msg = "DTarget PUT Request failed, engagement_uuid wasn't found \ + in kwargs or its content is empty, therefore cannot filter by it \ + to find the required VF" self.logger.error(msg) msg = "Action failed." return Response(msg, status=HTTP_400_BAD_REQUEST) def get(self, request): - deployment_targets = DeploymentTarget.objects.filter(ui_visibility=True).order_by('weight') - serializer = DeploymentTargetModelSerializer(deployment_targets, many=True) + deployment_targets = DeploymentTarget.objects.filter( + ui_visibility=True).order_by('weight') + serializer = DeploymentTargetModelSerializer( + deployment_targets, many=True) return Response(serializer.data) diff --git a/django/engagementmanager/rest/deployment_target_site.py b/django/engagementmanager/rest/deployment_target_site.py index 32ff5a4..748871e 100644 --- a/django/engagementmanager/rest/deployment_target_site.py +++ b/django/engagementmanager/rest/deployment_target_site.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -44,7 +44,8 @@ from engagementmanager.decorator.class_decorator import classDecorator from engagementmanager.decorator.log_func_entry import logFuncEntry from engagementmanager.models import VF, DeploymentTargetSite from engagementmanager.rest.vvp_api_view import VvpApiView -from engagementmanager.serializers import ThinDeploymentTargetSiteModelSerializer +from engagementmanager.serializers import \ + ThinDeploymentTargetSiteModelSerializer from engagementmanager.service.authorization_service import Permissions @@ -56,16 +57,19 @@ class DTSites(VvpApiView): if vf_uuid: vf = VF.objects.get(uuid=vf_uuid) dtsites = vf.deployment_target_sites - serializer = ThinDeploymentTargetSiteModelSerializer(dtsites, many=True) + serializer = ThinDeploymentTargetSiteModelSerializer( + dtsites, many=True) return Response(serializer.data) else: dtsites = DeploymentTargetSite.objects.all() - serializer = ThinDeploymentTargetSiteModelSerializer(dtsites, many=True) + serializer = ThinDeploymentTargetSiteModelSerializer( + dtsites, many=True) return Response(serializer.data) """ expecting: VF object uuid, DeploymentTargetSite uuid - result: addition of the DeploymentTargetSite object with dtsite_uuid to the VF's deployment_target_sites + result: addition of the DeploymentTargetSite object with dtsite_uuid \ + to the VF's deployment_target_sites """ @auth(Permissions.add_deployment_target_site) def post(self, request): @@ -76,7 +80,8 @@ class DTSites(VvpApiView): try: dtsite = DeploymentTargetSite.objects.get(name=name) - msg = "DTSite was already existed, hence would next be added to the VF's sites list" + msg = "DTSite was already existed, hence would next be \ + added to the VF's sites list" except DeploymentTargetSite.DoesNotExist: dtsite = DeploymentTargetSite.objects.create(name=name) dtsite.save() diff --git a/django/engagementmanager/rest/ecomp.py b/django/engagementmanager/rest/ecomp.py index a2585ac..0632ee4 100644 --- a/django/engagementmanager/rest/ecomp.py +++ b/django/engagementmanager/rest/ecomp.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -38,7 +38,7 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response -from rest_framework.status import HTTP_400_BAD_REQUEST, HTTP_202_ACCEPTED +from rest_framework.status import HTTP_400_BAD_REQUEST from engagementmanager.decorator.class_decorator import classDecorator from engagementmanager.decorator.log_func_entry import logFuncEntry @@ -58,12 +58,15 @@ class ECOMPReleaseRESTMethods(VvpApiView): update_ECOMP(engagement_uuid, ecomp_uuid) return Response(msg) else: - msg = "ECOMPRelease PUT Request failed, engagement_uuid wasn't found in kwargs or its content is empty, therefore cannot filter by it to find the required VF" + msg = "ECOMPRelease PUT Request failed, engagement_uuid wasn't \ + found in kwargs or its content is empty, therefore cannot filter \ + by it to find the required VF" self.logger.error(msg) msg = "Action failed." return Response(msg, status=HTTP_400_BAD_REQUEST) def get(self, request): - ecomp_releases = ECOMPRelease.objects.filter(ui_visibility=True).order_by('weight') + ecomp_releases = ECOMPRelease.objects.filter( + ui_visibility=True).order_by('weight') serializer = ECOMPReleaseModelSerializer(ecomp_releases, many=True) return Response(serializer.data) diff --git a/django/engagementmanager/rest/engagement.py b/django/engagementmanager/rest/engagement.py index 89e74fe..c557cd5 100644 --- a/django/engagementmanager/rest/engagement.py +++ b/django/engagementmanager/rest/engagement.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -51,8 +51,8 @@ from engagementmanager.serializers import VFModelSerializer, \ EngagementStatusModelSerializer from engagementmanager.service.authorization_service import Permissions from engagementmanager.service import engagement_service as eng_svc -from engagementmanager.utils.constants import Roles, RecentEngagementActionType, \ - CheckListState, EngagementStage +from engagementmanager.utils.constants import Roles, \ + RecentEngagementActionType, CheckListState, EngagementStage from engagementmanager.utils.request_data_mgr import request_data_mgr from engagementmanager.utils.validator import logEncoding from rest_framework.response import Response @@ -69,14 +69,17 @@ class ExpandedEngByUser(VvpApiView): if ('stage' not in data or not data['stage'] or 'keyword' not in data or 'offset' not in data or int(data['offset']) < 0 - or 'limit' not in data or not data['limit'] or (data['limit'] < 1)): - msg = "GetExpandedEngByUser - get request: one of the parameters is missing or invalid." + or 'limit' not in data or not data['limit'] or + (data['limit'] < 1)): + msg = "GetExpandedEngByUser - get request: one of the parameters \ + is missing or invalid." self.logger.error(msg) msg = "Action was failed due to bad request." return Response(msg, status=HTTP_400_BAD_REQUEST) user = request_data_mgr.get_user() data = eng_svc.get_dashboard_expanded_engs( - data['stage'], data['keyword'], data['offset'], data['limit'], user) + data['stage'], data['keyword'], data['offset'], + data['limit'], user) return Response(data) @@ -95,7 +98,8 @@ class ExportEngagements(VvpApiView): stageParam = request.GET['stage'] keywordParam = request.GET['keyword'] - # data, status = eng_svc.get_dashboard_expanded_engs(stageParam, keywordParam, 0, sys.maxint, user) + # data, status = eng_svc.get_dashboard_expanded_engs + # (stageParam, keywordParam, 0, sys.maxint, user) vfs, deployment_targets = eng_svc.get_expanded_engs_for_export( stageParam, keywordParam, user) @@ -103,92 +107,96 @@ class ExportEngagements(VvpApiView): # Create 'Validation Details' sheet and fill it up with required data: validationWorkSheet = workbook.create_sheet() validationWorkSheet.title = 'Validation Details' - headlines = [WriteOnlyCell(validationWorkSheet, value=u"EId"), - WriteOnlyCell(validationWorkSheet, value=u"Engagement"), - WriteOnlyCell(validationWorkSheet, value=u"Reviewer"), - WriteOnlyCell( - validationWorkSheet, value=u"Peer reviewer"), - WriteOnlyCell(validationWorkSheet, value=u"VFC"), - WriteOnlyCell(validationWorkSheet, value=u"VFC #"), - WriteOnlyCell(validationWorkSheet, value=u"Started"), - WriteOnlyCell(validationWorkSheet, value=u"Vendor"), - WriteOnlyCell(validationWorkSheet, value=u"AIC Version"), - WriteOnlyCell( - validationWorkSheet, value=u"ECOMP Release"), - WriteOnlyCell(validationWorkSheet, value=u"Validate"), - WriteOnlyCell(validationWorkSheet, value=u"Completed"), - WriteOnlyCell(validationWorkSheet, value=u"Stage"), - WriteOnlyCell( - validationWorkSheet, value=u"Heat Pre-validated"), - WriteOnlyCell(validationWorkSheet, value=u"Image Scan"), - WriteOnlyCell( - validationWorkSheet, value=u"AIC Instantiated"), - WriteOnlyCell( - validationWorkSheet, value=u"ASDC Onboarded"), - WriteOnlyCell( - validationWorkSheet, value=u"Overall Progress in %"), - WriteOnlyCell( - validationWorkSheet, value=u"Target Completion Date"), - WriteOnlyCell(validationWorkSheet, value=u"Status")] + headlines = [ + WriteOnlyCell(validationWorkSheet, value=u"EId"), + WriteOnlyCell(validationWorkSheet, value=u"Engagement"), + WriteOnlyCell(validationWorkSheet, value=u"Reviewer"), + WriteOnlyCell( + validationWorkSheet, value=u"Peer reviewer"), + WriteOnlyCell(validationWorkSheet, value=u"VFC"), + WriteOnlyCell(validationWorkSheet, value=u"VFC #"), + WriteOnlyCell(validationWorkSheet, value=u"Started"), + WriteOnlyCell(validationWorkSheet, value=u"Vendor"), + WriteOnlyCell(validationWorkSheet, value=u"AIC Version"), + WriteOnlyCell( + validationWorkSheet, value=u"ECOMP Release"), + WriteOnlyCell(validationWorkSheet, value=u"Validate"), + WriteOnlyCell(validationWorkSheet, value=u"Completed"), + WriteOnlyCell(validationWorkSheet, value=u"Stage"), + WriteOnlyCell( + validationWorkSheet, value=u"Heat Pre-validated"), + WriteOnlyCell(validationWorkSheet, value=u"Image Scan"), + WriteOnlyCell( + validationWorkSheet, value=u"AIC Instantiated"), + WriteOnlyCell( + validationWorkSheet, value=u"ASDC Onboarded"), + WriteOnlyCell( + validationWorkSheet, value=u"Overall Progress in %"), + WriteOnlyCell( + validationWorkSheet, value=u"Target Completion Date"), + WriteOnlyCell(validationWorkSheet, value=u"Status")] for headline in headlines: headline.font = Font(name='Courier', size=16, bold=True) validationWorkSheet.append(headlines) for vf in vfs: - validationWorkSheet.append([smart_str(vf["engagement__engagement_manual_id"]), - smart_str(vf["vf__name"]), - smart_str( - vf["vf_engagement__reviewer"]), - smart_str( - vf["vf_engagement__peer_reviewer"]), - smart_str(vf["vfcs"]), - smart_str(vf["vfcs__number"]), - smart_str( - vf["engagement__started_state_time"]), - smart_str(vf["vendor__name"]), - smart_str( - vf["deployment_target__version"]), - smart_str(vf["ecomp_release__name"]), - smart_str( - vf["engagement__validated_time"]), - smart_str( - vf["engagement__completed_time"]), - smart_str( - vf["engagement__engagement_stage"]), - smart_str( - vf["engagement__heat_validated_time"]), - smart_str( - vf["engagement__image_scan_time"]), - smart_str( - vf["engagement__aic_instantiation_time"]), - smart_str( - vf["engagement__asdc_onboarding_time"]), - smart_str(vf["engagement__progress"]), - smart_str( - vf["engagement__target_completion_date"]), - smart_str( - vf["engagement__latest_status"]) - ]) + validationWorkSheet.append( + [smart_str(vf["engagement__engagement_manual_id"]), + smart_str(vf["vf__name"]), + smart_str( + vf["vf_engagement__reviewer"]), + smart_str( + vf["vf_engagement__peer_reviewer"]), + smart_str(vf["vfcs"]), + smart_str(vf["vfcs__number"]), + smart_str( + vf["engagement__started_state_time"]), + smart_str(vf["vendor__name"]), + smart_str( + vf["deployment_target__version"]), + smart_str(vf["ecomp_release__name"]), + smart_str( + vf["engagement__validated_time"]), + smart_str( + vf["engagement__completed_time"]), + smart_str( + vf["engagement__engagement_stage"]), + smart_str( + vf["engagement__heat_validated_time"]), + smart_str( + vf["engagement__image_scan_time"]), + smart_str( + vf["engagement__aic_instantiation_time"]), + smart_str( + vf["engagement__asdc_onboarding_time"]), + smart_str(vf["engagement__progress"]), + smart_str( + vf["engagement__target_completion_date"]), + smart_str( + vf["engagement__latest_status"]) + ]) # Create 'Overview' sheet and fill it up with required data: overviewWorkSheet = workbook.create_sheet() overviewWorkSheet.title = 'Overview' - headlines = [WriteOnlyCell(validationWorkSheet, value=u"AIC/ECOMP"), - WriteOnlyCell( - validationWorkSheet, value=u"Active Count of Engagement"), - WriteOnlyCell( - validationWorkSheet, value=u"Sum of Nr of VFs"), - WriteOnlyCell( - validationWorkSheet, value=u"Intake Count of Engagement"), - WriteOnlyCell( - validationWorkSheet, value=u"Sum of Nr of VFs"), - WriteOnlyCell( - validationWorkSheet, value=u"Completed Count of Engagement"), - WriteOnlyCell( - validationWorkSheet, value=u"Sum of Nr of VFs"), - WriteOnlyCell( - validationWorkSheet, value=u"Total Count of Engagement"), - WriteOnlyCell(validationWorkSheet, value=u"Total Sum of Nr of VFs")] + headlines = [ + WriteOnlyCell(validationWorkSheet, value=u"AIC/ECOMP"), + WriteOnlyCell( + validationWorkSheet, value=u"Active Count of Engagement"), + WriteOnlyCell( + validationWorkSheet, value=u"Sum of Nr of VFs"), + WriteOnlyCell( + validationWorkSheet, value=u"Intake Count of Engagement"), + WriteOnlyCell( + validationWorkSheet, value=u"Sum of Nr of VFs"), + WriteOnlyCell( + validationWorkSheet, value=u"Completed Count of Engagement"), + WriteOnlyCell( + validationWorkSheet, value=u"Sum of Nr of VFs"), + WriteOnlyCell( + validationWorkSheet, value=u"Total Count of Engagement"), + WriteOnlyCell(validationWorkSheet, + value=u"Total Sum of Nr of VFs")] for headline in headlines: headline.font = Font(name='Courier', size=16, bold=True) overviewWorkSheet.append(headlines) @@ -196,10 +204,12 @@ class ExportEngagements(VvpApiView): for deployment_target in deployment_targets: overviewWorkSheet.append(deployment_target) - # We are using HttpResponse and not Rest Response since we couldnt find + # We are using HttpResponse and not + # Rest Response since we couldnt find # support for content diposition response = HttpResponse( - content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') + content_type='application/vnd.openxmlformats-officedocument.\ + spreadsheetml.sheet') response['Content-Disposition'] = 'attachment; filename=D2ICE.xlsx' workbook.save(response) @@ -215,12 +225,15 @@ class GetEngByUser(VvpApiView): user = request_data_mgr.get_user() vf_list = [] - engStageList = [EngagementStage.Intake.name, EngagementStage.Active.name, - EngagementStage.Validated.name, EngagementStage.Completed.name] # @UndefinedVariable + engStageList = [ + EngagementStage.Intake.name, EngagementStage.Active.name, + EngagementStage.Validated.name, EngagementStage.Completed.name] # @UndefinedVariable - if (user.role.name == Roles.admin.name or user.role.name == Roles.admin_ro.name): - vf_list = VF.objects.filter(engagement__engagement_stage__in=engStageList)\ + if (user.role.name == Roles.admin.name or + user.role.name == Roles.admin_ro.name): + vf_list = VF.objects.filter( + engagement__engagement_stage__in=engStageList)\ .distinct().order_by('engagement__engagement_manual_id')\ .annotate( engagement_manual_id=F('engagement__engagement_manual_id'), @@ -238,8 +251,10 @@ class GetEngByUser(VvpApiView): 'engagement_stage', ) else: - vf_list = VF.objects.filter(engagement__engagement_stage__in=engStageList).\ - filter(Q(engagement__engagement_team__uuid=user.uuid)).distinct().order_by('engagement__engagement_manual_id')\ + vf_list = VF.objects.filter( + engagement__engagement_stage__in=engStageList).\ + filter(Q(engagement__engagement_team__uuid=user.uuid))\ + .distinct().order_by('engagement__engagement_manual_id')\ .annotate( engagement_manual_id=F('engagement__engagement_manual_id'), engagement_uuid=F('engagement__uuid'), @@ -282,7 +297,8 @@ class SingleEngByUser(VvpApiView): engagement = None # @UndefinedVariable - if (user.role.name == Roles.admin.name or user.role.name == Roles.admin_ro.name): + if (user.role.name == Roles.admin.name or + user.role.name == Roles.admin_ro.name): engagement = Engagement.objects.get(uuid=eng_uuid) else: try: @@ -292,7 +308,7 @@ class SingleEngByUser(VvpApiView): try: engagement = Engagement.objects.get( engagement_team__uuid=user.uuid, uuid=eng_uuid) - except: + except BaseException: msg = "Eng for the User with uuid " + \ user.uuid + " doesn't exist." self.logger.error(msg) @@ -300,7 +316,8 @@ class SingleEngByUser(VvpApiView): return Response(msg, status=HTTP_500_INTERNAL_SERVER_ERROR) vfObj = VF.objects.get(engagement__uuid=engagement.uuid) eng_svc.update_or_insert_to_recent_engagements( - user.uuid, vfObj, RecentEngagementActionType.NAVIGATED_INTO_ENGAGEMENT.name) # @UndefinedVariable + user.uuid, vfObj, RecentEngagementActionType. + NAVIGATED_INTO_ENGAGEMENT.name) vfList = VF.objects.filter(engagement__uuid=engagement.uuid) formated_vf_list = VFModelSerializer(vfList, many=True).data @@ -342,11 +359,12 @@ class StarredEngagements(VvpApiView): @auth(Permissions.star_an_engagement) def get(self, request): user = request_data_mgr.get_user() - if (user == None): + if (not user): msg = "User with uuid " + user.uuid + \ " doesn't exist. Can't fetch their engagements" self.logger.error(logEncoding(msg)) - msg = "You are not registered as a user, please sign up in order to perform this action" + msg = "You are not registered as a user, please sign\ + up in order to perform this action" return Response(msg, status=HTTP_400_BAD_REQUEST) vf_list = eng_svc.vf_retreiver(user, True) @@ -360,17 +378,29 @@ class StarredEngagements(VvpApiView): for vf_data in vf_list: # @UndefinedVariable - if (user.role.name == Roles.el.name or user.role.name == Roles.admin.name or user.role.name == Roles.admin_ro.name): + if ( + user.role.name == Roles.el.name or + user.role.name == Roles.admin.name or + user.role.name == Roles.admin_ro.name): if (vf_data['engagement__reviewer__uuid'] == user.uuid): - checklist_lists = Checklist.objects.filter(Q(engagement__uuid=vf_data['engagement__uuid']), Q(engagement__reviewer=user), ~Q( - state=CheckListState.archive.name)).values('uuid', 'name', 'state', 'owner__uuid') # @UndefinedVariable + checklist_lists = Checklist.objects.filter( + Q(engagement__uuid=vf_data['engagement__uuid']), + Q(engagement__reviewer=user), ~Q( + state=CheckListState.archive.name)).values( + 'uuid', 'name', 'state', 'owner__uuid') # @UndefinedVariable - elif (user.role.name == Roles.admin.name or user.role.name == Roles.admin_ro.name): - checklist_lists = Checklist.objects.filter(Q(engagement__uuid=vf_data['engagement__uuid']), ~Q( - state=CheckListState.archive.name)).values('uuid', 'name', 'state', 'owner__uuid') # @UndefinedVariable + elif (user.role.name == Roles.admin.name or + user.role.name == Roles.admin_ro.name): + checklist_lists = Checklist.objects.filter( + Q(engagement__uuid=vf_data['engagement__uuid']), + ~Q(state=CheckListState.archive.name)).values( + 'uuid', 'name', 'state', 'owner__uuid') else: - checklist_lists = Checklist.objects.filter(Q(engagement__uuid=vf_data['engagement__uuid']), Q(owner=user), ~Q( - state=CheckListState.archive.name)).values('uuid', 'name', 'state', 'owner__uuid') # @UndefinedVariable + checklist_lists = Checklist.objects.filter( + Q(engagement__uuid=vf_data['engagement__uuid']), + Q(owner=user), ~Q( + state=CheckListState.archive.name)).values( + 'uuid', 'name', 'state', 'owner__uuid') vf_data['checklists'] = checklist_lists else: vf_data['checklists'] = None @@ -391,11 +421,12 @@ class StarredEngagements(VvpApiView): return Response(msg, status=HTTP_400_BAD_REQUEST) eng_uuid = data['engagement_uuid'] - if (user == None): + if (not user): msg = "User with uuid " + user.uuid + \ " doesn't exist. Can't fetch their engagements" self.logger.error(logEncoding(msg)) - msg = "You are not registered as a user, please sign up in order to perform this action" + msg = "You are not registered as a user, please sign up in order \ + to perform this action" return Response(msg, status=HTTP_400_BAD_REQUEST) msg = eng_svc.star_an_engagement(user, eng_uuid) @@ -409,11 +440,12 @@ class GetRecentEngagements(VvpApiView): @auth(Permissions.eng_membership) def get(self, request, format=None, **kwargs): user = request_data_mgr.get_user() - if (user == None): + if (not user): msg = "User with uuid " + user.uuid + \ " doesn't exist. Can't fetch their engagements" self.logger.error(logEncoding(msg)) - msg = "You are not registered as a user, please sign up in order to perform this action" + msg = "You are not registered as a user, please sign up in order \ + to perform this action" return Response(msg, status=HTTP_400_BAD_REQUEST) stared_list = eng_svc.vf_retreiver(user, True) @@ -431,17 +463,27 @@ class GetRecentEngagements(VvpApiView): if (idx == recentList): break # @UndefinedVariable - if (user.role.name == Roles.el.name or user.role.name == Roles.admin.name or user.role.name == Roles.admin_ro.name): + if (user.role.name == Roles.el.name or + user.role.name == Roles.admin.name or + user.role.name == Roles.admin_ro.name): if (vf_data['vf__engagement__reviewer__uuid'] == user.uuid): - checklist_lists = Checklist.objects.filter(Q(engagement__uuid=vf_data['vf__engagement__uuid']), Q(engagement__reviewer=user), ~Q( - state=CheckListState.archive.name)).values('uuid', 'name', 'state', 'owner__uuid') # @UndefinedVariable + checklist_lists = Checklist.objects.filter( + Q(engagement__uuid=vf_data['vf__engagement__uuid']), + Q(engagement__reviewer=user), ~Q( + state=CheckListState.archive.name)).values( + 'uuid', 'name', 'state', 'owner__uuid') # @UndefinedVariable - elif (user.role.name == Roles.admin.name or user.role.name == Roles.admin_ro.name): - checklist_lists = Checklist.objects.filter(Q(engagement__uuid=vf_data['vf__engagement__uuid']), ~Q( - state=CheckListState.archive.name)).values('uuid', 'name', 'state', 'owner__uuid') # @UndefinedVariable + elif (user.role.name == Roles.admin.name or + user.role.name == Roles.admin_ro.name): + checklist_lists = Checklist.objects.filter( + Q(engagement__uuid=vf_data['vf__engagement__uuid']), + ~Q(state=CheckListState.archive.name)).values( + 'uuid', 'name', 'state', 'owner__uuid') else: - checklist_lists = Checklist.objects.filter(Q(engagement__uuid=vf_data['vf__engagement__uuid']), Q(owner=user), ~Q( - state=CheckListState.archive.name)).values('uuid', 'name', 'state', 'owner__uuid') # @UndefinedVariable + checklist_lists = Checklist.objects.filter( + Q(engagement__uuid=vf_data['vf__engagement__uuid']), + Q(owner=user), ~Q(state=CheckListState.archive.name))\ + .values('uuid', 'name', 'state', 'owner__uuid') vf_data['checklists'] = checklist_lists else: vf_data['checklists'] = None @@ -457,7 +499,8 @@ class EngagementProgressBar(VvpApiView): data = request.data msg = "OK" - if ('progress' not in data or not data['progress'] or data['progress'] == ''): + if ('progress' not in data or not data['progress'] or + data['progress'] == ''): msg = "progress parameter is missing or empty" self.logger.error(msg) msg = "Action has failed due to bad request." @@ -472,7 +515,8 @@ class EngagementProgressBar(VvpApiView): eng = self.get_entity(Engagement, request_data_mgr.get_eng_uuid()) msg = "OK" - if ('target_date' not in data or not data['target_date'] or data['target_date'] == ''): + if ('target_date' not in data or not data['target_date'] or + data['target_date'] == ''): msg = "target_date parameter is missing or empty" self.logger.error(msg) msg = "Action has failed due to bad request." @@ -494,7 +538,8 @@ class ChangeTargetLabEntryDate(VvpApiView): eng = self.get_entity(Engagement, request_data_mgr.get_eng_uuid()) msg = "OK" vf = VF.objects.get(engagement__uuid=eng.uuid) - if ('target_date' not in data or not data['target_date'] or data['target_date'] == ''): + if ('target_date' not in data or not data['target_date'] + or data['target_date'] == ''): msg = "target_date parameter is missing or empty" self.logger.error(msg) msg = "Action has failed due to bad request." @@ -535,11 +580,13 @@ class Status(VvpApiView): if not description: msg = "Not description sent" self.logger.error(msg) - msg = "You are not registered as a user, please sign up in order to perform this action" + msg = "You are not registered as a user, please sign \ + up in order to perform this action" return Response(msg, status=HTTP_400_BAD_REQUEST) # @UndefinedVariable - if (user.role.name != Roles.admin.name and user.role.name != Roles.el.name): + if (user.role.name != Roles.admin.name and + user.role.name != Roles.el.name): msg = "User not authorized" self.logger.error(msg) msg = "Internal error." @@ -569,7 +616,8 @@ class Status(VvpApiView): return Response(msg, status=HTTP_400_BAD_REQUEST) # @UndefinedVariable - if (user.role.name != Roles.admin.name and user.role.name != Roles.el.name): + if (user.role.name != Roles.admin.name and + user.role.name != Roles.el.name): msg = "User not authorized" self.logger.error(msg) msg = "Internal error." @@ -598,7 +646,8 @@ class EngagementOps(VvpApiView): user = request_data_mgr.get_user() created_eng_status = eng_svc.insert_engagement_status( user, data['status'], engagement) - return Response(EngagementStatusModelSerializer(created_eng_status).data) + return Response( + EngagementStatusModelSerializer(created_eng_status).data) else: return Response() @@ -613,7 +662,7 @@ class EngagementTeamUsers(VvpApiView): data = request.data if (data['user_uuid']): requested_user_uuid = data['user_uuid'] - if (eng_uuid is not None and user is not None and data['user_uuid'] is not None): + if (eng_uuid and user and data['user_uuid']): eng_svc.remove_user_from_engagement_team( eng_uuid, user, requested_user_uuid) return Response(status=HTTP_204_NO_CONTENT) diff --git a/django/engagementmanager/rest/feedback.py b/django/engagementmanager/rest/feedback.py index b8075b8..146cb29 100644 --- a/django/engagementmanager/rest/feedback.py +++ b/django/engagementmanager/rest/feedback.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -57,7 +57,8 @@ class Feedback(VvpApiView): @auth(Permissions.add_feedback) def post(self, request): user = request_data_mgr.get_user() - if ('description' not in request.data or not request.data['description']): + if ('description' not in request.data or + not request.data['description']): raise KeyError("One of the input parameters are missing") new_description = request.data['description'] new_feedback = FeedbackModal( @@ -65,6 +66,7 @@ class Feedback(VvpApiView): description=new_description ) new_feedback.save() - self.slack_client.send_slack_notifications_for_new_feedback(new_feedback, user) + self.slack_client.send_slack_notifications_for_new_feedback( + new_feedback, user) return Response(status.HTTP_200_OK) diff --git a/django/engagementmanager/rest/invite.py b/django/engagementmanager/rest/invite.py index 8060a69..e5e1505 100644 --- a/django/engagementmanager/rest/invite.py +++ b/django/engagementmanager/rest/invite.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -36,7 +36,6 @@ # ============LICENSE_END============================================ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. -import json from rest_framework import status from rest_framework.response import Response @@ -59,15 +58,18 @@ class InviteTeamMember(VvpApiView): inviterUser = request_data_mgr.get_user() msg = "OK" sts = status.HTTP_200_OK - if (inviterUser != None): + if (inviterUser): dataList = [] dataList = request.data for data in dataList: - if 'eng_uuid' in data and data['eng_uuid'] and 'email' in data and data['email']: - inviteUserToSignUpOrLogin(inviterUser, data, is_contact_user=False) + if 'eng_uuid' in data and data['eng_uuid'] and \ + 'email' in data and data['email']: + inviteUserToSignUpOrLogin( + inviterUser, data, is_contact_user=False) else: - msg = "No eng_uuid or no email found on the request body to invite-team-members. data=" + str(data) + msg = "No eng_uuid or no email found on the request \ + body to invite-team-members. data=" + str(data) self.logger.error(logEncoding(msg)) sts = status.HTTP_500_INTERNAL_SERVER_ERROR @@ -84,9 +86,9 @@ class InviteContact(VvpApiView): data = request.data if ('full_name' not in data or not data['full_name'] or - 'email' not in data or not data['email'] or - 'phone_number' not in data or not data['phone_number'] or - 'eng_uuid' not in data or not data['eng_uuid']): + 'email' not in data or not data['email'] or + 'phone_number' not in data or not data['phone_number'] or + 'eng_uuid' not in data or not data['eng_uuid']): msg = "One of the input parameters is missing" self.logger.error(msg) return Response(msg, status=status.HTTP_400_BAD_REQUEST) diff --git a/django/engagementmanager/rest/login.py b/django/engagementmanager/rest/login.py index 53b906b..ddc5df4 100644 --- a/django/engagementmanager/rest/login.py +++ b/django/engagementmanager/rest/login.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -36,7 +36,6 @@ # ============LICENSE_END============================================ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. -import json from rest_framework.permissions import AllowAny from rest_framework.response import Response @@ -64,7 +63,9 @@ class Login(VvpApiView): if param: reset_password_param = param - reset_password_email, is_reset_pwd_flow = login_svc.identify_reset_password(jwt_obj, reset_password_param) + reset_password_email, is_reset_pwd_flow = login_svc.\ + identify_reset_password( + jwt_obj, reset_password_param) if not user_profile.user.is_active: msg = login_svc.render_user_not_active_message(data['email']) @@ -82,7 +83,9 @@ class Login(VvpApiView): if 'invitation' in data: login_svc.handle_invite_token(data, msg, user_profile) - self.logger.debug("login has passed successfully for [email=" + data['email'] + "]") + self.logger.debug( + "login has passed successfully for [email=" + data['email'] + + "]") login_svc.update_last_login(user_profile) return Response(msg) diff --git a/django/engagementmanager/rest/nextsteps.py b/django/engagementmanager/rest/nextsteps.py index 7d4f850..0c93f20 100644 --- a/django/engagementmanager/rest/nextsteps.py +++ b/django/engagementmanager/rest/nextsteps.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -41,7 +41,8 @@ import json from rest_framework.response import Response from rest_framework.status import HTTP_400_BAD_REQUEST, HTTP_204_NO_CONTENT -from engagementmanager.bus.messages.activity_event_message import ActivityEventMessage +from engagementmanager.bus.messages.activity_event_message import \ + ActivityEventMessage from engagementmanager.decorator.auth import auth from engagementmanager.decorator.class_decorator import classDecorator from engagementmanager.decorator.log_func_entry import logFuncEntry @@ -82,16 +83,20 @@ class NextSteps(VvpApiView): data = NextStepSvc().addNextStep(dataList) for next_step in data: - if (next_step['files'] != None): + if next_step['files']: next_step['files'] = json.loads(next_step['files']) - self.logger.debug("Successfully added a Next Step to engagement_uuid=" + - eng_uuid + " for creator with uuid=" + str(user)) + self.logger.debug( + "Successfully added a Next Step to engagement_uuid=" + + eng_uuid + + " for creator with uuid=" + + str(user)) return Response(data) @auth(Permissions.eng_membership) def get(self, request, **kwargs): - next_steps_data = NextStepSvc().get_next_steps(eng_stage=kwargs['eng_stage']) + next_steps_data = NextStepSvc().get_next_steps( + eng_stage=kwargs['eng_stage']) return Response(next_steps_data.data) @auth(Permissions.update_personal_next_step) @@ -129,7 +134,8 @@ class EditNextSteps(VvpApiView): ns = self.get_entity(NextStep, request_data_mgr.get_ns_uuid()) ns.delete() - activity_data = DeleteNextStepsActivityData(request_data_mgr.get_user(), ns.engagement) + activity_data = DeleteNextStepsActivityData( + request_data_mgr.get_user(), ns.engagement) bus_service.send_message(ActivityEventMessage(activity_data)) return Response(status=HTTP_204_NO_CONTENT) @@ -144,20 +150,23 @@ class ChecklistNextStep(VvpApiView): dataList = json.loads(body_unicode) msg = "OK" - if (request_data_mgr.get_cl_uuid() == None or request_data_mgr.get_eng_uuid() == None): - msg = "check list uuid or engagement uuid is missing from the url path parameters" + if (not request_data_mgr.get_cl_uuid() or not + request_data_mgr.get_eng_uuid()): + msg = "check list uuid or engagement uuid is missing from the " +\ + "url path parameters" self.logger.error(msg) return Response(msg, status=HTTP_400_BAD_REQUEST) for data in dataList: if ('assigneesUuids' not in data or not data['assigneesUuids'] or - 'description' not in data or not data['description'] or - 'duedate' not in data or not data['duedate']): + 'description' not in data or not data['description'] or + 'duedate' not in data or not data['duedate']): msg = "One of the CheckList's input parameters is missing" self.logger.error(msg) return Response(msg, status=HTTP_400_BAD_REQUEST) data = NextStepSvc().addNextStep( - dataList, desc="Checklist is denied due to a creation of a new NextStep") + dataList, desc="Checklist is denied due to a creation " + + "of a new NextStep") return Response(data) diff --git a/django/engagementmanager/rest/notification.py b/django/engagementmanager/rest/notification.py index 34c4a7b..53acb30 100644 --- a/django/engagementmanager/rest/notification.py +++ b/django/engagementmanager/rest/notification.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -44,7 +44,8 @@ from engagementmanager.decorator.auth import auth from engagementmanager.decorator.class_decorator import classDecorator from engagementmanager.decorator.log_func_entry import logFuncEntry import engagementmanager.models -from engagementmanager.notifications import num_of_notifications_for_user, reset_num_of_notifications_for_user,\ +from engagementmanager.notifications import num_of_notifications_for_user, \ + reset_num_of_notifications_for_user,\ pull_recent_notifications from engagementmanager.rest.vvp_api_view import VvpApiView from engagementmanager.service.authorization_service import Permissions @@ -75,12 +76,15 @@ class NotificationOps(VvpApiView): # PullRecentNotif4User def get(self, request, user_uuid, offset, limit): user = request_data_mgr.get_user() - serilizedActivitySet, num_of_objects = pull_recent_notifications(user.uuid, offset, limit) + serilizedActivitySet, num_of_objects = pull_recent_notifications( + user.uuid, offset, limit) if serilizedActivitySet is not None: - data = {'serilizedActivitySet': serilizedActivitySet, 'num_of_objects': num_of_objects} + data = {'serilizedActivitySet': serilizedActivitySet, + 'num_of_objects': num_of_objects} return Response(data) else: - return Response("Activity set wasn't found", status=HTTP_400_BAD_REQUEST) + return Response("Activity set wasn't found", + status=HTTP_400_BAD_REQUEST) # Reset the number of an unread notifications def put(self, request): diff --git a/django/engagementmanager/rest/parsers.py b/django/engagementmanager/rest/parsers.py index fce516a..9c778e7 100644 --- a/django/engagementmanager/rest/parsers.py +++ b/django/engagementmanager/rest/parsers.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -47,10 +47,10 @@ sanitizer = Cleaner( styles=[ 'color', 'font-family', 'font-style', 'font-weight', 'text-decoration-line', - ], + ], protocols=['http'], strip=True, - ) +) def clean_r(obj): @@ -94,6 +94,7 @@ class XSSParserMixin(parsers.BaseParser): cause clean_r() to be run against the parsed data. """ + def parse(self, stream, media_type=None, parser_context=None): return clean_r( super().parse( diff --git a/django/engagementmanager/rest/signup.py b/django/engagementmanager/rest/signup.py index 85d63cd..ee875ab 100644 --- a/django/engagementmanager/rest/signup.py +++ b/django/engagementmanager/rest/signup.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -51,10 +51,10 @@ from engagementmanager.decorator.log_func_entry import logFuncEntry from engagementmanager.models import Vendor, Engagement, Role, Invitation, \ IceUserProfile, CustomUser from engagementmanager.rest.vvp_api_view import VvpApiView -from engagementmanager.serializers import SuperThinIceUserProfileModelSerializer +from engagementmanager.serializers import\ + SuperThinIceUserProfileModelSerializer from engagementmanager.service.invite_service import markInvitationAsAccepted from engagementmanager.service.user_service import UserService -from engagementmanager.utils.authentication import JWTAuthentication from engagementmanager.utils.constants import Constants, Roles from engagementmanager.utils.validator import Validator, logEncoding from engagementmanager.views_helper import generateActivationLink, \ @@ -70,11 +70,11 @@ class SignUp(VvpApiView): data_dont_save = JSONParser().parse(request) if ('company' not in data or not data['company'] or - 'full_name' not in data or not data['full_name'] or - 'email' not in data or not data['email'] or - 'password' not in data or not data['password'] or - 'phone_number' not in data or not data['phone_number'] or - 'regular_email_updates' not in data): + 'full_name' not in data or not data['full_name'] or + 'email' not in data or not data['email'] or + 'password' not in data or not data['password'] or + 'phone_number' not in data or not data['phone_number'] or + 'regular_email_updates' not in data): msg = "One of the input parameters is missing" self.logger.error(msg) return Response(msg, status=status.HTTP_400_BAD_REQUEST) @@ -97,12 +97,15 @@ class SignUp(VvpApiView): Validator.validateEmail(i_email) - if data_dont_save['company'] == Constants.service_provider_company_name: + if data_dont_save['company'] == \ + Constants.service_provider_company_name: i_is_service_provider_contact = True mailTokens = i_email.split("@") - if mailTokens[1] not in Constants.service_provider_mail_domain and i_is_service_provider_contact: - msg = "Email address should be with service provider domain for signees that their company =" + \ + if mailTokens[1] not in Constants.service_provider_mail_domain and \ + i_is_service_provider_contact: + msg = "Email address should be with service provider domain for \ + signees that their company =" + \ Constants.service_provider_company_name self.logger.error(logEncoding(msg)) return Response(msg, status=status.HTTP_400_BAD_REQUEST) @@ -114,46 +117,62 @@ class SignUp(VvpApiView): activationToken = str(uuid.uuid4().hex) i_company = Vendor.objects.get(name=data_dont_save['company']) - user_object = CustomUser.objects.create_user(username=i_email, email=i_email, password=i_password, - activation_token=activationToken, activation_token_create_time=timezone.now(), is_active=False) - info = createUserTemplate(i_company, i_full_name, roleObj, i_phone_number, - i_is_service_provider_contact, None, i_regular_email_updates, user_object) - newUserObj, is_profile_created = IceUserProfile.objects.update_or_create( - email=user_object.email, defaults=info) + user_object = CustomUser.objects.create_user( + username=i_email, email=i_email, password=i_password, + activation_token=activationToken, + activation_token_create_time=timezone.now(), is_active=False) + info = createUserTemplate( + i_company, i_full_name, roleObj, i_phone_number, + i_is_service_provider_contact, + None, i_regular_email_updates, user_object) + newUserObj, is_profile_created = \ + IceUserProfile.objects.update_or_create( + email=user_object.email, defaults=info) self.logger.debug( "Creating Non activated User: " + str(newUserObj)) userData = SuperThinIceUserProfileModelSerializer(newUserObj).data - # If we eng_uuid and inviter_uuid is supplied it means that this user was - # invited. We want to add them to the engagement team of the inviter + # If we eng_uuid and inviter_uuid is supplied it means that this + # user was invited. We want to add them to the engagement team + # of the inviter if 'invitation' in data: invitation = Invitation.objects.get( invitation_token=data['invitation']) - self.logger.debug("Looks like user " + i_full_name + " has arrived to the sign-up page from an invite email initiated by user with uuid=" + - invitation.invited_by_user_uuid + ". Adding them to the inviter's engagement_team...") + self.logger.debug( + "Looks like user " + i_full_name + + " has arrived to the sign-up page from an invite email \ + initiated by user with uuid=" + + invitation.invited_by_user_uuid + ". Adding them to the \ + inviter's engagement_team...") userData['eng_uuid'] = invitation.engagement_uuid if data["is_contact_user"] == "true": engObj = Engagement.objects.get( uuid=invitation.engagement_uuid) engObj.contact_user = newUserObj - self.logger.debug("Attaching the user (" + newUserObj.full_name + - ") to the engagement's (" + engObj.uuid + ") contact_user") + self.logger.debug( + "Attaching the user (" + newUserObj.full_name + + ") to the engagement's (" + engObj.uuid + + ") contact_user") engObj.save() user_svc.addUserToEngAndFireProvisionVfSig( newUserObj, invitation) otherInviteObj = Invitation.objects.filter( - accepted=False, email=i_email).exclude(uuid=invitation.uuid) + accepted=False, email=i_email).exclude( + uuid=invitation.uuid) - if data['is_contact_user'] == "true" or data['is_contact_user'] == "True": + if data['is_contact_user'] == "true" or \ + data['is_contact_user'] == "True": engObj = Engagement.objects.get( uuid=invitation.engagement_uuid) engObj.contact_user = newUserObj - self.logger.debug("Attaching the user (" + newUserObj.full_name + - ") to the engagement's (" + engObj.uuid + ") contact_user") + self.logger.debug( + "Attaching the user (" + newUserObj.full_name + + ") to the engagement's (" + + engObj.uuid + ") contact_user") engObj.save() markInvitationAsAccepted(data['invitation']) @@ -171,10 +190,12 @@ class SignUp(VvpApiView): self.logger.debug( "Activation Link: " + data['activation_link']) - body = get_template("{activate_template_dir}activate_mail_body.html".format( - activate_template_dir=Constants.activate_template_dir)) - subject = get_template("{activate_template_dir}activate_mail_subject.html".format( - activate_template_dir=Constants.activate_template_dir)) + body = get_template( + "{activate_template_dir}activate_mail_body.html".format( + activate_template_dir=Constants.activate_template_dir)) + subject = get_template( + "{activate_template_dir}activate_mail_subject.html".format( + activate_template_dir=Constants.activate_template_dir)) mail.sendMail(i_email, data, body, subject) self.logger.debug( diff --git a/django/engagementmanager/rest/user.py b/django/engagementmanager/rest/user.py index 13fc916..7f9acb2 100644 --- a/django/engagementmanager/rest/user.py +++ b/django/engagementmanager/rest/user.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -36,7 +36,6 @@ # ============LICENSE_END============================================ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. -import json import uuid from django.conf import settings @@ -91,7 +90,8 @@ class UpdatePassword(VvpApiView): user.user.set_password(data['password']) user.user.temp_password = None user.user.save() - self.logger.info("Reset Password finished successfully for user with uuid=" + + self.logger.info("Reset Password finished successfully " + + "for user with uuid=" + user.uuid + " Redirecting to Login") return Response(msg) @@ -122,12 +122,13 @@ class SendResetPasswordInstructionMail(VvpApiView): self.logger.debug( "The login link to reset Password: " + str(data['login_link'])) - if (user != None): - body = get_template("{reset_pwd_template_dir}reset_pwd_instructions_mail_body.html" .format( - reset_pwd_template_dir=Constants.reset_pwd_template_dir)) - subject = get_template("{reset_pwd_template_dir}reset_pwd_instructions_mail_subject.html".format( - reset_pwd_template_dir=Constants.reset_pwd_template_dir)) - + if (user): + body = get_template( + Constants.reset_pwd_template_dir + + "reset_pwd_instructions_mail_body.html") + subject = get_template( + Constants.reset_pwd_template_dir + + "reset_pwd_instructions_mail_subject.html") user.user.temp_password = make_password(data['tempPassword']) user.user.save() user.save() @@ -135,8 +136,9 @@ class SendResetPasswordInstructionMail(VvpApiView): try: mail.sendMail(data['email'], data, body, subject) except Exception as e: - msg = "Something went wrong while trying to send reset-password mail to " + \ - data['email'] + "\n error: " + e.message + msg = "Something went wrong while trying to send \ + reset-password mail to " \ + + data['email'] + "\n error: " + e.message self.logger.error( msg + " rolling back the temporary password from the DB") user.user.temp_password = None @@ -162,7 +164,8 @@ class User(VvpApiView): user.phone_number = data['phone_number'] user.full_name = data['full_name'] if len(user.full_name) > 30: - return Response("first name should be up to 30 characters", status=HTTP_400_BAD_REQUEST) + return Response("first name should be up to 30 characters", + status=HTTP_400_BAD_REQUEST) self.handle_password_change(data, user) @@ -238,4 +241,5 @@ class EngagementLeads(VvpApiView): class RGWAAccessKey(VvpApiView): def get(self, request): - return Response({"rgwa_secret_key": UserService().get_user_rgwa_secret()}) + return Response( + {"rgwa_secret_key": UserService().get_user_rgwa_secret()}) diff --git a/django/engagementmanager/rest/validation_details.py b/django/engagementmanager/rest/validation_details.py index 1f1a929..ebb527e 100644 --- a/django/engagementmanager/rest/validation_details.py +++ b/django/engagementmanager/rest/validation_details.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/engagementmanager/rest/vendor.py b/django/engagementmanager/rest/vendor.py index b6ae351..1c5f5f6 100644 --- a/django/engagementmanager/rest/vendor.py +++ b/django/engagementmanager/rest/vendor.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -68,9 +68,6 @@ class VendorREST(VvpApiView): data = request.data vendor = None - public = False - if 'public' in data: - public = data['public'] try: vendor = Vendor.objects.get(name=data['name']) msg = "Company: " + vendor.name + " already exist" @@ -91,5 +88,5 @@ class VendorREST(VvpApiView): def delete(self, request, uuid): msg = "" sts = HTTP_204_NO_CONTENT - vendor = Vendor.objects.get(uuid=uuid).delete() + Vendor.objects.get(uuid=uuid).delete() return Response(msg, status=sts) diff --git a/django/engagementmanager/rest/vf.py b/django/engagementmanager/rest/vf.py index 23ee5b9..0288c14 100644 --- a/django/engagementmanager/rest/vf.py +++ b/django/engagementmanager/rest/vf.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/engagementmanager/rest/vfc.py b/django/engagementmanager/rest/vfc.py index 9ebf3bc..245e936 100644 --- a/django/engagementmanager/rest/vfc.py +++ b/django/engagementmanager/rest/vfc.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -36,7 +36,6 @@ # ============LICENSE_END============================================ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. -import json from rest_framework.response import Response from rest_framework.status import HTTP_204_NO_CONTENT @@ -64,10 +63,13 @@ class VFCRest(VvpApiView): return Response(serializer.data) """ - expecting: VF object uuid, VFC relevant fields(excluding the ones with default field) - result: addition of a VFC to the DB and concatenating them with the VF object + expecting: VF object uuid, VFC relevant fields + (excluding the ones with default field) + result: addition of a VFC to the DB and concatenating + them with the VF object """ - # This method doesn't need to be decorated with auth since it doesn't pass any engagement data from the front-end + # This method doesn't need to be decorated with auth since it doesn't pass + # any engagement data from the front-end @auth(Permissions.add_vfc) def post(self, request): diff --git a/django/engagementmanager/rest/vvp_api_view.py b/django/engagementmanager/rest/vvp_api_view.py index 4abe086..3163fe9 100644 --- a/django/engagementmanager/rest/vvp_api_view.py +++ b/django/engagementmanager/rest/vvp_api_view.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -40,7 +40,8 @@ from abc import ABCMeta from rest_framework.views import APIView from engagementmanager.decorator.class_decorator import classDecorator from engagementmanager.decorator.log_func_entry import logFuncEntry -from engagementmanager.service.authorization_service import AuthorizationService +from engagementmanager.service.authorization_service import \ + AuthorizationService from engagementmanager.service.logging_service import LoggingServiceFactory |