Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes #857

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion zou/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def id_parameter_format_error(error):

@app.errorhandler(WrongParameterException)
def wrong_parameter(error):
return jsonify(error=True, message=str(error)), 400
return jsonify(error=True, message=str(error), data=error.dict), 400


@app.errorhandler(ExpiredSignatureError)
Expand Down
4 changes: 2 additions & 2 deletions zou/app/blueprints/chats/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
persons_service,
user_service,
)
from zou.app.services.exception import ArgumentsException
from zou.app.services.exception import WrongParameterException


class ChatResource(Resource):
Expand Down Expand Up @@ -116,7 +116,7 @@ def post(self, entity_id):

chat = chats_service.get_chat(entity_id)
if person["id"] not in chat["participants"]:
raise ArgumentsException("You are not a participant of this chat")
raise WrongParameterException("You are not a participant of this chat")

return (
chats_service.create_chat_message(
Expand Down
10 changes: 5 additions & 5 deletions zou/app/blueprints/crud/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from zou.app.mixin import ArgsMixin
from zou.app.utils import events, fields, permissions, query
from zou.app.services.exception import (
ArgumentsException,
WrongParameterException,
WrongParameterException,
)

Expand Down Expand Up @@ -233,7 +233,7 @@ def post(self):
try:
data = request.json
if data is None:
raise ArgumentsException(
raise WrongParameterException(
"Data are empty. Please verify that you sent JSON data and"
" that you set the right headers."
)
Expand All @@ -254,7 +254,7 @@ def post(self):
current_app.logger.error(str(exception), exc_info=1)
return {"message": str(exception)}, 400

except ArgumentsException as exception:
except WrongParameterException as exception:
current_app.logger.error(str(exception), exc_info=1)
return (
exception.dict
Expand Down Expand Up @@ -402,7 +402,7 @@ def put(self, instance_id):
try:
data = self.get_arguments()
if data is None:
raise ArgumentsException(
raise WrongParameterException(
"Data are empty. Please verify that you sent JSON data and"
" that you set the right headers."
)
Expand All @@ -425,7 +425,7 @@ def put(self, instance_id):
current_app.logger.error(str(exception), exc_info=1)
return {"message": str(exception)}, 400

except ArgumentsException as exception:
except WrongParameterException as exception:
current_app.logger.error(str(exception), exc_info=1)
return (
exception.dict
Expand Down
6 changes: 3 additions & 3 deletions zou/app/blueprints/crud/day_off.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from zou.app.services import user_service, time_spents_service

from zou.app.services.exception import ArgumentsException
from zou.app.services.exception import WrongParameterException

from zou.app.utils import permissions

Expand All @@ -21,7 +21,7 @@ def check_creation_integrity(self, data):
if time_spents_service.get_day_offs_between(
data["date"], data["end_date"], data["person_id"]
):
raise ArgumentsException("Day off already exists for this period")
raise WrongParameterException("Day off already exists for this period")
return data

def post_creation(self, instance):
Expand Down Expand Up @@ -67,5 +67,5 @@ def pre_update(self, instance_dict, data):
data.get("person_id", instance_dict["person_id"]),
exclude_id=instance_dict["id"],
):
raise ArgumentsException("Day off already exists for this period")
raise WrongParameterException("Day off already exists for this period")
return data
6 changes: 3 additions & 3 deletions zou/app/blueprints/crud/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
)
from zou.app.utils import date_helpers, events, permissions

from zou.app.services.exception import ArgumentsException
from zou.app.services.exception import WrongParameterException

from werkzeug.exceptions import NotFound

Expand Down Expand Up @@ -88,7 +88,7 @@ def check_creation_integrity(self, data):
if "status" in data:
types = [entity_status for entity_status, _ in ENTITY_STATUSES]
if data["status"] not in types:
raise ArgumentsException("Invalid status")
raise WrongParameterException("Invalid status")
return True

def all_entries(self, query=None, relations=False):
Expand Down Expand Up @@ -255,5 +255,5 @@ def update_data(self, data, instance_id):
if "status" in data:
types = [entity_status for entity_status, _ in ENTITY_STATUSES]
if data["status"] not in types:
raise ArgumentsException("Invalid status")
raise WrongParameterException("Invalid status")
return data
19 changes: 16 additions & 3 deletions zou/app/blueprints/crud/metadata_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,28 @@
)

from zou.app.blueprints.crud.base import BaseModelResource, BaseModelsResource
from zou.app.utils import permissions
from zou.app.models.project import Project

from zou.app.services.exception import (
ArgumentsException,
WrongParameterException,
)


class MetadataDescriptorsResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, MetadataDescriptor)

def check_read_permissions(self):
return not permissions.has_vendor_permissions()

def add_project_permission_filter(self, query):
if not permissions.has_admin_permissions():
query = query.join(Project).filter(
user_service.build_related_projects_filter()
)
return query

def all_entries(self, query=None, relations=True):
if query is None:
query = self.model.query
Expand All @@ -30,11 +42,12 @@ def check_creation_integrity(self, data):
if "data_type" in data:
types = [type_name for type_name, _ in METADATA_DESCRIPTOR_TYPES]
if data["data_type"] not in types:
raise ArgumentsException("Invalid data_type")
raise WrongParameterException("Invalid data_type")
return True


class MetadataDescriptorResource(BaseModelResource):

def __init__(self):
BaseModelResource.__init__(self, MetadataDescriptor)

Expand All @@ -47,5 +60,5 @@ def update_data(self, data, instance_id):
if "data_type" in data:
types = [type_name for type_name, _ in METADATA_DESCRIPTOR_TYPES]
if data["data_type"] not in types:
raise ArgumentsException("Invalid data_type")
raise WrongParameterException("Invalid data_type")
return data
28 changes: 13 additions & 15 deletions zou/app/blueprints/crud/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from zou.app.mixin import ArgsMixin

from zou.app.services.exception import (
ArgumentsException,
WrongParameterException,
PersonInProtectedAccounts,
)

Expand Down Expand Up @@ -61,11 +61,9 @@ def check_create_permissions(self, data):
and data.get("active", True)
and persons_service.is_user_limit_reached()
):
raise ArgumentsException(
raise WrongParameterException(
"User limit reached.",
{
"error": True,
"message": "User limit reached.",
"limit": config.USER_LIMIT,
},
)
Expand All @@ -75,18 +73,18 @@ def check_creation_integrity(self, data):
if "role" in data and data["role"] not in [
role for role, _ in ROLE_TYPES
]:
raise ArgumentsException("Invalid role")
raise WrongParameterException("Invalid role")
if "contract_type" in data and data["contract_type"] not in [
contract_type for contract_type, _ in CONTRACT_TYPES
]:
raise ArgumentsException("Invalid contract_type")
raise WrongParameterException("Invalid contract_type")
if "two_factor_authentication" in data and data[
"two_factor_authentication"
] not in [
two_factor_authentication
for two_factor_authentication, _ in TWO_FACTOR_AUTHENTICATION_TYPES
]:
raise ArgumentsException("Invalid two_factor_authentication")
raise WrongParameterException("Invalid two_factor_authentication")

if "expiration_date" in data and data["expiration_date"] is not None:
try:
Expand All @@ -96,11 +94,11 @@ def check_creation_integrity(self, data):
).date()
< datetime.date.today()
):
raise ArgumentsException(
raise WrongParameterException(
"Expiration date can't be in the past."
)
except:
raise ArgumentsException("Expiration date is not valid.")
raise WrongParameterException("Expiration date is not valid.")
return data

def update_data(self, data):
Expand Down Expand Up @@ -156,18 +154,18 @@ def update_data(self, data, instance_id):
if "role" in data and data["role"] not in [
role for role, _ in ROLE_TYPES
]:
raise ArgumentsException("Invalid role")
raise WrongParameterException("Invalid role")
if "contract_type" in data and data["contract_type"] not in [
contract_type for contract_type, _ in CONTRACT_TYPES
]:
raise ArgumentsException("Invalid contract_type")
raise WrongParameterException("Invalid contract_type")
if "two_factor_authentication" in data and data[
"two_factor_authentication"
] not in [
two_factor_authentication
for two_factor_authentication, _ in TWO_FACTOR_AUTHENTICATION_TYPES
]:
raise ArgumentsException("Invalid two_factor_authentication")
raise WrongParameterException("Invalid two_factor_authentication")

if "expiration_date" in data and data["expiration_date"] is not None:
try:
Expand All @@ -177,11 +175,11 @@ def update_data(self, data, instance_id):
).date()
< datetime.date.today()
):
raise ArgumentsException(
raise WrongParameterException(
"Expiration date can't be in the past."
)
except:
raise ArgumentsException("Expiration date is not valid.")
raise WrongParameterException("Expiration date is not valid.")
return data

def check_delete_permissions(self, instance_dict):
Expand All @@ -204,7 +202,7 @@ def pre_update(self, instance_dict, data):
and not data.get("is_bot", False)
and persons_service.is_user_limit_reached()
):
raise ArgumentsException("User limit reached.")
raise WrongParameterException("User limit reached.")
if instance_dict["email"] in config.PROTECTED_ACCOUNTS:
message = None
if data.get("active") is False:
Expand Down
6 changes: 3 additions & 3 deletions zou/app/blueprints/crud/preview_background_file.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from zou.app.models.preview_background_file import PreviewBackgroundFile
from zou.app.services.exception import ArgumentsException
from zou.app.services.exception import WrongParameterException
from zou.app.services import files_service, deletion_service

from zou.app.blueprints.crud.base import BaseModelResource, BaseModelsResource
Expand All @@ -17,7 +17,7 @@ def update_data(self, data):
name = data.get("name", None)
preview_background_file = PreviewBackgroundFile.get_by(name=name)
if preview_background_file is not None:
raise ArgumentsException(
raise WrongParameterException(
"A preview background file with similar name already exists"
)
return data
Expand All @@ -44,7 +44,7 @@ def update_data(self, data, instance_id):
if preview_background_file is not None and instance_id != str(
preview_background_file.id
):
raise ArgumentsException(
raise WrongParameterException(
"A preview background file with similar name already exists"
)
return data
Expand Down
10 changes: 5 additions & 5 deletions zou/app/blueprints/crud/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from zou.app.blueprints.crud.base import BaseModelResource, BaseModelsResource

from zou.app.services.exception import ArgumentsException
from zou.app.services.exception import WrongParameterException


class ProjectsResource(BaseModelsResource):
Expand All @@ -44,7 +44,7 @@ def check_creation_integrity(self, data):
if data["production_style"] not in [
type_name for type_name, _ in PROJECT_STYLES
]:
raise ArgumentsException("Invalid production_style")
raise WrongParameterException("Invalid production_style")
return True

def update_data(self, data):
Expand All @@ -71,7 +71,7 @@ def update_data(self, data):
or data["preview_background_file_id"]
not in data["preview_background_files_ids"]
):
raise ArgumentsException("Invalid preview_background_file_id")
raise WrongParameterException("Invalid preview_background_file_id")
return data

def post_creation(self, project):
Expand Down Expand Up @@ -131,7 +131,7 @@ def pre_update(self, project_dict, data):
data["preview_background_file_id"]
not in preview_background_files_ids
):
raise ArgumentsException("Invalid preview_background_file_id")
raise WrongParameterException("Invalid preview_background_file_id")

return data

Expand Down Expand Up @@ -167,7 +167,7 @@ def update_data(self, data, instance_id):
if data["production_style"] not in [
type_name for type_name, _ in PROJECT_STYLES
]:
raise ArgumentsException("Invalid production_style")
raise WrongParameterException("Invalid production_style")
return data

@jwt_required()
Expand Down
4 changes: 2 additions & 2 deletions zou/app/blueprints/crud/schedule_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from zou.app.blueprints.crud.base import BaseModelResource, BaseModelsResource

from zou.app.services import user_service
from zou.app.services.exception import ArgumentsException
from zou.app.services.exception import WrongParameterException


class ScheduleItemsResource(BaseModelsResource):
Expand All @@ -17,7 +17,7 @@ def check_creation_integrity(self, data):
object_id=data.get("object_id", None),
)
if schedule_item is not None:
raise ArgumentsException("A similar schedule item already exists")
raise WrongParameterException("A similar schedule item already exists")
return schedule_item


Expand Down
6 changes: 3 additions & 3 deletions zou/app/blueprints/crud/task_type.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from zou.app.models.task_type import TaskType
from zou.app.services.exception import ArgumentsException
from zou.app.services.exception import WrongParameterException
from zou.app.services import tasks_service

from zou.app.blueprints.crud.base import BaseModelResource, BaseModelsResource
Expand All @@ -17,7 +17,7 @@ def update_data(self, data):
name = data.get("name", None)
task_type = TaskType.get_by(name=name)
if task_type is not None:
raise ArgumentsException(
raise WrongParameterException(
"A task type with similar name already exists"
)
return data
Expand All @@ -40,7 +40,7 @@ def update_data(self, data, instance_id):
if name is not None:
task_type = TaskType.get_by(name=name)
if task_type is not None and instance_id != str(task_type.id):
raise ArgumentsException(
raise WrongParameterException(
"A task type with similar name already exists"
)
return data
Expand Down
Loading
Loading