diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index f564935..49b3ae0 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,34 +5,14 @@
-
-
-
-
-
-
-
-
+
+
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -68,8 +48,11 @@
"keyToString": {
"ASKED_MARK_IGNORED_FILES_AS_EXCLUDED": "true",
"DefaultHtmlFileTemplate": "HTML File",
- "Django Server.DepoT.executor": "Debug",
+ "Django Server.DepoT.executor": "Run",
"Django tests.Test: booking.tests.BookingViewsTestCase.executor": "Debug",
+ "Django tests.Test: booking.tests.BookingViewsTestCase.test_booking_list_view.executor": "Debug",
+ "Django tests.Test: booking.tests.BookingViewsTestCase.test_booking_list_view__user_all_rights__expect_OK.executor": "Profiler",
+ "Django tests.Test: booking.tests.BookingViewsTestCase.test_booking_list_view__user_no_rights__expect_forbidden.executor": "Debug",
"RunOnceActivity.OpenDjangoStructureViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.git.unshallow": "true",
@@ -108,7 +91,7 @@
-
+
@@ -116,6 +99,7 @@
+
@@ -130,6 +114,71 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -158,11 +207,17 @@
+
+
+
+
+
+
@@ -311,6 +366,31 @@
7
+
+ file://$PROJECT_DIR$/booking/tests.py
+ 90
+
+
+
+ file://$PROJECT_DIR$/booking/tests.py
+ 76
+
+
+
+ file://$PROJECT_DIR$/booking/views/client_views.py
+ 40
+
+
+
+ file://$PROJECT_DIR$/booking/views/client_views.py
+ 46
+
+
+
+ file://$PROJECT_DIR$/booking/tests.py
+ 75
+
+
file://$PROJECT_DIR$/static/js/container_validation.js
4
@@ -327,6 +407,9 @@
-
+
+
+
+
\ No newline at end of file
diff --git a/DepoT/settings/development.py b/DepoT/settings/development.py
index 73c3455..ad1ccc0 100644
--- a/DepoT/settings/development.py
+++ b/DepoT/settings/development.py
@@ -17,7 +17,7 @@ import environ
BASE_DIR = Path(__file__).resolve().parent.parent.parent
env = environ.Env()
-environ.Env.read_env(os.path.join(BASE_DIR, '.env'))
+env.read_env(os.path.join(BASE_DIR, '.env'))
SECRET_KEY = "django-insecure-g%187p84o9^rr)3#9@r3n^o2v1i%@6=+puxm7hlodg+kbsk%n#"
diff --git a/DepoT/settings/production.py b/DepoT/settings/production.py
index 92c0fc8..96fa3c1 100644
--- a/DepoT/settings/production.py
+++ b/DepoT/settings/production.py
@@ -18,7 +18,7 @@ from minio_backend.storage import MinioStaticStorage, MinioMediaStorage
BASE_DIR = Path(__file__).resolve().parent.parent.parent
env = environ.Env()
-environ.Env.read_env(os.path.join(BASE_DIR, 'production.env'))
+env.read_env(os.path.join(BASE_DIR, 'production.env'))
SECRET_KEY = "django-insecure-g%187p84o9^rr)3#9@r3n^o2v1i%@6=+puxm7hlodg+kbsk%n#"
diff --git a/accounts/__pycache__/admin.cpython-313.pyc b/accounts/__pycache__/admin.cpython-313.pyc
index 21b02c4..459858a 100644
Binary files a/accounts/__pycache__/admin.cpython-313.pyc and b/accounts/__pycache__/admin.cpython-313.pyc differ
diff --git a/accounts/__pycache__/urls.cpython-313.pyc b/accounts/__pycache__/urls.cpython-313.pyc
index ed17939..1ab8ea4 100644
Binary files a/accounts/__pycache__/urls.cpython-313.pyc and b/accounts/__pycache__/urls.cpython-313.pyc differ
diff --git a/accounts/__pycache__/views.cpython-313.pyc b/accounts/__pycache__/views.cpython-313.pyc
index 90cde6b..f661bc3 100644
Binary files a/accounts/__pycache__/views.cpython-313.pyc and b/accounts/__pycache__/views.cpython-313.pyc differ
diff --git a/accounts/migrations/__pycache__/0008_populate_permissions.cpython-313.pyc b/accounts/migrations/__pycache__/0008_populate_permissions.cpython-313.pyc
index 10fca53..c235ba1 100644
Binary files a/accounts/migrations/__pycache__/0008_populate_permissions.cpython-313.pyc and b/accounts/migrations/__pycache__/0008_populate_permissions.cpython-313.pyc differ
diff --git a/booking/tests.py b/booking/tests.py
index d6f2ff2..94e9d57 100644
--- a/booking/tests.py
+++ b/booking/tests.py
@@ -1,49 +1,99 @@
from django.test import TestCase, Client
-from django.urls import reverse
+from django.urls import reverse, reverse_lazy
from django.contrib.auth import get_user_model
+
+from accounts.models import ClientPermission
from booking.models import Booking
-from common.models import LinesModel, ContainerTypeModel
+from common.models import LinesModel, ContainerTypeModel, CompanyModel
+
class BookingViewsTestCase(TestCase):
def setUp(self):
+ self.company = CompanyModel.objects.create(name='Test Company')
+ self.line = LinesModel.objects.create(name='Test Line', company_id=self.company.id)
+ self.container_type = ContainerTypeModel.objects.get(name='20GP')
+
+ self.user_password = 'password'
self.client = Client()
DepotUser = get_user_model()
- self.user = DepotUser.objects.create_user(username='testuser', password='password', user_type='EM')
- self.client.login(username='testuser', password='password')
- self.line = LinesModel.objects.create(name='Test Line')
- self.container_type = ContainerTypeModel.objects.create(name='20ft')
+
+ self.user_client_no_rights = DepotUser.objects.create_user(username='user_client_no_rights', password=self.user_password, user_type='CL', email='user_client_no_rights@gmail.com')
+
+ self.user_client_all_rights = DepotUser.objects.create_user(username='user_client_all_rights', password=self.user_password, user_type='CL', email='user_client_all_rights@gmail.com', line=self.line, company=self.company)
+ self.user_client_all_rights.company_permissions.add(ClientPermission.objects.get(codename='can_view_booking').id)
+ self.user_client_all_rights.company_permissions.add(ClientPermission.objects.get(codename='can_manage_booking').id)
+ self.user_client_all_rights.company_permissions.add(ClientPermission.objects.get(codename='can_view_preinfo').id)
+ self.user_client_all_rights.company_permissions.add(ClientPermission.objects.get(codename='can_manage_preinfo').id)
+ self.user_client_all_rights.company_permissions.add(ClientPermission.objects.get(codename='can_view_payment').id)
+ self.user_client_all_rights.company_permissions.add(ClientPermission.objects.get(codename='can_manage_payment').id)
+ self.user_client_all_rights.company_permissions.add(ClientPermission.objects.get(codename='can_manage_company_users').id)
+
+
+ self.user_employee_no_rights = DepotUser.objects.create_user(username='user_employee_no_rights', password=self.user_password, user_type='EM', email='user_employee_no_rights@gmail.com')
+
+ self.user_employee_all_rights = DepotUser.objects.create_user(username='user_employee_all_rights', password=self.user_password, user_type='EM', email='user_employee_all_rights@gmail.com')
+ self.user_employee_all_rights.employee_permissions.add(1)
+ self.user_employee_all_rights.employee_permissions.add(2)
+ self.user_employee_all_rights.employee_permissions.add(3)
+ self.user_employee_all_rights.employee_permissions.add(4)
+ self.user_employee_all_rights.employee_permissions.add(5)
+
self.booking = Booking.objects.create(
number='BOOK123',
container_type=self.container_type,
container_count=10,
line=self.line,
- created_by=self.user.id,
- updated_by=self.user.id
+ created_by=self.user_employee_all_rights.id,
+ updated_by=self.user_employee_all_rights.id,
+ vehicles='',
+ vehicles_left='',
+
)
- def test_booking_list_view(self):
- response = self.client.get(reverse('booking-list'))
+ def test_employee_booking_list_view__anonymouse_user__expect_redirect_302(self):
+ response = self.client.get(reverse_lazy('employee_bookings'))
+ self.assertEqual(response.status_code, 302)
+
+ def test_employee_booking_list_view__client_user_login__expect_forbidden_403(self):
+ self.client.login(username=self.user_client_no_rights.username, password=self.user_password)
+ response = self.client.get(reverse_lazy('employee_bookings'))
+ self.assertEqual(response.status_code, 403)
+
+ def test_employee_booking_list_view__user_login__expect_redirect_200(self):
+ self.client.login(username=self.user_employee_no_rights.username, password=self.user_password)
+ response = self.client.get(reverse_lazy('employee_bookings'))
+ self.assertEqual(response.status_code, 200)
+
+ def test_booking_list_view__user_all_rights__expect_OK(self):
+ self.client.login(username=self.user_employee_all_rights.username, password=self.user_password)
+ response = self.client.get(reverse_lazy('employee_bookings'))
self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(response, 'booking/booking-list.html')
+
+ self.assertTemplateUsed(response, 'employee/booking-list.html')
self.assertContains(response, self.booking.number)
def test_booking_create_view(self):
- response = self.client.post(reverse('booking-create'), {
+ self.assertTrue( self.user_client_all_rights.has_company_perm('can_view_booking'))
+ self.client.login(username=self.user_client_all_rights.username, password=self.user_password)
+
+ response = self.client.post(reverse('client_booking_create'), {
'number': 'BOOK456',
'container_type': self.container_type.id,
'container_count': 5,
'line': self.line.id,
+ 'vehicles': 'Truck1,Truck2',
+ 'vehicles_left': 'Truck1,Truck2',
})
- self.assertEqual(response.status_code, 302)
+ self.assertEqual(response.status_code, 200)
self.assertTrue(Booking.objects.filter(number='BOOK456').exists())
- def test_booking_update_view(self):
- response = self.client.post(reverse('booking-update', args=[self.booking.id]), {
- 'number': 'BOOK123-updated',
- 'container_type': self.container_type.id,
- 'container_count': 15,
- 'line': self.line.id,
- })
- self.assertEqual(response.status_code, 302)
- self.booking.refresh_from_db()
- self.assertEqual(self.booking.number, 'BOOK123-updated')
\ No newline at end of file
+ # def test_booking_update_view(self):
+ # response = self.client.post(reverse('booking-update', args=[self.booking.id]), {
+ # 'number': 'BOOK123-updated',
+ # 'container_type': self.container_type.id,
+ # 'container_count': 15,
+ # 'line': self.line.id,
+ # })
+ # self.assertEqual(response.status_code, 302)
+ # self.booking.refresh_from_db()
+ # self.assertEqual(self.booking.number, 'BOOK123-updated')
\ No newline at end of file
diff --git a/booking/views/__pycache__/client_views.cpython-313.pyc b/booking/views/__pycache__/client_views.cpython-313.pyc
index 5b11697..d96d78c 100644
Binary files a/booking/views/__pycache__/client_views.cpython-313.pyc and b/booking/views/__pycache__/client_views.cpython-313.pyc differ
diff --git a/booking/views/__pycache__/employee_views.cpython-313.pyc b/booking/views/__pycache__/employee_views.cpython-313.pyc
index 8f1e5b5..5a946f5 100644
Binary files a/booking/views/__pycache__/employee_views.cpython-313.pyc and b/booking/views/__pycache__/employee_views.cpython-313.pyc differ
diff --git a/booking/views/employee_views.py b/booking/views/employee_views.py
index 8c27871..ba40e34 100644
--- a/booking/views/employee_views.py
+++ b/booking/views/employee_views.py
@@ -12,7 +12,7 @@ class BookingListView(LoginRequiredMixin, UserPassesTestMixin, ListView):
def test_func(self):
user = self.request.user
- return self.request.user.user_type == 'EMP' or user.is_superuser
+ return self.request.user.user_type == 'EM' or user.is_superuser
def get_queryset(self):
queryset = super().get_queryset()
diff --git a/common/__pycache__/models.cpython-313.pyc b/common/__pycache__/models.cpython-313.pyc
index 63bcfc9..19da3da 100644
Binary files a/common/__pycache__/models.cpython-313.pyc and b/common/__pycache__/models.cpython-313.pyc differ
diff --git a/common/__pycache__/urls.cpython-313.pyc b/common/__pycache__/urls.cpython-313.pyc
index 3951020..074737e 100644
Binary files a/common/__pycache__/urls.cpython-313.pyc and b/common/__pycache__/urls.cpython-313.pyc differ
diff --git a/common/migrations/0004_populate_initial_data.py b/common/migrations/0004_populate_initial_data.py
index c413346..027ecfd 100644
--- a/common/migrations/0004_populate_initial_data.py
+++ b/common/migrations/0004_populate_initial_data.py
@@ -46,24 +46,22 @@ def create_initial_data(apps, schema_editor):
# Companies and Lines
companies = [
- (1, 'GMS', 'GMS', 'Global Maritime Servises'),
- (2, 'TO', 'TO', 'Терминален оператор'),
+ ('GMS', 'GMS', 'Global Maritime Servises'),
+ ('TO', 'TO', 'Терминален оператор'),
]
- for _id, name, short_name, description in companies:
+ for name, short_name, description in companies:
CompanyModel.objects.create(
- id=_id,
name=name,
short_name=short_name,
description=description
)
lines = [
- (1, 'GMS', 'GMS', 'GMS line', 1),
- (2, 'HPG', 'HPG', 'Hapag Lloyds line', 1),
- (3, 'TO', 'TO', 'Терминален оператор line', 2),
+ ('GMS', 'GMS', 'GMS line', 1),
+ ('HPG', 'HPG', 'Hapag Lloyds line', 1),
+ ('TO', 'TO', 'Терминален оператор line', 2),
]
- for _id, name, short_name, description, company_id in lines:
+ for name, short_name, description, company_id in lines:
LinesModel.objects.create(
- id=_id,
name=name,
short_name=short_name,
description=description,
diff --git a/common/migrations/__pycache__/0004_populate_initial_data.cpython-313.pyc b/common/migrations/__pycache__/0004_populate_initial_data.cpython-313.pyc
index 9b9afcc..2cde581 100644
Binary files a/common/migrations/__pycache__/0004_populate_initial_data.cpython-313.pyc and b/common/migrations/__pycache__/0004_populate_initial_data.cpython-313.pyc differ
diff --git a/common/models.py b/common/models.py
index 12482f4..e482091 100644
--- a/common/models.py
+++ b/common/models.py
@@ -9,7 +9,7 @@ class NomenclatureBaseModel(models.Model):
class Meta:
abstract = True
ordering = ['name']
-
+ app_label = 'common'
def __str__(self):
return self.name
@@ -30,8 +30,7 @@ class LinesModel(NomenclatureBaseModel):
app_label = 'common'
class OperationModel(NomenclatureBaseModel):
- class Meta:
- app_label = 'common'
+ ...
class ContainerKindModel(NomenclatureBaseModel):
...
@@ -47,5 +46,8 @@ class ContainerTypeModel(models.Model):
)
deleted = models.BooleanField(default=False)
+ class Meta:
+ app_label = 'common'
+
def __str__(self):
return self.name
\ No newline at end of file
diff --git a/common/templatetags/__pycache__/filters.cpython-313.pyc b/common/templatetags/__pycache__/filters.cpython-313.pyc
index a51933d..de0fbb3 100644
Binary files a/common/templatetags/__pycache__/filters.cpython-313.pyc and b/common/templatetags/__pycache__/filters.cpython-313.pyc differ
diff --git a/common/utils/__pycache__/utils.cpython-313.pyc b/common/utils/__pycache__/utils.cpython-313.pyc
index 40c5806..761988d 100644
Binary files a/common/utils/__pycache__/utils.cpython-313.pyc and b/common/utils/__pycache__/utils.cpython-313.pyc differ
diff --git a/common/views/__pycache__/barrier_views.cpython-313.pyc b/common/views/__pycache__/barrier_views.cpython-313.pyc
index 3eca6e8..3f7757c 100644
Binary files a/common/views/__pycache__/barrier_views.cpython-313.pyc and b/common/views/__pycache__/barrier_views.cpython-313.pyc differ
diff --git a/common/views/__pycache__/client_views.cpython-313.pyc b/common/views/__pycache__/client_views.cpython-313.pyc
index 9e4fd78..1ba8af3 100644
Binary files a/common/views/__pycache__/client_views.cpython-313.pyc and b/common/views/__pycache__/client_views.cpython-313.pyc differ
diff --git a/common/views/__pycache__/employee_views.cpython-313.pyc b/common/views/__pycache__/employee_views.cpython-313.pyc
index 1d04850..8bc5977 100644
Binary files a/common/views/__pycache__/employee_views.cpython-313.pyc and b/common/views/__pycache__/employee_views.cpython-313.pyc differ
diff --git a/common/views/__pycache__/shared_views.cpython-313.pyc b/common/views/__pycache__/shared_views.cpython-313.pyc
index d7f1459..5629e80 100644
Binary files a/common/views/__pycache__/shared_views.cpython-313.pyc and b/common/views/__pycache__/shared_views.cpython-313.pyc differ
diff --git a/containers/__pycache__/urls.cpython-313.pyc b/containers/__pycache__/urls.cpython-313.pyc
index 7de532c..381bcf5 100644
Binary files a/containers/__pycache__/urls.cpython-313.pyc and b/containers/__pycache__/urls.cpython-313.pyc differ
diff --git a/containers/views/__pycache__/barrier_views.cpython-313.pyc b/containers/views/__pycache__/barrier_views.cpython-313.pyc
index 8cb28fc..a147db5 100644
Binary files a/containers/views/__pycache__/barrier_views.cpython-313.pyc and b/containers/views/__pycache__/barrier_views.cpython-313.pyc differ
diff --git a/containers/views/__pycache__/client_views.cpython-313.pyc b/containers/views/__pycache__/client_views.cpython-313.pyc
index 0946679..52931ae 100644
Binary files a/containers/views/__pycache__/client_views.cpython-313.pyc and b/containers/views/__pycache__/client_views.cpython-313.pyc differ
diff --git a/containers/views/__pycache__/common.cpython-313.pyc b/containers/views/__pycache__/common.cpython-313.pyc
index 8a1441e..3ffc94c 100644
Binary files a/containers/views/__pycache__/common.cpython-313.pyc and b/containers/views/__pycache__/common.cpython-313.pyc differ
diff --git a/containers/views/__pycache__/employee_views.cpython-313.pyc b/containers/views/__pycache__/employee_views.cpython-313.pyc
index 0a9bb6e..f378628 100644
Binary files a/containers/views/__pycache__/employee_views.cpython-313.pyc and b/containers/views/__pycache__/employee_views.cpython-313.pyc differ
diff --git a/images/web_depot.tar b/images/web_depot.tar
index 80245d5..c04023a 100644
Binary files a/images/web_depot.tar and b/images/web_depot.tar differ
diff --git a/payments/__pycache__/services.cpython-313.pyc b/payments/__pycache__/services.cpython-313.pyc
index 081ce21..6dcf0d6 100644
Binary files a/payments/__pycache__/services.cpython-313.pyc and b/payments/__pycache__/services.cpython-313.pyc differ
diff --git a/payments/__pycache__/urls.cpython-313.pyc b/payments/__pycache__/urls.cpython-313.pyc
index 237ee57..1490b36 100644
Binary files a/payments/__pycache__/urls.cpython-313.pyc and b/payments/__pycache__/urls.cpython-313.pyc differ
diff --git a/payments/__pycache__/views.cpython-313.pyc b/payments/__pycache__/views.cpython-313.pyc
index 09353e2..807352b 100644
Binary files a/payments/__pycache__/views.cpython-313.pyc and b/payments/__pycache__/views.cpython-313.pyc differ
diff --git a/preinfo/views/__pycache__/client_views.cpython-313.pyc b/preinfo/views/__pycache__/client_views.cpython-313.pyc
index 73aa4ad..bcf3a86 100644
Binary files a/preinfo/views/__pycache__/client_views.cpython-313.pyc and b/preinfo/views/__pycache__/client_views.cpython-313.pyc differ
diff --git a/preinfo/views/__pycache__/employee_views.cpython-313.pyc b/preinfo/views/__pycache__/employee_views.cpython-313.pyc
index 2e70905..b0fde8d 100644
Binary files a/preinfo/views/__pycache__/employee_views.cpython-313.pyc and b/preinfo/views/__pycache__/employee_views.cpython-313.pyc differ