diff --git a/apps/workspaces/apis/clone_settings/serializers.py b/apps/workspaces/apis/clone_settings/serializers.py index 70235502a..f9ca21c44 100644 --- a/apps/workspaces/apis/clone_settings/serializers.py +++ b/apps/workspaces/apis/clone_settings/serializers.py @@ -9,14 +9,12 @@ from apps.workspaces.apis.import_settings.serializers import ImportSettingsSerializer from apps.workspaces.apis.advanced_configurations.serializers import AdvancedConfigurationsSerializer -from apps.workspaces.apis.map_employees.serializers import MapEmployeesSerializer class CloneSettingsSerializer(serializers.ModelSerializer): export_settings = ReadWriteSerializerMethodField() import_settings = ReadWriteSerializerMethodField() advanced_configurations = ReadWriteSerializerMethodField() - employee_mappings = ReadWriteSerializerMethodField() workspace_id = serializers.SerializerMethodField() class Meta: @@ -25,8 +23,7 @@ class Meta: 'workspace_id', 'export_settings', 'import_settings', - 'advanced_configurations', - 'employee_mappings' + 'advanced_configurations' ] read_only_fields = ['workspace_id'] @@ -42,14 +39,10 @@ def get_import_settings(self, instance): def get_advanced_configurations(self, instance): return AdvancedConfigurationsSerializer(instance).data - def get_employee_mappings(self, instance): - return MapEmployeesSerializer(instance).data - def update(self, instance, validated): export_settings = validated.pop('export_settings') import_settings = validated.pop('import_settings') advanced_configurations = validated.pop('advanced_configurations') - employee_mapping = validated.pop('employee_mappings') export_settings_serializer = ExportSettingsSerializer( instance, data=export_settings, partial=True @@ -63,16 +56,11 @@ def update(self, instance, validated): instance, data=advanced_configurations, partial=True ) - employee_mapping_serializer = MapEmployeesSerializer( - instance, data=employee_mapping, partial=True - ) - - if export_settings_serializer.is_valid(raise_exception=True) and employee_mapping_serializer.is_valid(raise_exception=True) \ - and import_settings_serializer.is_valid(raise_exception=True) and \ + if export_settings_serializer.is_valid(raise_exception=True) and \ + import_settings_serializer.is_valid(raise_exception=True) and \ advanced_configurations_serializer.is_valid(raise_exception=True): with transaction.atomic(): - employee_mapping_serializer.save() export_settings_serializer.save() import_settings_serializer.save() advanced_configurations_serializer.save() @@ -88,7 +76,4 @@ def validate(self, data): if not data.get('advanced_configurations'): raise serializers.ValidationError('Advanced Settings are required') - - if not data.get('employee_mappings'): - raise serializers.ValidationError('Employee Mappings are required') return data diff --git a/apps/workspaces/apis/map_employees/__init__.py b/apps/workspaces/apis/map_employees/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/apps/workspaces/apis/map_employees/serializers.py b/apps/workspaces/apis/map_employees/serializers.py deleted file mode 100644 index 4be4198df..000000000 --- a/apps/workspaces/apis/map_employees/serializers.py +++ /dev/null @@ -1,54 +0,0 @@ -from rest_framework import serializers - -from apps.workspaces.apis.map_employees.triggers import MapEmployeesTriggers -from apps.workspaces.models import Workspace, WorkspaceGeneralSettings - - -class WorkspaceGeneralSettingsSerializer(serializers.ModelSerializer): - class Meta: - model = WorkspaceGeneralSettings - fields = ['employee_field_mapping', 'auto_map_employees'] - - -class MapEmployeesSerializer(serializers.ModelSerializer): - workspace_general_settings = WorkspaceGeneralSettingsSerializer() - workspace_id = serializers.SerializerMethodField() - - class Meta: - model = Workspace - fields = ['workspace_general_settings', 'workspace_id'] - read_only_fields = ['workspace_id'] - - def get_workspace_id(self, instance): - return instance.id - - def update(self, instance, validated_data): - workspace_id = instance.id - workspace_general_settings = validated_data.pop('workspace_general_settings') - - workspace_general_settings_instance = WorkspaceGeneralSettings.objects.filter(workspace_id=instance.id).first() - - if workspace_general_settings_instance and (workspace_general_settings_instance.employee_field_mapping != workspace_general_settings['employee_field_mapping']): - workspace_general_settings_instance.reimbursable_expenses_object = None - workspace_general_settings_instance.save() - - workspace_general_settings_instance, _ = WorkspaceGeneralSettings.objects.update_or_create( - workspace_id=workspace_id, defaults={'employee_field_mapping': workspace_general_settings['employee_field_mapping'], 'auto_map_employees': workspace_general_settings['auto_map_employees']} - ) - - MapEmployeesTriggers.run_workspace_general_settings_triggers(workspace_general_settings_instance) - - if instance.onboarding_state == 'MAP_EMPLOYEES': - instance.onboarding_state = 'EXPORT_SETTINGS' - instance.save() - - return instance - - def validate(self, data): - if not data.get('workspace_general_settings').get('employee_field_mapping'): - raise serializers.ValidationError('employee_field_mapping field is required') - - if data.get('workspace_general_settings').get('auto_map_employees') and data.get('workspace_general_settings').get('auto_map_employees') not in ['EMAIL', 'NAME', 'EMPLOYEE_CODE']: - raise serializers.ValidationError('auto_map_employees can have only EMAIL / NAME / EMPLOYEE_CODE') - - return data diff --git a/apps/workspaces/apis/map_employees/triggers.py b/apps/workspaces/apis/map_employees/triggers.py deleted file mode 100644 index c658b60f3..000000000 --- a/apps/workspaces/apis/map_employees/triggers.py +++ /dev/null @@ -1,15 +0,0 @@ -from apps.mappings.queues import schedule_auto_map_employees -from apps.workspaces.models import WorkspaceGeneralSettings - - -class MapEmployeesTriggers: - """ - Class containing all triggers for map_employees - """ - - @staticmethod - def run_workspace_general_settings_triggers(workspace_general_settings_instance: WorkspaceGeneralSettings): - """ - Run workspace general settings triggers - """ - schedule_auto_map_employees(workspace_general_settings_instance.auto_map_employees, workspace_general_settings_instance.workspace.id) diff --git a/apps/workspaces/apis/map_employees/views.py b/apps/workspaces/apis/map_employees/views.py deleted file mode 100644 index b340448a8..000000000 --- a/apps/workspaces/apis/map_employees/views.py +++ /dev/null @@ -1,11 +0,0 @@ -from rest_framework import generics - -from apps.workspaces.apis.map_employees.serializers import MapEmployeesSerializer -from apps.workspaces.models import Workspace - - -class MapEmployeesView(generics.RetrieveUpdateAPIView): - serializer_class = MapEmployeesSerializer - - def get_object(self): - return Workspace.objects.filter(id=self.kwargs['workspace_id']).first() diff --git a/apps/workspaces/apis/urls.py b/apps/workspaces/apis/urls.py index f3713fbd0..d98dd3558 100644 --- a/apps/workspaces/apis/urls.py +++ b/apps/workspaces/apis/urls.py @@ -19,12 +19,10 @@ from apps.workspaces.apis.errors.views import ErrorsView from apps.workspaces.apis.export_settings.views import ExportSettingsView from apps.workspaces.apis.import_settings.views import ImportSettingsView, ImportCodeFieldView -from apps.workspaces.apis.map_employees.views import MapEmployeesView from apps.workspaces.apis.clone_settings.views import CloneSettingsView urlpatterns = [ path('/export_settings/', ExportSettingsView.as_view()), - path('/map_employees/', MapEmployeesView.as_view()), path('/import_settings/import_code_fields_config/', ImportCodeFieldView.as_view(), name='import-code-fields-config'), path('/import_settings/', ImportSettingsView.as_view()), path('/advanced_configurations/', AdvancedConfigurationsView.as_view()), diff --git a/tests/test_workspaces/test_apis/test_map_employee/__init__.py b/tests/test_workspaces/test_apis/test_map_employee/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/test_workspaces/test_apis/test_map_employee/fixtures.py b/tests/test_workspaces/test_apis/test_map_employee/fixtures.py deleted file mode 100644 index 429f58f5c..000000000 --- a/tests/test_workspaces/test_apis/test_map_employee/fixtures.py +++ /dev/null @@ -1,6 +0,0 @@ -data = { - 'map_employees': {'workspace_general_settings': {'employee_field_mapping': 'EMPLOYEE', 'auto_map_employees': 'EMAIL'}}, - 'response': {"workspace_general_settings": {"employee_field_mapping": "EMPLOYEE", "auto_map_employees": "EMAIL"}, "workspace_id": 8}, - 'invalid_auto_map_employees': {'workspace_general_settings': {'employee_field_mapping': 'EMPLOYEE', 'auto_map_employees': 'EMAILs'}}, - 'missing_employee_mapping': {'workspace_general_settings': {'auto_map_employees': 'EMAILs'}}, -} diff --git a/tests/test_workspaces/test_apis/test_map_employee/test_serializers.py b/tests/test_workspaces/test_apis/test_map_employee/test_serializers.py deleted file mode 100644 index 9949fc150..000000000 --- a/tests/test_workspaces/test_apis/test_map_employee/test_serializers.py +++ /dev/null @@ -1,24 +0,0 @@ -import pytest -from rest_framework.exceptions import ValidationError - -from apps.workspaces.apis.map_employees.serializers import MapEmployeesSerializer - - -def test_employee_field_mapping_required(): - invalid_data = {'workspace_general_settings': {}} - serializer = MapEmployeesSerializer(data=invalid_data) - with pytest.raises(ValidationError): - serializer.is_valid(raise_exception=True) - - -def test_auto_map_employees_value(): - invalid_data = {'workspace_general_settings': {'auto_map_employees': 'INVALID_VALUE'}} - serializer = MapEmployeesSerializer(data=invalid_data) - with pytest.raises(ValidationError): - serializer.is_valid(raise_exception=True) - - -def test_valid_data(): - valid_data = {'workspace_general_settings': {'employee_field_mapping': 'value'}} - serializer = MapEmployeesSerializer(data=valid_data) - assert serializer.is_valid() is True diff --git a/tests/test_workspaces/test_apis/test_map_employee/test_views.py b/tests/test_workspaces/test_apis/test_map_employee/test_views.py deleted file mode 100644 index fcb819794..000000000 --- a/tests/test_workspaces/test_apis/test_map_employee/test_views.py +++ /dev/null @@ -1,38 +0,0 @@ -import json - -from apps.workspaces.models import Workspace, WorkspaceGeneralSettings -from tests.helper import dict_compare_keys -from tests.test_workspaces.test_apis.test_map_employee.fixtures import data - - -def test_map_employees(api_client, test_connection): - - workspace = Workspace.objects.get(id=3) - workspace.onboarding_state = 'MAP_EMPLOYEES' - workspace.save() - - workspace_general_settings_instance = WorkspaceGeneralSettings.objects.filter(workspace_id=3).first() - workspace_general_settings_instance.employee_field_mapping = 'VENDOR' - workspace_general_settings_instance.save() - - url = '/api/v2/workspaces/3/map_employees/' - api_client.credentials(HTTP_AUTHORIZATION='Bearer {}'.format(test_connection.access_token)) - response = api_client.put(url, data=data['map_employees'], format='json') - - assert response.status_code == 200 - - response = json.loads(response.content) - - assert dict_compare_keys(response, data['response']) == [], 'workspaces api returns a diff in the keys' - - response = api_client.put(url, data=data['missing_employee_mapping'], format='json') - - assert response.status_code == 400 - response = json.loads(response.content) - - response = api_client.put(url, data=data['invalid_auto_map_employees'], format='json') - - assert response.status_code == 400 - response = json.loads(response.content) - - assert response['non_field_errors'][0] == 'auto_map_employees can have only EMAIL / NAME / EMPLOYEE_CODE'