-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.3.1
- Loading branch information
Showing
15 changed files
with
774 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
contribution_plan/gql/gql_mutations/payment_plan_mutations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
contribution_plan/migrations/0008_historicalpaymentplan_paymentplan.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
] |
74 changes: 74 additions & 0 deletions
74
contribution_plan/migrations/0009_contributionplan_roles_for_admin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.