Skip to content

Commit

Permalink
CM-854: allow to fetch grievance config
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan committed Apr 8, 2024
1 parent 07f47af commit d325bcd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
29 changes: 16 additions & 13 deletions grievance_social_protection/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"gql_mutation_delete_categorys_perms": ["123007"],
"tickets_attachments_root_path": None,

"grievance_types": ["Default"],
"grievance_flags": ["Default"],
"grievance_channels": ["Default"],
}


Expand All @@ -29,20 +32,20 @@ class TicketConfig(AppConfig):
gql_mutation_update_categorys_perms = []
gql_mutation_delete_categorys_perms = []
tickets_attachments_root_path = None

def _configure_perms(self, cfg):
TicketConfig.default_validations_disabled = cfg["default_validations_disabled"]
TicketConfig.gql_query_tickets_perms = cfg["gql_query_tickets_perms"]
TicketConfig.gql_mutation_create_tickets_perms = cfg["gql_mutation_create_tickets_perms"]
TicketConfig.gql_mutation_update_tickets_perms = cfg["gql_mutation_update_tickets_perms"]
TicketConfig.gql_mutation_delete_tickets_perms = cfg["gql_mutation_delete_tickets_perms"]
TicketConfig.gql_query_categorys_perms = cfg["gql_query_categorys_perms"]
TicketConfig.gql_mutation_create_categorys_perms = cfg["gql_mutation_create_categorys_perms"]
TicketConfig.gql_mutation_update_categorys_perms = cfg["gql_mutation_update_categorys_perms"]
TicketConfig.gql_mutation_delete_categorys_perms = cfg["gql_mutation_delete_categorys_perms"],
TicketConfig.tickets_attachments_root_path = cfg["tickets_attachments_root_path"]
grievance_types = []
grievance_flags = []
grievance_channels = []

def ready(self):
from core.models import ModuleConfiguration
cfg = ModuleConfiguration.get_or_default(MODULE_NAME, DEFAULT_CFG)
self._configure_perms(cfg)
self.__load_config(cfg)

@classmethod
def __load_config(cls, cfg):
"""
Load all config fields that match current AppConfig class fields, all custom fields have to be loaded separately
"""
for field in cfg:
if hasattr(TicketConfig, field):
setattr(TicketConfig, field, cfg[field])
20 changes: 19 additions & 1 deletion grievance_social_protection/gql_queries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import graphene
from graphene import ObjectType
from graphene_django import DjangoObjectType

from .apps import TicketConfig
from .models import Ticket, Category, TicketAttachment
from insuree.schema import InsureeGQLType
from core import prefix_filterset, ExtendedConnection, filter_validity, ExtendedRelayConnection
Expand All @@ -16,7 +19,6 @@ class Meta:
filter_fields = {
"id": ["exact"],
"uuid": ['exact'],
"uuid": ["exact"],
"category_title": ["exact", "istartswith", "icontains", "iexact"],
"slug": ["exact", "istartswith", "icontains", "iexact"]
}
Expand Down Expand Up @@ -81,3 +83,19 @@ class Meta:
def get_queryset(cls, queryset, info):
queryset = queryset.filter(*filter_validity())
return queryset


class GrievanceTypeConfigurationGQLType(ObjectType):
grievance_types = graphene.List(graphene.String)
grievance_flags = graphene.List(graphene.String)
grievance_channels = graphene.List(graphene.String)


def resolve_grievance_types(self, info):
return TicketConfig.grievance_types

def resolve_grievance_flags(self, info):
return TicketConfig.grievance_flags

def resolve_grievance_channels(self, info):
return TicketConfig.grievance_channels
9 changes: 9 additions & 0 deletions grievance_social_protection/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Query(graphene.ObjectType):
orderBy=graphene.List(of_type=graphene.String),
)

grievance_config = graphene.Field(GrievanceTypeConfigurationGQLType)

def resolve_ticket_details(self, info, **kwargs):
# if not info.context.user.has_perms(ServiceProviderConfig.gql_query_service_provider_perms):
# raise PermissionDenied(_("unauthorized"))
Expand Down Expand Up @@ -99,6 +101,13 @@ def resolve_claim_attachments(self, info, **kwargs):
raise PermissionDenied(_("unauthorized"))


def resolve_grievance_config(self, info, **kwargs):
user = info.context.user
if not user.is_imis_admin:
raise PermissionDenied(_("unauthorized"))
return GrievanceTypeConfigurationGQLType()


class Mutation(graphene.ObjectType):
create_Ticket = CreateTicketMutation.Field()
update_Ticket = UpdateTicketMutation.Field()
Expand Down

0 comments on commit d325bcd

Please sign in to comment.