Skip to content

Commit

Permalink
Finish release/v1.3.1
Browse files Browse the repository at this point in the history
1.3.1
  • Loading branch information
dragos-dobre authored Dec 15, 2021
2 parents a7e0c3c + 6e0203a commit 85112a9
Show file tree
Hide file tree
Showing 15 changed files with 774 additions and 38 deletions.
36 changes: 35 additions & 1 deletion contribution_plan/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"gql_query_contributionplanbundle_admins_perms": [],
"gql_query_contributionplan_perms": ["151201"],
"gql_query_contributionplan_admins_perms": [],
"gql_query_paymentplan_perms": ["157101"],
"gql_query_paymentplan_admins_perms": [],

"gql_mutation_create_contributionplanbundle_perms": ["151102"],
"gql_mutation_update_contributionplanbundle_perms": ["151103"],
Expand All @@ -19,6 +21,11 @@
"gql_mutation_update_contributionplan_perms": ["151203"],
"gql_mutation_delete_contributionplan_perms": ["151204"],
"gql_mutation_replace_contributionplan_perms": ["151206"],

"gql_mutation_create_paymentplan_perms": ["157102"],
"gql_mutation_update_paymentplan_perms": ["157103"],
"gql_mutation_delete_paymentplan_perms": ["157104"],
"gql_mutation_replace_paymentplan_perms": ["157106"],
}


Expand All @@ -31,6 +38,9 @@ class ContributionPlanConfig(AppConfig):
gql_query_contributionplan_perms = []
gql_query_contributionplan_admins_perms = []

gql_query_paymentplan_perms = []
gql_query_paymentplan_admins_perms = []

gql_mutation_create_contributionplanbundle_perms = []
gql_mutation_update_contributionplanbundle_perms = []
gql_mutation_delete_contributionplanbundle_perms = []
Expand All @@ -41,6 +51,11 @@ class ContributionPlanConfig(AppConfig):
gql_mutation_delete_contributionplan_perms = []
gql_mutation_replace_contributionplan_perms = []

gql_mutation_create_paymentplan_perms = []
gql_mutation_update_paymentplan_perms = []
gql_mutation_delete_paymentplan_perms = []
gql_mutation_replace_paymentplan_perms = []

def _configure_permissions(selfself, cfg):
ContributionPlanConfig.gql_query_contributionplanbundle_perms = cfg[
"gql_query_contributionplanbundle_perms"]
Expand All @@ -54,6 +69,12 @@ def _configure_permissions(selfself, cfg):
"gql_query_contributionplan_admins_perms"
]

ContributionPlanConfig.gql_query_paymentplan_perms = cfg[
"gql_query_paymentplan_perms"]
ContributionPlanConfig.gql_query_paymentplan_admins_perms = cfg[
"gql_query_paymentplan_admins_perms"
]

ContributionPlanConfig.gql_mutation_create_contributionplanbundle_perms = cfg[
"gql_mutation_create_contributionplanbundle_perms"
]
Expand All @@ -80,7 +101,20 @@ def _configure_permissions(selfself, cfg):
"gql_mutation_replace_contributionplan_perms"
]

ContributionPlanConfig.gql_mutation_create_paymentplan_perms = cfg[
"gql_mutation_create_paymentplan_perms"
]
ContributionPlanConfig.gql_mutation_update_paymentplan_perms = cfg[
"gql_mutation_update_paymentplan_perms"
]
ContributionPlanConfig.gql_mutation_delete_paymentplan_perms = cfg[
"gql_mutation_delete_paymentplan_perms"
]
ContributionPlanConfig.gql_mutation_replace_paymentplan_perms = cfg[
"gql_mutation_replace_paymentplan_perms"
]

def ready(self):
from core.models import ModuleConfiguration
cfg = ModuleConfiguration.get_or_default(MODULE_NAME, DEFAULT_CFG)
self._configure_permissions(cfg)
self._configure_permissions(cfg)
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ class ReplaceContributionPlanMutation(BaseHistoryModelReplaceMutationMixin, Base
_model = ContributionPlan

class Input(ContributionPlanReplaceInputType):
pass
pass
14 changes: 13 additions & 1 deletion contribution_plan/gql/gql_mutations/input_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,16 @@ class ContributionPlanBundleDetailsUpdateInputType(OpenIMISMutation.Input):
class ContributionPlanBundleDetailsReplaceInputType(ReplaceInputType):
contribution_plan_id = graphene.UUID(required=False)
date_valid_from = graphene.Date(required=True)
date_valid_to = graphene.Date(required=False)
date_valid_to = graphene.Date(required=False)


class PaymentPlanInputType(ContributionPlanInputType):
pass


class PaymentPlanUpdateInputType(ContributionPlanUpdateInputType):
pass


class PaymentPlanReplaceInputType(ContributionPlanReplaceInputType):
pass
70 changes: 70 additions & 0 deletions contribution_plan/gql/gql_mutations/payment_plan_mutations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from core.gql.gql_mutations import DeleteInputType
from core.gql.gql_mutations.base_mutation import BaseMutation, BaseDeleteMutation, BaseReplaceMutation, \
BaseHistoryModelCreateMutationMixin, BaseHistoryModelUpdateMutationMixin, \
BaseHistoryModelDeleteMutationMixin, BaseHistoryModelReplaceMutationMixin
from contribution_plan.gql.gql_mutations import PaymentPlanInputType, PaymentPlanUpdateInputType, \
PaymentPlanReplaceInputType
from contribution_plan.apps import ContributionPlanConfig
from contribution_plan.models import PaymentPlan
from django.contrib.auth.models import AnonymousUser
from django.core.exceptions import ValidationError


class CreatePaymentPlanMutation(BaseHistoryModelCreateMutationMixin, BaseMutation):
_mutation_class = "PaymentPlanMutation"
_mutation_module = "contribution_plan"
_model = PaymentPlan

@classmethod
def _validate_mutation(cls, user, **data):
if type(user) is AnonymousUser or not user.id or not user.has_perms(
ContributionPlanConfig.gql_mutation_create_paymentplan_perms):
raise ValidationError("mutation.authentication_required")

class Input(PaymentPlanInputType):
pass


class UpdatePaymentPlanMutation(BaseHistoryModelUpdateMutationMixin, BaseMutation):
_mutation_class = "PaymentPlanMutation"
_mutation_module = "contribution_plan"
_model = PaymentPlan

@classmethod
def _validate_mutation(cls, user, **data):
if type(user) is AnonymousUser or not user.id or not user.has_perms(
ContributionPlanConfig.gql_mutation_update_paymentplan_perms):
raise ValidationError("mutation.authentication_required")

class Input(PaymentPlanUpdateInputType):
pass


class DeletePaymentPlanMutation(BaseHistoryModelDeleteMutationMixin, BaseDeleteMutation):
_mutation_class = "PaymentPlanMutation"
_mutation_module = "contribution_plan"
_model = PaymentPlan

@classmethod
def _validate_mutation(cls, user, **data):
if type(user) is AnonymousUser or not user.id or not user.has_perms(
ContributionPlanConfig.gql_mutation_delete_paymentplan_perms):
raise ValidationError("mutation.authentication_required")

class Input(DeleteInputType):
pass


class ReplacePaymentPlanMutation(BaseHistoryModelReplaceMutationMixin, BaseReplaceMutation):
_mutation_class = "PaymentPlanMutation"
_mutation_module = "contribution_plan"
_model = PaymentPlan

@classmethod
def _validate_mutation(cls, user, **data):
if type(user) is AnonymousUser or not user.id or not user.has_perms(
ContributionPlanConfig.gql_mutation_replace_paymentplan_perms):
raise ValidationError("mutation.authentication_required")

class Input(PaymentPlanReplaceInputType):
pass
29 changes: 28 additions & 1 deletion contribution_plan/gql/gql_types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import graphene
from contribution_plan.models import ContributionPlanBundle, ContributionPlan, ContributionPlanBundleDetails
from contribution_plan.models import ContributionPlanBundle, ContributionPlan, \
ContributionPlanBundleDetails, PaymentPlan
from core import ExtendedConnection, prefix_filterset
from graphene_django import DjangoObjectType
from product.schema import ProductGQLType
Expand Down Expand Up @@ -82,3 +83,29 @@ class Meta:
def get_queryset(cls, queryset, info):
return ContributionPlanBundleDetails.get_queryset(queryset, info)


class PaymentPlanGQLType(DjangoObjectType):

class Meta:
model = PaymentPlan
interfaces = (graphene.relay.Node,)
filter_fields = {
"id": ["exact"],
"version": ["exact"],
"code": ["exact", "istartswith", "icontains", "iexact"],
"name": ["exact", "istartswith", "icontains", "iexact"],
**prefix_filterset("benefit_plan__", ProductGQLType._meta.filter_fields),
"calculation": ["exact"],
"periodicity": ["exact", "lt", "lte", "gt", "gte"],
"date_created": ["exact", "lt", "lte", "gt", "gte"],
"date_updated": ["exact", "lt", "lte", "gt", "gte"],
"user_created": ["exact"],
"user_updated": ["exact"],
"is_deleted": ["exact"]
}

connection_class = ExtendedConnection

@classmethod
def get_queryset(cls, queryset, info):
return PaymentPlan.get_queryset(queryset, info)
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Generated by Django 3.0.14 on 2021-11-09 12:54

import contribution_plan.mixins
import core.fields
import datetime
import dirtyfields.dirtyfields
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import jsonfallback.fields
import simple_history.models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('product', '__first__'),
('contribution_plan', '0007_auto_20210217_1302'),
]

operations = [
migrations.CreateModel(
name='PaymentPlan',
fields=[
('id', models.UUIDField(db_column='UUID', default=None, editable=False, primary_key=True, serialize=False)),
('is_deleted', models.BooleanField(db_column='isDeleted', default=False)),
('json_ext', jsonfallback.fields.FallbackJSONField(blank=True, db_column='Json_ext', null=True)),
('date_created', core.fields.DateTimeField(db_column='DateCreated', null=True)),
('date_updated', core.fields.DateTimeField(db_column='DateUpdated', null=True)),
('version', models.IntegerField(default=1)),
('date_valid_from', core.fields.DateTimeField(db_column='DateValidFrom', default=datetime.datetime.now)),
('date_valid_to', core.fields.DateTimeField(blank=True, db_column='DateValidTo', null=True)),
('replacement_uuid', models.UUIDField(db_column='ReplacementUUID', null=True)),
('code', models.CharField(blank=True, db_column='Code', max_length=255, null=True)),
('name', models.CharField(blank=True, db_column='Name', max_length=255, null=True)),
('calculation', models.UUIDField(db_column='calculationUUID')),
('periodicity', models.IntegerField(db_column='Periodicity')),
('benefit_plan', models.ForeignKey(db_column='BenefitPlanID', on_delete=django.db.models.deletion.DO_NOTHING, to='product.Product')),
('user_created', models.ForeignKey(db_column='UserCreatedUUID', on_delete=django.db.models.deletion.DO_NOTHING, related_name='paymentplan_user_created', to=settings.AUTH_USER_MODEL)),
('user_updated', models.ForeignKey(db_column='UserUpdatedUUID', on_delete=django.db.models.deletion.DO_NOTHING, related_name='paymentplan_user_updated', to=settings.AUTH_USER_MODEL)),
],
options={
'db_table': 'tblPaymentPlan',
},
bases=(contribution_plan.mixins.GenericPlanQuerysetMixin, dirtyfields.dirtyfields.DirtyFieldsMixin, models.Model),
),
migrations.CreateModel(
name='HistoricalPaymentPlan',
fields=[
('id', models.UUIDField(db_column='UUID', db_index=True, default=None, editable=False)),
('is_deleted', models.BooleanField(db_column='isDeleted', default=False)),
('json_ext', jsonfallback.fields.FallbackJSONField(blank=True, db_column='Json_ext', null=True)),
('date_created', core.fields.DateTimeField(db_column='DateCreated', null=True)),
('date_updated', core.fields.DateTimeField(db_column='DateUpdated', null=True)),
('version', models.IntegerField(default=1)),
('date_valid_from', core.fields.DateTimeField(db_column='DateValidFrom', default=datetime.datetime.now)),
('date_valid_to', core.fields.DateTimeField(blank=True, db_column='DateValidTo', null=True)),
('replacement_uuid', models.UUIDField(db_column='ReplacementUUID', null=True)),
('code', models.CharField(blank=True, db_column='Code', max_length=255, null=True)),
('name', models.CharField(blank=True, db_column='Name', max_length=255, null=True)),
('calculation', models.UUIDField(db_column='calculationUUID')),
('periodicity', models.IntegerField(db_column='Periodicity')),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField()),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('benefit_plan', models.ForeignKey(blank=True, db_column='BenefitPlanID', db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='product.Product')),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('user_created', models.ForeignKey(blank=True, db_column='UserCreatedUUID', db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
('user_updated', models.ForeignKey(blank=True, db_column='UserUpdatedUUID', db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'historical payment plan',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': 'history_date',
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import logging

from django.db import migrations

logger = logging.getLogger(__name__)


MIGRATION_SQL = """
/* Contribution plan and bundle*/
DECLARE @SystemRole INT
SELECT @SystemRole = role.RoleID from tblRole role where IsSystem=256;
/* Contribution plan bundle*/
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151101)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151101, CURRENT_TIMESTAMP)
END
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151102)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151102, CURRENT_TIMESTAMP)
END
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151103)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151103, CURRENT_TIMESTAMP)
END
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151104)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151104, CURRENT_TIMESTAMP)
END
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151106)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151106, CURRENT_TIMESTAMP)
END
/* Contribution plan */
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151201)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151201, CURRENT_TIMESTAMP)
END
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151202)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151202, CURRENT_TIMESTAMP)
END
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151203)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151203, CURRENT_TIMESTAMP)
END
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151204)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151204, CURRENT_TIMESTAMP)
END
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151206)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151206, CURRENT_TIMESTAMP)
END
"""


class Migration(migrations.Migration):
dependencies = [
('contribution_plan', '0008_historicalpaymentplan_paymentplan')
]

operations = [
migrations.RunSQL(MIGRATION_SQL)
]
28 changes: 28 additions & 0 deletions contribution_plan/mixins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.conf import settings
from django.db import models
from graphql import ResolveInfo

from core.models import HistoryModelManager


class GenericPlanManager(HistoryModelManager):
def filter(self, *args, **kwargs):
keys = [x for x in kwargs if "itemsvc" in x]
for key in keys:
new_key = key.replace("itemsvc", self.model.model_prefix)
kwargs[new_key] = kwargs.pop(key)
return super(GenericPlanManager, self).filter(*args, **kwargs)


class GenericPlanQuerysetMixin:

@classmethod
def get_queryset(cls, queryset, user):
queryset = cls.filter_queryset(queryset)
if isinstance(user, ResolveInfo):
user = user.context.user
if settings.ROW_SECURITY and user.is_anonymous:
return queryset.filter(id=-1)
if settings.ROW_SECURITY:
pass
return queryset
Loading

0 comments on commit 85112a9

Please sign in to comment.