Skip to content

Commit

Permalink
Merge pull request #895 from EvanBldy/main
Browse files Browse the repository at this point in the history
various improvements
  • Loading branch information
frankrousseau authored Dec 11, 2024
2 parents 2e6b354 + 6a28d98 commit 88fccab
Show file tree
Hide file tree
Showing 35 changed files with 257 additions and 202 deletions.
10 changes: 5 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ install_requires =
Jinja2==3.1.4
ldap3==2.9.1
matterhook==0.2
meilisearch==0.32.0
meilisearch==0.33.0
numpy==2.0.1; python_version == '3.9'
numpy==2.1.3; python_version >= '3.10'
numpy==2.2.0; python_version >= '3.10'
opencv-python==4.10.0.84
OpenTimelineIO==0.17.0
OpenTimelineIO-Plugins==0.17.0
Expand All @@ -72,7 +72,7 @@ install_requires =
python-slugify==8.0.4
python-socketio==5.11.4
pytz==2024.2
redis==5.2.0
redis==5.2.1
requests==2.32.3
rq==2.0.0
slackclient==2.9.4
Expand Down Expand Up @@ -100,12 +100,12 @@ test =
fakeredis==2.26.1
mixer==7.2.2
pytest-cov==6.0.0
pytest==8.3.3
pytest==8.3.4

monitoring =
prometheus-flask-exporter==0.23.1
pygelf==0.4.2
sentry-sdk==2.19.0
sentry-sdk==2.19.2

lint =
autoflake==2.3.1
Expand Down
2 changes: 1 addition & 1 deletion tests/auth/test_auth_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,5 +290,5 @@ def test_get_last_login_logs(self):
self.log_in("[email protected]")
login_logs = self.get("/data/events/login-logs/last")
self.assertEqual(len(login_logs), 4)
login_logs = self.get("/data/events/login-logs/last?page_size=2")
login_logs = self.get("/data/events/login-logs/last?limit=2")
self.assertEqual(len(login_logs), 2)
2 changes: 1 addition & 1 deletion tests/events/test_event_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_get_last_events(self):

events = self.get("/data/events/last")
self.assertEqual(len(events), 4)
events = self.get("/data/events/last?page_size=2")
events = self.get("/data/events/last?limit=2")
self.assertEqual(len(events), 2)
events = self.get("/data/events/last?before=%s" % before)
self.assertEqual(len(events), 2)
Expand Down
4 changes: 2 additions & 2 deletions tests/services/test_events_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_get_last_events(self):
)
events = events_service.get_last_events()
self.assertEqual(len(events), 3)
events = events_service.get_last_events(page_size=2)
events = events_service.get_last_events(limit=2)
self.assertEqual(len(events), 2)
date = fields.get_date_object(asset["created_at"], "%Y-%m-%dT%H:%M:%S")
events = events_service.get_last_events(before=date)
Expand All @@ -44,5 +44,5 @@ def test_get_last_login_logs(self):
events_service.create_login_log(self.person.id, "127.0.0.1", "web")
login_logs = events_service.get_last_login_logs()
self.assertEqual(len(login_logs), 4)
login_logs = events_service.get_last_login_logs(page_size=2)
login_logs = events_service.get_last_login_logs(limit=2)
self.assertEqual(len(login_logs), 2)
2 changes: 1 addition & 1 deletion zou/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def indexer_key_error(error):
raise error


if not config.DEBUG:
if config.DEBUG:

@app.errorhandler(Exception)
def server_error(error):
Expand Down
32 changes: 17 additions & 15 deletions zou/app/blueprints/auth/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def get(self):
description: Person not found
"""
person = persons_service.get_current_user(relations=True)
organisation = persons_service.get_organisation()
organisation = persons_service.get_organisation(
sensitive=permissions.has_admin_permissions()
)
return {
"authenticated": True,
"user": person,
Expand Down Expand Up @@ -227,28 +229,28 @@ def post(self):
"HTTP_X_REAL_IP", request.remote_addr
)

organisation = persons_service.get_organisation(
sensitive=user["role"] != "admin"
)

response = jsonify(
{
"user": user,
"organisation": organisation,
"login": True,
"access_token": access_token,
"refresh_token": refresh_token,
}
)

if is_from_browser(request.user_agent):
organisation = persons_service.get_organisation()
response = jsonify(
{
"user": user,
"organisation": organisation,
"login": True,
}
)
set_access_cookies(response, access_token)
set_refresh_cookies(response, refresh_token)
events_service.create_login_log(user["id"], ip_address, "web")
else:
events_service.create_login_log(
user["id"], ip_address, "script"
)
response = {
"login": True,
"user": user,
"access_token": access_token,
"refresh_token": refresh_token,
}
current_app.logger.info(f"User {email} is logged in.")
return response
except WrongUserException:
Expand Down
8 changes: 4 additions & 4 deletions zou/app/blueprints/breakdown/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,14 @@ def get(self, project_id):
type: string
format: Number
x-example: 2
- in: limit
name: page
- in: query
name: limit
required: False
type: string
format: Number
x-example: 100
- in: cursor_created_at
name: page
- in: query
name: cursor_created_at
required: False
type: string
format: Datetime
Expand Down
17 changes: 16 additions & 1 deletion zou/app/blueprints/crud/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,22 @@ def all_entries(self, query=None, relations=False):
if query is None:
query = self.model.query

return self.model.serialize_list(query.all(), relations=relations)
return self.serialize_list(query.all(), relations=relations)

def serialize_list(self, entries, relations=False):
return self.model.serialize_list(
entries,
relations=relations,
ignored_attrs=(
[]
if permissions.has_admin_permissions()
else [
"chat_token_slack",
"chat_webhook_mattermost",
"chat_token_discord",
]
),
)

def paginated_entries(self, query, page, limit=None, relations=False):
total = query.count()
Expand Down
13 changes: 0 additions & 13 deletions zou/app/blueprints/crud/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,6 @@ class CommentsResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, Comment)

def check_read_permissions(self, options=None):
if options is not None:
if "project_id" in options:
user_service.check_project_access(options["project_id"])
if (
permissions.has_vendor_permissions()
or permissions.has_client_permissions()
):
raise permissions.PermissionDenied
else:
return True
return permissions.check_admin_permissions()


class CommentResource(BaseModelResource):
def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def all_entries(self, query=None, relations=False):
if query is None:
query = self.model.query

return self.model.serialize_list(
return self.serialize_list(
query.limit(1000).all(), relations=relations
)

Expand Down
18 changes: 9 additions & 9 deletions zou/app/blueprints/crud/metadata_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ def add_project_permission_filter(self, query):
)
return query

def all_entries(self, query=None, relations=True):
if query is None:
query = self.model.query

return [
metadata_descriptor.serialize(relations=relations)
for metadata_descriptor in query.all()
]

def check_creation_integrity(self, data):
"""
Check if the data descriptor has a valid data_type.
Expand All @@ -46,6 +37,15 @@ def check_creation_integrity(self, data):
raise WrongParameterException("Invalid data_type")
return True

def all_entries(self, query=None, relations=True):
if query is None:
query = self.model.query

return [
metadata_descriptor.serialize(relations=relations)
for metadata_descriptor in query.all()
]


class MetadataDescriptorResource(BaseModelResource):

Expand Down
17 changes: 16 additions & 1 deletion zou/app/blueprints/crud/organisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from zou.app.blueprints.crud.base import BaseModelResource, BaseModelsResource

from zou.app.services import persons_service
from zou.app.utils.permissions import has_admin_permissions


class OrganisationsResource(BaseModelsResource):
Expand All @@ -24,6 +25,20 @@ def pre_update(self, instance_dict, data):
data["hours_by_day"] = float(data["hours_by_day"])
return data

def serialize_instance(self, data, relations=True):
return data.serialize(
relations=relations,
ignored_attrs=(
[]
if has_admin_permissions()
else [
"chat_token_slack",
"chat_webhook_mattermost",
"chat_token_discord",
]
),
)

def post_update(self, instance_dict, data):
persons_service.clear_oranisation_cache()
persons_service.clear_organisation_cache()
return instance_dict
16 changes: 8 additions & 8 deletions zou/app/blueprints/events/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get(self):
type: boolean
default: False
- in: query
name: page_size
name: limit
type: integer
default: 100
x-example: 100
Expand All @@ -50,7 +50,7 @@ def get(self):
("after", None, False),
("before", None, False),
("only_files", False, False),
("page_size", 100, False),
("limit", 100, False),
("project_id", None, False),
("name", None, False),
],
Expand All @@ -59,7 +59,7 @@ def get(self):
permissions.check_manager_permissions()
before = self.parse_date_parameter(args["before"])
after = self.parse_date_parameter(args["after"])
page_size = args["page_size"]
limit = args["limit"]
only_files = args["only_files"] == "true"
project_id = args.get("project_id", None)
name = args["name"]
Expand All @@ -71,7 +71,7 @@ def get(self):
return events_service.get_last_events(
after=after,
before=before,
page_size=page_size,
limit=limit,
only_files=only_files,
project_id=project_id,
name=name,
Expand All @@ -93,18 +93,18 @@ def get(self):
format: date
x-example: "2022-07-12T00:00:00"
- in: query
name: page_size
name: limit
type: integer
x-example: 100
responses:
200:
description: All login logs
"""
args = self.get_args(["before", ("page_size", 100)])
args = self.get_args(["before", ("limit", 100)])

permissions.check_manager_permissions()
before = None
if args["before"] is not None:
before = date_helpers.get_datetime_from_string(args["before"])
page_size = args["page_size"]
return events_service.get_last_login_logs(before, page_size)
limit = args["limit"]
return events_service.get_last_login_logs(before, limit)
21 changes: 15 additions & 6 deletions zou/app/blueprints/export/csv/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def check_permissions(self, project_id):
def build_headers(self, metadata_infos, validation_columns):
headers = ["Project", "Type", "Name", "Description", "Time Spent"]

metadata_headers = [name for (name, _) in metadata_infos]
metadata_headers = [name for (name, _, _) in metadata_infos]

validation_assignations_columns = []
for validation_column in validation_columns:
Expand Down Expand Up @@ -97,10 +97,15 @@ def build_row(self, result, metadata_infos, validation_columns):
for person_id in task["assignees"]
]
)

for _, field_name in metadata_infos:
result_metadata = result.get("data", {}) or {}
row.append(result_metadata.get(field_name, ""))
result_data = result.get("data", {}) or {}
for _, field_name, data_type in metadata_infos:
result_metadata = result_data.get(field_name, "")
if data_type == "boolean":
row.append(
"true" if result_metadata.lower() == "true" else "false"
)
else:
row.append(result_metadata)

for column in validation_columns:
if column in task_map:
Expand Down Expand Up @@ -153,7 +158,11 @@ def get_metadata_infos(self, project_id):
]

columns = [
(descriptor["name"], descriptor["field_name"])
(
descriptor["name"],
descriptor["field_name"],
descriptor["data_type"],
)
for descriptor in descriptors
]

Expand Down
Loading

0 comments on commit 88fccab

Please sign in to comment.