Allow district admin to delete users #1738
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Frontend PR: ohcnetwork/care_fe#6781
Proposed Changes
In this commit, a new filter condition has been added specifically for the
DistrictAdmin
user type in the users API viewsets. More specifically, in thedestroy
function. Previously, if a user had a request that passed through this function, it would only check if the user's type is less thanStateAdmin
and hence not a superuser.Now, besides the pre-existing conditions (user type is less than
StateAdmin
and not a superuser), if the user type isDistrictAdmin
, an additional filter is applied. The filter checks if thedistrict
field of the user matches the district of therequest.user
and also verifies if the user type is less thanDistrictAdmin
and not a superuser.Thus, this commit essentially grants a finer degree of control to the District Administrators in managing users under their jurisdiction i.e., the same district. It is important to note that this patch restricts the
DistrictAdmin
from deleting users of the same type or higher and the superusers, thus putting checks on their privileges.Associated Issue
@coronasafe/care-backend-maintainers @coronasafe/care-backend-admins