From b21a63837c8cfefcb5e0869c55acbf5bc5bf14d4 Mon Sep 17 00:00:00 2001 From: anishfyle Date: Tue, 17 Dec 2024 15:09:55 +0530 Subject: [PATCH 1/3] fix: remove employee settings apis --- .../workspaces/apis/map_employees/__init__.py | 0 .../apis/map_employees/serializers.py | 54 ------------------- .../workspaces/apis/map_employees/triggers.py | 15 ------ apps/workspaces/apis/map_employees/views.py | 11 ---- apps/workspaces/apis/urls.py | 2 - 5 files changed, 82 deletions(-) delete mode 100644 apps/workspaces/apis/map_employees/__init__.py delete mode 100644 apps/workspaces/apis/map_employees/serializers.py delete mode 100644 apps/workspaces/apis/map_employees/triggers.py delete mode 100644 apps/workspaces/apis/map_employees/views.py 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()), From a024d861f466c7bc4ee72f6bdaf52812fd5ef6c0 Mon Sep 17 00:00:00 2001 From: anishfyle Date: Wed, 18 Dec 2024 10:42:40 +0530 Subject: [PATCH 2/3] rem test --- .../apis/clone_settings/serializers.py | 13 +------ .../test_apis/test_map_employee/__init__.py | 0 .../test_apis/test_map_employee/fixtures.py | 6 --- .../test_map_employee/test_serializers.py | 24 ------------ .../test_apis/test_map_employee/test_views.py | 38 ------------------- 5 files changed, 2 insertions(+), 79 deletions(-) delete mode 100644 tests/test_workspaces/test_apis/test_map_employee/__init__.py delete mode 100644 tests/test_workspaces/test_apis/test_map_employee/fixtures.py delete mode 100644 tests/test_workspaces/test_apis/test_map_employee/test_serializers.py delete mode 100644 tests/test_workspaces/test_apis/test_map_employee/test_views.py diff --git a/apps/workspaces/apis/clone_settings/serializers.py b/apps/workspaces/apis/clone_settings/serializers.py index 70235502a..054c0ede6 100644 --- a/apps/workspaces/apis/clone_settings/serializers.py +++ b/apps/workspaces/apis/clone_settings/serializers.py @@ -9,7 +9,6 @@ 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): @@ -42,9 +41,6 @@ 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') @@ -63,16 +59,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() 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' From 0e88ee00d42d78cd4112984ea7ed0758e886c729 Mon Sep 17 00:00:00 2001 From: anishfyle Date: Wed, 18 Dec 2024 10:48:03 +0530 Subject: [PATCH 3/3] fix clone settings --- apps/workspaces/apis/clone_settings/serializers.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/apps/workspaces/apis/clone_settings/serializers.py b/apps/workspaces/apis/clone_settings/serializers.py index 054c0ede6..f9ca21c44 100644 --- a/apps/workspaces/apis/clone_settings/serializers.py +++ b/apps/workspaces/apis/clone_settings/serializers.py @@ -15,7 +15,6 @@ class CloneSettingsSerializer(serializers.ModelSerializer): export_settings = ReadWriteSerializerMethodField() import_settings = ReadWriteSerializerMethodField() advanced_configurations = ReadWriteSerializerMethodField() - employee_mappings = ReadWriteSerializerMethodField() workspace_id = serializers.SerializerMethodField() class Meta: @@ -24,8 +23,7 @@ class Meta: 'workspace_id', 'export_settings', 'import_settings', - 'advanced_configurations', - 'employee_mappings' + 'advanced_configurations' ] read_only_fields = ['workspace_id'] @@ -45,7 +43,6 @@ 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 @@ -79,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