cornflow 1.2.2__py3-none-any.whl → 1.2.3a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -79,9 +79,9 @@ def register_base_permissions_command(external_app: str = None, verbose: bool =
79
79
 
80
80
  # TODO: for now the permission are not going to get deleted just in case.
81
81
  # We are just going to register new permissions
82
- # if len(permissions_to_delete) > 0:
83
- # for permission in permissions_to_delete:
84
- # db.session.delete(permission)
82
+ if len(permissions_to_delete) > 0:
83
+ for permission in permissions_to_delete:
84
+ db.session.delete(permission)
85
85
 
86
86
  try:
87
87
  db.session.commit()
cornflow/shared/const.py CHANGED
@@ -1,7 +1,7 @@
1
1
  """
2
2
  In this file we import the values for different constants on cornflow server
3
3
  """
4
- CORNFLOW_VERSION = "1.2.2"
4
+ CORNFLOW_VERSION = "1.2.3a1"
5
5
  INTERNAL_TOKEN_ISSUER = "cornflow"
6
6
 
7
7
  # endpoints responses for health check
@@ -29,6 +29,7 @@ from cornflow.app import (
29
29
  register_dag_permissions,
30
30
  register_roles,
31
31
  register_views,
32
+ register_base_assignations,
32
33
  )
33
34
  from cornflow.commands.dag import register_deployed_dags_command_test
34
35
  from cornflow.endpoints import resources, alarms_resources
@@ -494,3 +495,92 @@ class TestCommands(TestCase):
494
495
  },
495
496
  )
496
497
  self.assertEqual(403, response.status_code)
498
+
499
+ def test_permissions_not_deleted_when_roles_removed_from_code(self):
500
+ """
501
+ Test that permissions are NOT deleted when roles are removed from ROLES_WITH_ACCESS.
502
+
503
+ This test demonstrates the current bug: when a role is removed from
504
+ ROLES_WITH_ACCESS in an endpoint's code, the corresponding permissions
505
+ in the database are not automatically deleted. This happens because
506
+ the deletion logic in register_base_permissions_command is commented out.
507
+
508
+ The test should currently FAIL to demonstrate the bug exists.
509
+ """
510
+ # First, initialize the access system normally
511
+ self.runner.invoke(access_init)
512
+
513
+ # Get the original ROLES_WITH_ACCESS for ExampleDataListEndpoint
514
+ from cornflow.endpoints.example_data import ExampleDataListEndpoint
515
+
516
+ original_roles = ExampleDataListEndpoint.ROLES_WITH_ACCESS.copy()
517
+
518
+ # Verify initial permissions are created for all three roles
519
+ # Get the view ID for the endpoint
520
+ from cornflow.models import ViewModel
521
+
522
+ view = ViewModel.query.filter_by(name="example-data").first()
523
+ self.assertIsNotNone(view, "example-data view should exist")
524
+
525
+ # Check permissions exist for all original roles
526
+ from cornflow.shared.const import ACTIONS_MAP
527
+ from cornflow.models import PermissionViewRoleModel
528
+
529
+ # Check GET action permissions (action_id=1 is typically GET)
530
+ get_action_id = 1
531
+ initial_permissions = PermissionViewRoleModel.query.filter_by(
532
+ api_view_id=view.id, action_id=get_action_id
533
+ ).all()
534
+
535
+ initial_role_ids = [perm.role_id for perm in initial_permissions]
536
+ self.assertEqual(
537
+ len(original_roles),
538
+ len(initial_permissions),
539
+ f"Should have permissions for all {len(original_roles)} original roles",
540
+ )
541
+
542
+ # Now simulate removing PLANNER_ROLE from ROLES_WITH_ACCESS
543
+ from cornflow.shared.const import PLANNER_ROLE, VIEWER_ROLE, ADMIN_ROLE
544
+
545
+ modified_roles = [VIEWER_ROLE, ADMIN_ROLE] # Remove PLANNER_ROLE
546
+
547
+ # Temporarily modify the ROLES_WITH_ACCESS
548
+ ExampleDataListEndpoint.ROLES_WITH_ACCESS = modified_roles
549
+
550
+ try:
551
+
552
+ # Run the permission registration again
553
+ # (this simulates redeploying the app with modified roles)
554
+ self.runner.invoke(register_base_assignations, ["-v"])
555
+
556
+ # Check permissions after the "code change"
557
+ updated_permissions = PermissionViewRoleModel.query.filter_by(
558
+ api_view_id=view.id, action_id=get_action_id
559
+ ).all()
560
+
561
+ updated_role_ids = [perm.role_id for perm in updated_permissions]
562
+
563
+ # THIS IS THE BUG: The permission for PLANNER_ROLE should be deleted
564
+ # but it's not because the deletion logic is commented out
565
+ # So we expect this assertion to FAIL, demonstrating the bug
566
+ self.assertEqual(
567
+ len(modified_roles),
568
+ len(updated_permissions),
569
+ f"After removing PLANNER_ROLE from code, should only have {len(modified_roles)} permissions, "
570
+ f"but still has {len(updated_permissions)} permissions. "
571
+ f"This demonstrates the bug: permissions are not deleted when roles are removed from ROLES_WITH_ACCESS.",
572
+ )
573
+
574
+ # Also check that PLANNER_ROLE permission was actually removed
575
+ planner_permissions = [
576
+ perm for perm in updated_permissions if perm.role_id == PLANNER_ROLE
577
+ ]
578
+ self.assertEqual(
579
+ 0,
580
+ len(planner_permissions),
581
+ "PLANNER_ROLE permission should have been deleted but still exists",
582
+ )
583
+
584
+ finally:
585
+ # Restore original ROLES_WITH_ACCESS to avoid affecting other tests
586
+ ExampleDataListEndpoint.ROLES_WITH_ACCESS = original_roles
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cornflow
3
- Version: 1.2.2
3
+ Version: 1.2.3a1
4
4
  Summary: cornflow is an open source multi-solver optimization server with a REST API built using flask.
5
5
  Home-page: https://github.com/baobabsoluciones/cornflow
6
6
  Author: baobab soluciones
@@ -14,7 +14,7 @@ Requires-Dist: alembic==1.9.2
14
14
  Requires-Dist: apispec<=6.3.0
15
15
  Requires-Dist: cachetools==5.3.3
16
16
  Requires-Dist: click<=8.1.7
17
- Requires-Dist: cornflow-client>=1.2.2
17
+ Requires-Dist: cornflow-client>=1.2.0
18
18
  Requires-Dist: cryptography<=44.0.1
19
19
  Requires-Dist: disposable-email-domains>=0.0.86
20
20
  Requires-Dist: Flask==2.3.2
@@ -32,7 +32,7 @@ cornflow/commands/access.py,sha256=NTZJFF9la8TDuMcD_ISQtJTj-wtM2p1dddokQJHtkj0,7
32
32
  cornflow/commands/actions.py,sha256=4AwgAmyI6VeaugkISvTlNGrIzMMU_-ZB3MhwDD_CIEA,1544
33
33
  cornflow/commands/cleanup.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
34
  cornflow/commands/dag.py,sha256=AtagFGnB_ucfO0qUawDgd4iRoBCVc-RiOs08DqXSwXM,3786
35
- cornflow/commands/permissions.py,sha256=mDPqiY2r2YXlUg4wmZRoI4GAMVFC6AjNT3kqzPEKUw8,6627
35
+ cornflow/commands/permissions.py,sha256=iNa8I1jsuBBdA1XqoNz_tbm7YAb1-Oc6nitepYLNPRg,6621
36
36
  cornflow/commands/roles.py,sha256=Oux-UkswkQ74zqaMEJYIEsZpQZGBcGaSahVzx9feAHU,1516
37
37
  cornflow/commands/schemas.py,sha256=40dZSJ2nEqBa7Crb6DbFmnclT5e8ljAIjscOgHr9lhk,1970
38
38
  cornflow/commands/users.py,sha256=2YTbNYY5kZL6ujxGP4fyYgqtv5uuVGdkLR31n7OFFaE,2477
@@ -119,7 +119,7 @@ cornflow/schemas/user_role.py,sha256=e5y6RgdZZtLqD-h2B3sa5WokI5-pT78tWw85IG34I74
119
119
  cornflow/schemas/view.py,sha256=ctq9Y1TmjrWdyOqgDYeEx7qbbuNLKfSiNOlFTlXmpaw,429
120
120
  cornflow/shared/__init__.py,sha256=1ahcBwWOsSjGI4FEm77JBQjitBdBszOncKcEMjzwGYE,29
121
121
  cornflow/shared/compress.py,sha256=pohQaGs1xbH8CN6URIH6BAHA--pFq7Hmjz8oI3c3B5c,1347
122
- cornflow/shared/const.py,sha256=ndYbK94cs5tmwX1mFs6S_t5v_mC7il24IcicmNHL9Zw,3553
122
+ cornflow/shared/const.py,sha256=nepftaeiyR-pmAXnHwws5MqCARoTqWPG_-TtCw3KufM,3555
123
123
  cornflow/shared/email.py,sha256=QNDDMv86LZObkevSCyUbLQeR2UD3zWScPIr82NDzYHQ,3437
124
124
  cornflow/shared/exceptions.py,sha256=E82488IiwTXCv8iwrnGvkTonhJcwbeE5ARO4Zsmhl2c,6966
125
125
  cornflow/shared/licenses.py,sha256=Lc71Jw2NxVTFWtoXdQ9wJX_o3BDfYg1xVoehDXvnCkQ,1328
@@ -148,7 +148,7 @@ cornflow/tests/unit/test_apiview.py,sha256=03M1GsQRVK7zqmslhOJXr4lLDLY2gMAgg86nk
148
148
  cornflow/tests/unit/test_application.py,sha256=ZVmTQDUOkPRxHqt6mWU9G_lQ3jJNMJR0cx7IkLMFGrU,1715
149
149
  cornflow/tests/unit/test_cases.py,sha256=Ez9dxlZL-SUf9DW9b_A_qPowHqUZ-TA73DMOzeBeLIU,37718
150
150
  cornflow/tests/unit/test_cli.py,sha256=E2w-Lzgx_k__0mYwlbg2z80_z9nwPZKI0CbgyGmpQRY,18775
151
- cornflow/tests/unit/test_commands.py,sha256=kvO8Vn60rj3WBG2oXw7NpDSEYoGLNe806txbJPhtNJo,14722
151
+ cornflow/tests/unit/test_commands.py,sha256=ZajFnltdPlw4o6B5Cf7ZSYhZb6fM9z6tARhFOhKMug8,18695
152
152
  cornflow/tests/unit/test_dags.py,sha256=XsOi5bBJQdQz3DmYAVJf1myoAsRyBBdmku-xBr0Bku0,13386
153
153
  cornflow/tests/unit/test_data_checks.py,sha256=6s50d1iuRTUcAYn14oEcRS39ZZ6E9ussU4YpkpYhtC4,8612
154
154
  cornflow/tests/unit/test_example_data.py,sha256=D-Tgnqw7NZlnBXaDcUU0reNhAca5JlJP2Sdn3KdS4Sw,4127
@@ -169,8 +169,8 @@ cornflow/tests/unit/test_tables.py,sha256=SW_K8LRLwR1nB0uH8CPQCjeN8Gei-TasAgkOin
169
169
  cornflow/tests/unit/test_token.py,sha256=PZ11b46UCQpCESsRiAPhpgWkGAsAwKCVNxVQai_kxXM,4199
170
170
  cornflow/tests/unit/test_users.py,sha256=N5tcF5nSncD0F_ZlBxGuS87p6kNS4hUzRLr3_AcnK-o,22802
171
171
  cornflow/tests/unit/tools.py,sha256=ag3sWv2WLi498R1GL5AOUnXqSsszD3UugzLZLC5NqAw,585
172
- cornflow-1.2.2.dist-info/METADATA,sha256=PMSZtEpia3rytt8MfgpZn2zUEzh-Lwi2LtEVXYBt394,9527
173
- cornflow-1.2.2.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
174
- cornflow-1.2.2.dist-info/entry_points.txt,sha256=q9cPKAFBsmHkERCqQ2JcOTM-tVBLHTl-DGxwCXowAWM,46
175
- cornflow-1.2.2.dist-info/top_level.txt,sha256=Qj9kLFJW1PLb-ZV2s_aCkQ-Wi5W6KC6fFR-LTBrx-rU,24
176
- cornflow-1.2.2.dist-info/RECORD,,
172
+ cornflow-1.2.3a1.dist-info/METADATA,sha256=zrEdE7w5XdzXENv06QWMxLNDmS0Zfcvpq5zsaJtuaGs,9529
173
+ cornflow-1.2.3a1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
174
+ cornflow-1.2.3a1.dist-info/entry_points.txt,sha256=q9cPKAFBsmHkERCqQ2JcOTM-tVBLHTl-DGxwCXowAWM,46
175
+ cornflow-1.2.3a1.dist-info/top_level.txt,sha256=Qj9kLFJW1PLb-ZV2s_aCkQ-Wi5W6KC6fFR-LTBrx-rU,24
176
+ cornflow-1.2.3a1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.8.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5