Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak committed Sep 17, 2024
1 parent f27bbed commit 44acffa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions care/facility/api/serializers/facility.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class Meta:
"read_cover_image_url",
"patient_count",
"bed_count",
"facility_flags",
]
read_only_fields = ("modified_date", "created_date")

Expand Down
1 change: 1 addition & 0 deletions care/users/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def get_detail_representation(self, obj=None) -> dict:
"doctor_qualification": obj.doctor_qualification,
"weekly_working_hours": obj.weekly_working_hours,
"video_connect_link": obj.video_connect_link,
"user_flags": [],
**self.get_local_body_district_state_representation(obj),
}

Expand Down
18 changes: 11 additions & 7 deletions care/utils/registries/feature_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class FlagNotFoundException(ValidationError):
pass


class InvalidFlagTypeException(ValidationError):
pass


class FlagType(enum.Enum):
USER = "USER"
FACILITY = "FACILITY"
Expand All @@ -27,7 +31,7 @@ class FlagRegistry:
@classmethod
def register(cls, flag_type: FlagType, flag_name: FlagName) -> None:
if flag_type not in FlagType:
return
raise InvalidFlagTypeException("Invalid Flag Type")
if flag_type not in cls._flags:
cls._flags[flag_type] = {}
cls._flags[flag_type][flag_name] = True
Expand All @@ -52,6 +56,12 @@ def validate_flag_type(cls, flag_type: FlagType) -> None:
if flag_type not in FlagType or flag_type not in cls._flags:
raise FlagNotFoundException("Invalid Flag Type")

@classmethod
def validate_flag_name(cls, flag_type: FlagType, flag_name):
cls.validate_flag_type(flag_type)
if flag_name not in cls._flags[flag_type]:
raise FlagNotFoundException("Flag not registered")

@classmethod
def get_all_flags(cls, flag_type: FlagType) -> list[FlagName]:
cls.validate_flag_type(flag_type)
Expand All @@ -63,11 +73,5 @@ def get_all_flags_as_choices(
) -> list[tuple[FlagName, FlagName]]:
return ((x, x) for x in cls._flags.get(flag_type, {}).keys())

@classmethod
def validate_flag_name(cls, flag_type: FlagType, flag_name):
cls.validate_flag_type(flag_type)
if flag_name not in cls._flags[flag_type]:
raise FlagNotFoundException("Flag not registered")


FlagRegistry.register(FlagType.USER, "USER_TEST_FLAG")

0 comments on commit 44acffa

Please sign in to comment.