ecodev-core 0.0.17__tar.gz → 0.0.19__tar.gz

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.

Potentially problematic release.


This version of ecodev-core might be problematic. Click here for more details.

Files changed (25) hide show
  1. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/PKG-INFO +1 -1
  2. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/__init__.py +2 -1
  3. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/app_user.py +12 -2
  4. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/authentication.py +9 -9
  5. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/pyproject.toml +1 -1
  6. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/LICENSE.md +0 -0
  7. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/README.md +0 -0
  8. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/app_activity.py +0 -0
  9. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/app_rights.py +0 -0
  10. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/auth_configuration.py +0 -0
  11. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/backup.py +0 -0
  12. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/check_dependencies.py +0 -0
  13. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/custom_equal.py +0 -0
  14. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/db_connection.py +0 -0
  15. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/db_filters.py +0 -0
  16. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/db_insertion.py +0 -0
  17. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/db_retrieval.py +0 -0
  18. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/enum_utils.py +0 -0
  19. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/list_utils.py +0 -0
  20. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/logger.py +0 -0
  21. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/pandas_utils.py +0 -0
  22. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/permissions.py +0 -0
  23. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/pydantic_utils.py +0 -0
  24. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/read_write.py +0 -0
  25. {ecodev_core-0.0.17 → ecodev_core-0.0.19}/ecodev_core/safe_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ecodev-core
3
- Version: 0.0.17
3
+ Version: 0.0.19
4
4
  Summary: Low level sqlmodel/fastapi/pydantic building blocks
5
5
  License: MIT
6
6
  Author: Thomas Epelbaum
@@ -10,6 +10,7 @@ from ecodev_core.app_rights import AppRight
10
10
  from ecodev_core.app_user import AppUser
11
11
  from ecodev_core.app_user import select_user
12
12
  from ecodev_core.app_user import upsert_app_users
13
+ from ecodev_core.app_user import upsert_new_user
13
14
  from ecodev_core.auth_configuration import AUTH
14
15
  from ecodev_core.authentication import attempt_to_log
15
16
  from ecodev_core.authentication import get_access_token
@@ -78,4 +79,4 @@ __all__ = [
78
79
  'enum_converter', 'ServerSideFilter', 'get_rows', 'count_rows', 'ServerSideField', 'get_raw_df',
79
80
  'generic_insertion', 'custom_equal', 'is_authorized_user', 'get_method', 'AppActivity',
80
81
  'fastapi_monitor', 'dash_monitor', 'is_monitoring_user', 'get_recent_activities', 'select_user',
81
- 'get_access_token', 'safe_get_user', 'backup', 'group_by', 'get_excelfile']
82
+ 'get_access_token', 'safe_get_user', 'backup', 'group_by', 'get_excelfile', 'upsert_new_user']
@@ -2,7 +2,7 @@
2
2
  Module implementing the sqlmodel orm part of the user table
3
3
  """
4
4
  from pathlib import Path
5
- from typing import Dict
5
+ from typing import Any
6
6
  from typing import List
7
7
  from typing import Optional
8
8
  from typing import TYPE_CHECKING
@@ -39,7 +39,7 @@ class AppUser(SQLModel, table=True): # type: ignore
39
39
  rights: List['AppRight'] = Relationship(back_populates='user')
40
40
 
41
41
 
42
- def user_convertor(df: pd.DataFrame) -> List[Dict]:
42
+ def user_convertor(df: pd.DataFrame) -> List[Any]:
43
43
  """
44
44
  Dummy user convertor
45
45
  """
@@ -90,3 +90,13 @@ def select_user(username: str, session: Session) -> AppUser:
90
90
  sqlalchemy.exc.MultipleResultsFound: Should normally never be an issue.
91
91
  """
92
92
  return session.exec(select(AppUser).where(col(AppUser.user) == username)).one()
93
+
94
+
95
+ def upsert_new_user(user_id: int, user: str, session: Session, password: str = '') -> None:
96
+ """
97
+ Upsert a new user if not already present in db
98
+ """
99
+ if not session.exec(select(AppUser).where(col(AppUser.id) == user_id)).first():
100
+ session.add(AppUser(user=user, password=password, permission=Permission.Consultant,
101
+ id=user_id))
102
+ session.commit()
@@ -93,20 +93,23 @@ class JwtAuth(AuthenticationBackend):
93
93
  request.session.update(token)
94
94
  return True if token else False
95
95
 
96
- @staticmethod
97
- def authorized(form: Any):
96
+ def authorized(self, form: Any):
98
97
  """
99
98
  Check that the user information contained in the form corresponds to an admin user
100
99
  """
101
100
  with Session(engine) as session:
102
101
  try:
103
- token = attempt_to_log(form.get('username', ''), form.get('password', ''), session)
104
- if is_admin_user(token['access_token']):
105
- return token
106
- return None
102
+ return self.admin_token(form, session)
107
103
  except HTTPException:
108
104
  return None
109
105
 
106
+ def admin_token(self, form: Any, session: Session) -> Union[Dict[str, str], None]:
107
+ """
108
+ Unsafe attempt to retrieve the token, only return it if admin rights
109
+ """
110
+ token = attempt_to_log(form.get('username', ''), form.get('password', ''), session)
111
+ return token if is_admin_user(token['access_token']) else None
112
+
110
113
  async def logout(self, request: Request) -> bool:
111
114
  """
112
115
  Logout procedure: clears the cache
@@ -238,8 +241,6 @@ def _verify_access_token(token: str,
238
241
  """
239
242
  try:
240
243
  payload = jwt.decode(token, AUTH.secret_key, algorithms=[AUTH.algorithm])
241
- log.critical(tfa_value)
242
- log.critical(payload.get('tfa'))
243
244
  if tfa_check and (not tfa_value or not _check_password(tfa_value, payload.get('tfa'))):
244
245
  raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=INVALID_TFA,
245
246
  headers={'WWW-Authenticate': 'Bearer'})
@@ -264,4 +265,3 @@ def _check_password(plain_password: Optional[str], hashed_password: str) -> bool
264
265
  Check the passed password (compare it to the passed encoded one).
265
266
  """
266
267
  return CONTEXT.verify(plain_password, hashed_password)
267
-
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "ecodev-core"
3
- version = "0.0.17"
3
+ version = "0.0.19"
4
4
  description = "Low level sqlmodel/fastapi/pydantic building blocks"
5
5
  authors = ["Thomas Epelbaum <tomepel@gmail.com>",
6
6
  "Olivier Gabriel <olivier.gabriel.geom@gmail.com>",
File without changes
File without changes