diff --git a/apps/workspaces/api/views.py b/apps/workspaces/api/views.py index 8a7a557..24ec4f9 100644 --- a/apps/workspaces/api/views.py +++ b/apps/workspaces/api/views.py @@ -290,7 +290,7 @@ class WorkspaceMembershipViewSet(ModelViewSet): "status": "invalid", "action": "none", "user": None, - "messages": [f"Import is limited to {MEMBER_IMPORT_MAX_ROWS} rows."], + "messages": ["too_many_rows"], } ], } @@ -307,40 +307,40 @@ class WorkspaceMembershipViewSet(ModelViewSet): normalized_rate = "" if not mobile: - messages.append("Mobile is required.") + messages.append("mobile_required") elif mobile in seen_mobiles: - messages.append("This mobile appears more than once in the import file.") + messages.append("duplicate_mobile") else: seen_mobiles.add(mobile) user = User.objects.filter(mobile=mobile).first() if not user: - messages.append("No user exists with this mobile number.") + messages.append("user_not_found") elif str(user.id) in existing_memberships: - messages.append("This user is already a member of the workspace.") + messages.append("already_member") if role == WorkspaceMembership.Role.OWNER: - messages.append("Owner role cannot be imported.") + messages.append("owner_role_not_allowed") elif role not in allowed_roles: - messages.append("Role must be admin, member, or guest.") + messages.append("invalid_role") elif not can_assign_workspace_role(request.user, workspace, role): - messages.append("You do not have permission to assign this role.") + messages.append("role_permission_denied") has_rate = bool(hourly_rate_raw) has_currency = bool(currency) if has_rate != has_currency: - messages.append("Hourly rate and currency must be provided together.") + messages.append("rate_currency_pair_required") elif has_rate and has_currency: try: parsed_rate = Decimal(hourly_rate_raw.replace(",", "")) if parsed_rate <= Decimal("0"): - messages.append("Hourly rate must be greater than zero.") + messages.append("hourly_rate_positive") else: normalized_rate = f"{parsed_rate:.2f}" except (InvalidOperation, ValueError): - messages.append("Hourly rate must be a valid number.") + messages.append("hourly_rate_invalid") if not PriceUnit.objects.filter(code=currency, is_deleted=False).exists(): - messages.append("Currency is invalid.") + messages.append("currency_invalid") row_status = "invalid" if messages else "valid" if messages: diff --git a/apps/workspaces/tests/test_capabilities.py b/apps/workspaces/tests/test_capabilities.py index 9bb1e76..1d393ac 100644 --- a/apps/workspaces/tests/test_capabilities.py +++ b/apps/workspaces/tests/test_capabilities.py @@ -407,7 +407,7 @@ class WorkspaceCapabilityTests(APITestCase): self.assertEqual(response.status_code, 200) self.assertFalse(response.data["can_commit"]) - self.assertIn("permission", response.data["rows"][0]["messages"][0].lower()) + self.assertIn("role_permission_denied", response.data["rows"][0]["messages"]) def test_member_cannot_import_workspace_members(self): target = self._user(24)