@@ -137,15 +137,31 @@ def post(self, request):
137137 def patch (self , request , uid ):
138138 data = request .data
139139 user = get_object_or_404 (User , id = uid )
140+
140141 if not request .user .has_perm ("account.change_user" ):
141142 if request .user .id != user .id :
142143 return Response ({
143144 "detail" : "You have no permission to change this user"
144145 }, status = status .HTTP_403_FORBIDDEN )
145-
146- data .pop ("is_active" , None )
147- data .pop ("is_staff" , None )
148- data .pop ("is_superuser" , None )
146+
147+ request_is_active = data .get ("is_active" )
148+ request_is_staff = data .get ("is_staff" )
149+ request_is_superuser = data .get ("is_superuser" )
150+
151+ if request_is_active != None and request_is_active != user .is_active :
152+ return Response ({
153+ "detail" : "You have no permission to change this user"
154+ }, status = status .HTTP_403_FORBIDDEN )
155+
156+ if request_is_staff != None and request_is_staff != user .is_active :
157+ return Response ({
158+ "detail" : "You have no permission to change this user"
159+ }, status = status .HTTP_403_FORBIDDEN )
160+
161+ if request_is_superuser != None and request_is_superuser != user .is_superuser :
162+ return Response ({
163+ "detail" : "You have no permission to change this user"
164+ }, status = status .HTTP_403_FORBIDDEN )
149165
150166 us = AccountSerializer (user , data = data , partial = True )
151167 us .is_valid (raise_exception = True )
0 commit comments