mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	custom fields: Allow list of users in user type of custom fields.
Allow user to add more than one user-value in user type of custom fields. Tweaked by tabbott to improve the models.py code and type annotations.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							b0db90648a
						
					
				
				
					commit
					8909cb1d15
				
			@@ -1,5 +1,5 @@
 | 
			
		||||
 | 
			
		||||
from typing import Union, List, Dict, Optional
 | 
			
		||||
from typing import Union, List, Dict, Optional, cast
 | 
			
		||||
import logging
 | 
			
		||||
import ujson
 | 
			
		||||
 | 
			
		||||
@@ -142,7 +142,7 @@ def remove_user_custom_profile_data(request: HttpRequest, user_profile: UserProf
 | 
			
		||||
def update_user_custom_profile_data(
 | 
			
		||||
        request: HttpRequest,
 | 
			
		||||
        user_profile: UserProfile,
 | 
			
		||||
        data: List[Dict[str, Union[int, str]]]=REQ(validator=check_list(
 | 
			
		||||
        data: List[Dict[str, Union[int, str, List[int]]]]=REQ(validator=check_list(
 | 
			
		||||
            check_dict([('id', check_int)])))) -> HttpResponse:
 | 
			
		||||
    for item in data:
 | 
			
		||||
        field_id = item['id']
 | 
			
		||||
@@ -153,8 +153,8 @@ def update_user_custom_profile_data(
 | 
			
		||||
 | 
			
		||||
        validators = CustomProfileField.FIELD_VALIDATORS
 | 
			
		||||
        field_type = field.field_type
 | 
			
		||||
        value = item['value']
 | 
			
		||||
        var_name = '{}'.format(field.name)
 | 
			
		||||
        value = item['value']
 | 
			
		||||
        if field_type in validators:
 | 
			
		||||
            validator = validators[field_type]
 | 
			
		||||
            result = validator(var_name, value)
 | 
			
		||||
@@ -164,7 +164,8 @@ def update_user_custom_profile_data(
 | 
			
		||||
            result = choice_field_validator(var_name, field_data, value)
 | 
			
		||||
        elif field_type == CustomProfileField.USER:
 | 
			
		||||
            user_field_validator = CustomProfileField.USER_FIELD_VALIDATORS[field_type]
 | 
			
		||||
            result = user_field_validator(user_profile.realm.id, value, False)
 | 
			
		||||
            result = user_field_validator(user_profile.realm.id, cast(List[int], value),
 | 
			
		||||
                                          False)
 | 
			
		||||
        else:
 | 
			
		||||
            raise AssertionError("Invalid field type")
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user