Skip to content

Commit 85112a9

Browse files
authored
Finish release/v1.3.1
1.3.1
2 parents a7e0c3c + 6e0203a commit 85112a9

15 files changed

+774
-38
lines changed

contribution_plan/apps.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"gql_query_contributionplanbundle_admins_perms": [],
1010
"gql_query_contributionplan_perms": ["151201"],
1111
"gql_query_contributionplan_admins_perms": [],
12+
"gql_query_paymentplan_perms": ["157101"],
13+
"gql_query_paymentplan_admins_perms": [],
1214

1315
"gql_mutation_create_contributionplanbundle_perms": ["151102"],
1416
"gql_mutation_update_contributionplanbundle_perms": ["151103"],
@@ -19,6 +21,11 @@
1921
"gql_mutation_update_contributionplan_perms": ["151203"],
2022
"gql_mutation_delete_contributionplan_perms": ["151204"],
2123
"gql_mutation_replace_contributionplan_perms": ["151206"],
24+
25+
"gql_mutation_create_paymentplan_perms": ["157102"],
26+
"gql_mutation_update_paymentplan_perms": ["157103"],
27+
"gql_mutation_delete_paymentplan_perms": ["157104"],
28+
"gql_mutation_replace_paymentplan_perms": ["157106"],
2229
}
2330

2431

@@ -31,6 +38,9 @@ class ContributionPlanConfig(AppConfig):
3138
gql_query_contributionplan_perms = []
3239
gql_query_contributionplan_admins_perms = []
3340

41+
gql_query_paymentplan_perms = []
42+
gql_query_paymentplan_admins_perms = []
43+
3444
gql_mutation_create_contributionplanbundle_perms = []
3545
gql_mutation_update_contributionplanbundle_perms = []
3646
gql_mutation_delete_contributionplanbundle_perms = []
@@ -41,6 +51,11 @@ class ContributionPlanConfig(AppConfig):
4151
gql_mutation_delete_contributionplan_perms = []
4252
gql_mutation_replace_contributionplan_perms = []
4353

54+
gql_mutation_create_paymentplan_perms = []
55+
gql_mutation_update_paymentplan_perms = []
56+
gql_mutation_delete_paymentplan_perms = []
57+
gql_mutation_replace_paymentplan_perms = []
58+
4459
def _configure_permissions(selfself, cfg):
4560
ContributionPlanConfig.gql_query_contributionplanbundle_perms = cfg[
4661
"gql_query_contributionplanbundle_perms"]
@@ -54,6 +69,12 @@ def _configure_permissions(selfself, cfg):
5469
"gql_query_contributionplan_admins_perms"
5570
]
5671

72+
ContributionPlanConfig.gql_query_paymentplan_perms = cfg[
73+
"gql_query_paymentplan_perms"]
74+
ContributionPlanConfig.gql_query_paymentplan_admins_perms = cfg[
75+
"gql_query_paymentplan_admins_perms"
76+
]
77+
5778
ContributionPlanConfig.gql_mutation_create_contributionplanbundle_perms = cfg[
5879
"gql_mutation_create_contributionplanbundle_perms"
5980
]
@@ -80,7 +101,20 @@ def _configure_permissions(selfself, cfg):
80101
"gql_mutation_replace_contributionplan_perms"
81102
]
82103

104+
ContributionPlanConfig.gql_mutation_create_paymentplan_perms = cfg[
105+
"gql_mutation_create_paymentplan_perms"
106+
]
107+
ContributionPlanConfig.gql_mutation_update_paymentplan_perms = cfg[
108+
"gql_mutation_update_paymentplan_perms"
109+
]
110+
ContributionPlanConfig.gql_mutation_delete_paymentplan_perms = cfg[
111+
"gql_mutation_delete_paymentplan_perms"
112+
]
113+
ContributionPlanConfig.gql_mutation_replace_paymentplan_perms = cfg[
114+
"gql_mutation_replace_paymentplan_perms"
115+
]
116+
83117
def ready(self):
84118
from core.models import ModuleConfiguration
85119
cfg = ModuleConfiguration.get_or_default(MODULE_NAME, DEFAULT_CFG)
86-
self._configure_permissions(cfg)
120+
self._configure_permissions(cfg)

contribution_plan/gql/gql_mutations/contribution_plan_mutations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ class ReplaceContributionPlanMutation(BaseHistoryModelReplaceMutationMixin, Base
4040
_model = ContributionPlan
4141

4242
class Input(ContributionPlanReplaceInputType):
43-
pass
43+
pass

contribution_plan/gql/gql_mutations/input_types.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,16 @@ class ContributionPlanBundleDetailsUpdateInputType(OpenIMISMutation.Input):
8484
class ContributionPlanBundleDetailsReplaceInputType(ReplaceInputType):
8585
contribution_plan_id = graphene.UUID(required=False)
8686
date_valid_from = graphene.Date(required=True)
87-
date_valid_to = graphene.Date(required=False)
87+
date_valid_to = graphene.Date(required=False)
88+
89+
90+
class PaymentPlanInputType(ContributionPlanInputType):
91+
pass
92+
93+
94+
class PaymentPlanUpdateInputType(ContributionPlanUpdateInputType):
95+
pass
96+
97+
98+
class PaymentPlanReplaceInputType(ContributionPlanReplaceInputType):
99+
pass
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from core.gql.gql_mutations import DeleteInputType
2+
from core.gql.gql_mutations.base_mutation import BaseMutation, BaseDeleteMutation, BaseReplaceMutation, \
3+
BaseHistoryModelCreateMutationMixin, BaseHistoryModelUpdateMutationMixin, \
4+
BaseHistoryModelDeleteMutationMixin, BaseHistoryModelReplaceMutationMixin
5+
from contribution_plan.gql.gql_mutations import PaymentPlanInputType, PaymentPlanUpdateInputType, \
6+
PaymentPlanReplaceInputType
7+
from contribution_plan.apps import ContributionPlanConfig
8+
from contribution_plan.models import PaymentPlan
9+
from django.contrib.auth.models import AnonymousUser
10+
from django.core.exceptions import ValidationError
11+
12+
13+
class CreatePaymentPlanMutation(BaseHistoryModelCreateMutationMixin, BaseMutation):
14+
_mutation_class = "PaymentPlanMutation"
15+
_mutation_module = "contribution_plan"
16+
_model = PaymentPlan
17+
18+
@classmethod
19+
def _validate_mutation(cls, user, **data):
20+
if type(user) is AnonymousUser or not user.id or not user.has_perms(
21+
ContributionPlanConfig.gql_mutation_create_paymentplan_perms):
22+
raise ValidationError("mutation.authentication_required")
23+
24+
class Input(PaymentPlanInputType):
25+
pass
26+
27+
28+
class UpdatePaymentPlanMutation(BaseHistoryModelUpdateMutationMixin, BaseMutation):
29+
_mutation_class = "PaymentPlanMutation"
30+
_mutation_module = "contribution_plan"
31+
_model = PaymentPlan
32+
33+
@classmethod
34+
def _validate_mutation(cls, user, **data):
35+
if type(user) is AnonymousUser or not user.id or not user.has_perms(
36+
ContributionPlanConfig.gql_mutation_update_paymentplan_perms):
37+
raise ValidationError("mutation.authentication_required")
38+
39+
class Input(PaymentPlanUpdateInputType):
40+
pass
41+
42+
43+
class DeletePaymentPlanMutation(BaseHistoryModelDeleteMutationMixin, BaseDeleteMutation):
44+
_mutation_class = "PaymentPlanMutation"
45+
_mutation_module = "contribution_plan"
46+
_model = PaymentPlan
47+
48+
@classmethod
49+
def _validate_mutation(cls, user, **data):
50+
if type(user) is AnonymousUser or not user.id or not user.has_perms(
51+
ContributionPlanConfig.gql_mutation_delete_paymentplan_perms):
52+
raise ValidationError("mutation.authentication_required")
53+
54+
class Input(DeleteInputType):
55+
pass
56+
57+
58+
class ReplacePaymentPlanMutation(BaseHistoryModelReplaceMutationMixin, BaseReplaceMutation):
59+
_mutation_class = "PaymentPlanMutation"
60+
_mutation_module = "contribution_plan"
61+
_model = PaymentPlan
62+
63+
@classmethod
64+
def _validate_mutation(cls, user, **data):
65+
if type(user) is AnonymousUser or not user.id or not user.has_perms(
66+
ContributionPlanConfig.gql_mutation_replace_paymentplan_perms):
67+
raise ValidationError("mutation.authentication_required")
68+
69+
class Input(PaymentPlanReplaceInputType):
70+
pass

contribution_plan/gql/gql_types.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import graphene
2-
from contribution_plan.models import ContributionPlanBundle, ContributionPlan, ContributionPlanBundleDetails
2+
from contribution_plan.models import ContributionPlanBundle, ContributionPlan, \
3+
ContributionPlanBundleDetails, PaymentPlan
34
from core import ExtendedConnection, prefix_filterset
45
from graphene_django import DjangoObjectType
56
from product.schema import ProductGQLType
@@ -82,3 +83,29 @@ class Meta:
8283
def get_queryset(cls, queryset, info):
8384
return ContributionPlanBundleDetails.get_queryset(queryset, info)
8485

86+
87+
class PaymentPlanGQLType(DjangoObjectType):
88+
89+
class Meta:
90+
model = PaymentPlan
91+
interfaces = (graphene.relay.Node,)
92+
filter_fields = {
93+
"id": ["exact"],
94+
"version": ["exact"],
95+
"code": ["exact", "istartswith", "icontains", "iexact"],
96+
"name": ["exact", "istartswith", "icontains", "iexact"],
97+
**prefix_filterset("benefit_plan__", ProductGQLType._meta.filter_fields),
98+
"calculation": ["exact"],
99+
"periodicity": ["exact", "lt", "lte", "gt", "gte"],
100+
"date_created": ["exact", "lt", "lte", "gt", "gte"],
101+
"date_updated": ["exact", "lt", "lte", "gt", "gte"],
102+
"user_created": ["exact"],
103+
"user_updated": ["exact"],
104+
"is_deleted": ["exact"]
105+
}
106+
107+
connection_class = ExtendedConnection
108+
109+
@classmethod
110+
def get_queryset(cls, queryset, info):
111+
return PaymentPlan.get_queryset(queryset, info)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Generated by Django 3.0.14 on 2021-11-09 12:54
2+
3+
import contribution_plan.mixins
4+
import core.fields
5+
import datetime
6+
import dirtyfields.dirtyfields
7+
from django.conf import settings
8+
from django.db import migrations, models
9+
import django.db.models.deletion
10+
import jsonfallback.fields
11+
import simple_history.models
12+
13+
14+
class Migration(migrations.Migration):
15+
16+
dependencies = [
17+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
18+
('product', '__first__'),
19+
('contribution_plan', '0007_auto_20210217_1302'),
20+
]
21+
22+
operations = [
23+
migrations.CreateModel(
24+
name='PaymentPlan',
25+
fields=[
26+
('id', models.UUIDField(db_column='UUID', default=None, editable=False, primary_key=True, serialize=False)),
27+
('is_deleted', models.BooleanField(db_column='isDeleted', default=False)),
28+
('json_ext', jsonfallback.fields.FallbackJSONField(blank=True, db_column='Json_ext', null=True)),
29+
('date_created', core.fields.DateTimeField(db_column='DateCreated', null=True)),
30+
('date_updated', core.fields.DateTimeField(db_column='DateUpdated', null=True)),
31+
('version', models.IntegerField(default=1)),
32+
('date_valid_from', core.fields.DateTimeField(db_column='DateValidFrom', default=datetime.datetime.now)),
33+
('date_valid_to', core.fields.DateTimeField(blank=True, db_column='DateValidTo', null=True)),
34+
('replacement_uuid', models.UUIDField(db_column='ReplacementUUID', null=True)),
35+
('code', models.CharField(blank=True, db_column='Code', max_length=255, null=True)),
36+
('name', models.CharField(blank=True, db_column='Name', max_length=255, null=True)),
37+
('calculation', models.UUIDField(db_column='calculationUUID')),
38+
('periodicity', models.IntegerField(db_column='Periodicity')),
39+
('benefit_plan', models.ForeignKey(db_column='BenefitPlanID', on_delete=django.db.models.deletion.DO_NOTHING, to='product.Product')),
40+
('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)),
41+
('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)),
42+
],
43+
options={
44+
'db_table': 'tblPaymentPlan',
45+
},
46+
bases=(contribution_plan.mixins.GenericPlanQuerysetMixin, dirtyfields.dirtyfields.DirtyFieldsMixin, models.Model),
47+
),
48+
migrations.CreateModel(
49+
name='HistoricalPaymentPlan',
50+
fields=[
51+
('id', models.UUIDField(db_column='UUID', db_index=True, default=None, editable=False)),
52+
('is_deleted', models.BooleanField(db_column='isDeleted', default=False)),
53+
('json_ext', jsonfallback.fields.FallbackJSONField(blank=True, db_column='Json_ext', null=True)),
54+
('date_created', core.fields.DateTimeField(db_column='DateCreated', null=True)),
55+
('date_updated', core.fields.DateTimeField(db_column='DateUpdated', null=True)),
56+
('version', models.IntegerField(default=1)),
57+
('date_valid_from', core.fields.DateTimeField(db_column='DateValidFrom', default=datetime.datetime.now)),
58+
('date_valid_to', core.fields.DateTimeField(blank=True, db_column='DateValidTo', null=True)),
59+
('replacement_uuid', models.UUIDField(db_column='ReplacementUUID', null=True)),
60+
('code', models.CharField(blank=True, db_column='Code', max_length=255, null=True)),
61+
('name', models.CharField(blank=True, db_column='Name', max_length=255, null=True)),
62+
('calculation', models.UUIDField(db_column='calculationUUID')),
63+
('periodicity', models.IntegerField(db_column='Periodicity')),
64+
('history_id', models.AutoField(primary_key=True, serialize=False)),
65+
('history_date', models.DateTimeField()),
66+
('history_change_reason', models.CharField(max_length=100, null=True)),
67+
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
68+
('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')),
69+
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
70+
('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)),
71+
('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)),
72+
],
73+
options={
74+
'verbose_name': 'historical payment plan',
75+
'ordering': ('-history_date', '-history_id'),
76+
'get_latest_by': 'history_date',
77+
},
78+
bases=(simple_history.models.HistoricalChanges, models.Model),
79+
),
80+
]
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import logging
2+
3+
from django.db import migrations
4+
5+
logger = logging.getLogger(__name__)
6+
7+
8+
MIGRATION_SQL = """
9+
/* Contribution plan and bundle*/
10+
DECLARE @SystemRole INT
11+
SELECT @SystemRole = role.RoleID from tblRole role where IsSystem=256;
12+
/* Contribution plan bundle*/
13+
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151101)
14+
BEGIN
15+
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
16+
VALUES (@SystemRole, 151101, CURRENT_TIMESTAMP)
17+
END
18+
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151102)
19+
BEGIN
20+
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
21+
VALUES (@SystemRole, 151102, CURRENT_TIMESTAMP)
22+
END
23+
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151103)
24+
BEGIN
25+
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
26+
VALUES (@SystemRole, 151103, CURRENT_TIMESTAMP)
27+
END
28+
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151104)
29+
BEGIN
30+
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
31+
VALUES (@SystemRole, 151104, CURRENT_TIMESTAMP)
32+
END
33+
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151106)
34+
BEGIN
35+
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
36+
VALUES (@SystemRole, 151106, CURRENT_TIMESTAMP)
37+
END
38+
/* Contribution plan */
39+
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151201)
40+
BEGIN
41+
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
42+
VALUES (@SystemRole, 151201, CURRENT_TIMESTAMP)
43+
END
44+
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151202)
45+
BEGIN
46+
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
47+
VALUES (@SystemRole, 151202, CURRENT_TIMESTAMP)
48+
END
49+
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151203)
50+
BEGIN
51+
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
52+
VALUES (@SystemRole, 151203, CURRENT_TIMESTAMP)
53+
END
54+
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151204)
55+
BEGIN
56+
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
57+
VALUES (@SystemRole, 151204, CURRENT_TIMESTAMP)
58+
END
59+
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151206)
60+
BEGIN
61+
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
62+
VALUES (@SystemRole, 151206, CURRENT_TIMESTAMP)
63+
END
64+
"""
65+
66+
67+
class Migration(migrations.Migration):
68+
dependencies = [
69+
('contribution_plan', '0008_historicalpaymentplan_paymentplan')
70+
]
71+
72+
operations = [
73+
migrations.RunSQL(MIGRATION_SQL)
74+
]

contribution_plan/mixins.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from django.conf import settings
2+
from django.db import models
3+
from graphql import ResolveInfo
4+
5+
from core.models import HistoryModelManager
6+
7+
8+
class GenericPlanManager(HistoryModelManager):
9+
def filter(self, *args, **kwargs):
10+
keys = [x for x in kwargs if "itemsvc" in x]
11+
for key in keys:
12+
new_key = key.replace("itemsvc", self.model.model_prefix)
13+
kwargs[new_key] = kwargs.pop(key)
14+
return super(GenericPlanManager, self).filter(*args, **kwargs)
15+
16+
17+
class GenericPlanQuerysetMixin:
18+
19+
@classmethod
20+
def get_queryset(cls, queryset, user):
21+
queryset = cls.filter_queryset(queryset)
22+
if isinstance(user, ResolveInfo):
23+
user = user.context.user
24+
if settings.ROW_SECURITY and user.is_anonymous:
25+
return queryset.filter(id=-1)
26+
if settings.ROW_SECURITY:
27+
pass
28+
return queryset

0 commit comments

Comments
 (0)