Skip to content

Commit

Permalink
flak8 formating with black
Browse files Browse the repository at this point in the history
  • Loading branch information
delcroip committed Oct 17, 2024
1 parent 2b52245 commit c162348
Show file tree
Hide file tree
Showing 32 changed files with 1,999 additions and 1,111 deletions.
2 changes: 1 addition & 1 deletion policy/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
default_app_config = 'policy.apps.PolicyConfig'
default_app_config = "policy.apps.PolicyConfig"
22 changes: 12 additions & 10 deletions policy/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
MODULE_NAME = "policy"

DEFAULT_CFG = {
"gql_query_policies_perms": ['101201'],
"gql_query_policies_perms": ["101201"],
"gql_query_policy_officers_perms": [],
"gql_query_policies_by_insuree_perms": ['101201'],
"gql_query_policies_by_family_perms": ['101201'],
"gql_query_eligibilities_perms": ['101201'],
"gql_mutation_create_policies_perms": ['101202'],
"gql_mutation_renew_policies_perms": ['101205'],
"gql_mutation_edit_policies_perms": ['101203'],
"gql_mutation_suspend_policies_perms": ['101203'],
"gql_mutation_delete_policies_perms": ['101204'],
"gql_query_policies_by_insuree_perms": ["101201"],
"gql_query_policies_by_family_perms": ["101201"],
"gql_query_eligibilities_perms": ["101201"],
"gql_mutation_create_policies_perms": ["101202"],
"gql_mutation_renew_policies_perms": ["101205"],
"gql_mutation_edit_policies_perms": ["101203"],
"gql_mutation_suspend_policies_perms": ["101203"],
"gql_mutation_delete_policies_perms": ["101204"],
"policy_renewal_interval": 14, # Notify renewal nb of days before expiry date
"policy_location_via": "family", # ... or product
"default_eligibility_disabled": False,
Expand All @@ -26,6 +26,7 @@
"contribution_receipt_length": 5,
}


class PolicyConfig(AppConfig):
name = MODULE_NAME

Expand Down Expand Up @@ -55,5 +56,6 @@ def __load_config(self, cfg):

def ready(self):
from core.models import ModuleConfiguration

cfg = ModuleConfiguration.get_or_default(MODULE_NAME, DEFAULT_CFG)
self.__load_config(cfg)
self.__load_config(cfg)
114 changes: 71 additions & 43 deletions policy/gql_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,21 @@ class CreateRenewOrUpdatePolicyMutation(OpenIMISMutation):
@classmethod
def do_mutate(cls, perms, user, **data):
if type(user) is AnonymousUser or not user.id:
raise ValidationError(
_("mutation.authentication_required"))
raise ValidationError(_("mutation.authentication_required"))
if not user.has_perms(perms):
raise PermissionDenied(_("unauthorized"))
client_mutation_id = data.get("client_mutation_id")
errors = validate_idle_policy(data)
if len(errors):
return errors
data['audit_user_id'] = user.id_for_audit
data["audit_user_id"] = user.id_for_audit
from core.utils import TimeUtils
data['validity_from'] = TimeUtils.now()

data["validity_from"] = TimeUtils.now()
policy = PolicyService(user).update_or_create(data, user)
PolicyMutation.object_mutated(user, client_mutation_id=client_mutation_id, policy=policy)
PolicyMutation.object_mutated(
user, client_mutation_id=client_mutation_id, policy=policy
)
return None


Expand All @@ -67,12 +69,17 @@ def async_mutate(cls, user, **data):
with transaction.atomic():
data["status"] = Policy.STATUS_IDLE
data["stage"] = Policy.STAGE_NEW
return cls.do_mutate(PolicyConfig.gql_mutation_create_policies_perms, user, **data)
return cls.do_mutate(
PolicyConfig.gql_mutation_create_policies_perms, user, **data
)
except Exception as exc:
return [{
'message': _("policy.mutation.failed_to_create_policy"),
'detail': str(exc),
'exc': exc}]
return [
{
"message": _("policy.mutation.failed_to_create_policy"),
"detail": str(exc),
"exc": exc,
}
]


class UpdatePolicyMutation(CreateRenewOrUpdatePolicyMutation):
Expand All @@ -86,12 +93,17 @@ class Input(PolicyInputType):
def async_mutate(cls, user, **data):
try:
with transaction.atomic():
return cls.do_mutate(PolicyConfig.gql_mutation_edit_policies_perms, user, **data)
return cls.do_mutate(
PolicyConfig.gql_mutation_edit_policies_perms, user, **data
)
except Exception as exc:
return [{
'message': _("policy.mutation.failed_to_update_policy"),
'detail': str(exc),
'exc': exc}]
return [
{
"message": _("policy.mutation.failed_to_update_policy"),
"detail": str(exc),
"exc": exc,
}
]


class RenewPolicyMutation(CreateRenewOrUpdatePolicyMutation):
Expand All @@ -106,16 +118,21 @@ def async_mutate(cls, user, **data):
try:
with transaction.atomic():
# ensure we don't update the existing one, but recreate a new one!
if 'policy_uuid' in data:
data['prev_policy'] = data.pop('policy_uuid')
if "policy_uuid" in data:
data["prev_policy"] = data.pop("policy_uuid")
data["status"] = Policy.STATUS_IDLE
data["stage"] = Policy.STAGE_RENEWED
return cls.do_mutate(PolicyConfig.gql_mutation_renew_policies_perms, user, **data)
return cls.do_mutate(
PolicyConfig.gql_mutation_renew_policies_perms, user, **data
)
except Exception as exc:
return [{
'message': _("policy.mutation.failed_to_renew_policy"),
'detail': str(exc),
'exc': exc}]
return [
{
"message": _("policy.mutation.failed_to_renew_policy"),
"detail": str(exc),
"exc": exc,
}
]


class SuspendPoliciesMutation(OpenIMISMutation):
Expand All @@ -130,29 +147,35 @@ def async_mutate(cls, user, **data):
try:
with transaction.atomic():
if type(user) is AnonymousUser or not user.id:
raise ValidationError(
_("mutation.authentication_required"))
raise ValidationError(_("mutation.authentication_required"))
if not user.has_perms(PolicyConfig.gql_mutation_suspend_policies_perms):
raise PermissionDenied(_("unauthorized"))
errors = []
for policy_uuid in data["uuids"]:
policy = Policy.objects.filter(uuid=policy_uuid).first()
if policy is None:
errors += {
'title': policy_uuid,
'list': [{'message': _(
"policy.mutation.id_does_not_exist") % {'id': policy_uuid}}]
"title": policy_uuid,
"list": [
{
"message": _("policy.mutation.id_does_not_exist")
% {"id": policy_uuid}
}
],
}
continue
errors += PolicyService(user).set_suspended(user, policy)
if len(errors) == 1:
errors = errors[0]['list']
errors = errors[0]["list"]
return errors
except Exception as exc:
return [{
'message': _("policy.mutation.failed_to_suspend_policy"),
'detail': str(exc),
'exc': exc}]
return [
{
"message": _("policy.mutation.failed_to_suspend_policy"),
"detail": str(exc),
"exc": exc,
}
]


class DeletePoliciesMutation(OpenIMISMutation):
Expand All @@ -170,22 +193,27 @@ def async_mutate(cls, user, **data):
raise PermissionDenied(_("unauthorized"))
errors = []
for policy_uuid in data["uuids"]:
policy = Policy.objects \
.filter(uuid=policy_uuid) \
.first()
policy = Policy.objects.filter(uuid=policy_uuid).first()
if policy is None:
errors += {
'title': policy_uuid,
'list': [{'message': _(
"policy.validation.id_does_not_exist") % {'id': policy_uuid}}]
"title": policy_uuid,
"list": [
{
"message": _("policy.validation.id_does_not_exist")
% {"id": policy_uuid}
}
],
}
continue
errors += PolicyService(user).set_deleted(policy)
if len(errors) == 1:
errors = errors[0]['list']
errors = errors[0]["list"]
return errors
except Exception as exc:
return [{
'message': _("policy.mutation.failed_to_delete_policies"),
'detail': str(exc),
'exc': exc}]
return [
{
"message": _("policy.mutation.failed_to_delete_policies"),
"detail": str(exc),
"exc": exc,
}
]
10 changes: 7 additions & 3 deletions policy/gql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
from django.utils.translation import gettext as _
from .apps import PolicyConfig
from .models import Policy
from core import prefix_filterset, filter_validity, ExtendedConnection, ExtendedRelayConnection
from core import (
prefix_filterset,
filter_validity,
ExtendedConnection,
ExtendedRelayConnection,
)
from core.schema import OfficerGQLType
from product.schema import ProductGQLType
from django.core.exceptions import PermissionDenied


class PolicyGQLType(DjangoObjectType):
sum_premiums = graphene.Float(source="sum_premiums")

def resolve_family(self, info):
if not info.context.user.has_perms(PolicyConfig.gql_query_policies_perms):
raise PermissionDenied(_("unauthorized"))
Expand Down Expand Up @@ -104,4 +109,3 @@ class EligibilityGQLType(graphene.ObjectType):
item_left = graphene.Int()
is_item_ok = graphene.Boolean()
is_service_ok = graphene.Boolean()

85 changes: 66 additions & 19 deletions policy/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,78 @@ class Migration(migrations.Migration):

initial = True

dependencies = [
]
dependencies = []

operations = [
migrations.CreateModel(
name='Policy',
name="Policy",
fields=[
('id', models.AutoField(db_column='PolicyID', primary_key=True, serialize=False)),
('legacy_id', models.IntegerField(blank=True, db_column='LegacyID', null=True)),
('stage', models.CharField(blank=True, db_column='PolicyStage', max_length=1, null=True)),
('status', models.SmallIntegerField(blank=True, db_column='PolicyStatus', null=True)),
('value', models.DecimalField(blank=True, db_column='PolicyValue', decimal_places=2, max_digits=18, null=True)),
('enroll_date', core.fields.DateField(db_column='EnrollDate')),
('start_date', core.fields.DateField(db_column='StartDate')),
('effective_date', core.fields.DateField(blank=True, db_column='EffectiveDate', null=True)),
('expiry_date', core.fields.DateField(blank=True, db_column='ExpiryDate', null=True)),
('validity_from', core.fields.DateTimeField(db_column='ValidityFrom')),
('validity_to', core.fields.DateTimeField(blank=True, db_column='ValidityTo', null=True)),
('offline', models.BooleanField(blank=True, db_column='isOffline', null=True)),
('audit_user_id', models.IntegerField(db_column='AuditUserID')),
('row_id', models.BinaryField(blank=True, db_column='RowID', null=True)),
(
"id",
models.AutoField(
db_column="PolicyID", primary_key=True, serialize=False
),
),
(
"legacy_id",
models.IntegerField(blank=True, db_column="LegacyID", null=True),
),
(
"stage",
models.CharField(
blank=True, db_column="PolicyStage", max_length=1, null=True
),
),
(
"status",
models.SmallIntegerField(
blank=True, db_column="PolicyStatus", null=True
),
),
(
"value",
models.DecimalField(
blank=True,
db_column="PolicyValue",
decimal_places=2,
max_digits=18,
null=True,
),
),
("enroll_date", core.fields.DateField(db_column="EnrollDate")),
("start_date", core.fields.DateField(db_column="StartDate")),
(
"effective_date",
core.fields.DateField(
blank=True, db_column="EffectiveDate", null=True
),
),
(
"expiry_date",
core.fields.DateField(
blank=True, db_column="ExpiryDate", null=True
),
),
("validity_from", core.fields.DateTimeField(db_column="ValidityFrom")),
(
"validity_to",
core.fields.DateTimeField(
blank=True, db_column="ValidityTo", null=True
),
),
(
"offline",
models.BooleanField(blank=True, db_column="isOffline", null=True),
),
("audit_user_id", models.IntegerField(db_column="AuditUserID")),
(
"row_id",
models.BinaryField(blank=True, db_column="RowID", null=True),
),
],
options={
'db_table': 'tblPolicy',
'managed': False,
"db_table": "tblPolicy",
"managed": False,
},
),
]
Loading

0 comments on commit c162348

Please sign in to comment.