From b21a63837c8cfefcb5e0869c55acbf5bc5bf14d4 Mon Sep 17 00:00:00 2001 From: anishfyle Date: Tue, 17 Dec 2024 15:09:55 +0530 Subject: [PATCH] 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()),