@@ -115,9 +115,7 @@ def get_serializer_class(self):
115115
116116 def patch (self , request , * args , ** kwargs ):
117117 """
118- Updates an edxapp user's attribute and synchronizes with the forum.
119-
120- For users with different signup sources, updates are not allowed.
118+ Allows to safely update an Edxapp user's attribute.
121119 """
122120 query = self .get_user_query (request )
123121 user = get_edxapp_user (** query )
@@ -131,9 +129,6 @@ def patch(self, request, *args, **kwargs):
131129 data = serializer .validated_data
132130 data ["user" ] = user
133131
134- # Update user in cs_comments_service forums
135- replace_username_cs_user (** data )
136-
137132 admin_fields = getattr (settings , "ACCOUNT_VISIBILITY_CONFIGURATION" , {}).get (
138133 "admin_fields" , {}
139134 )
@@ -154,13 +149,13 @@ def get_serializer_class(self):
154149 """
155150 return WrittableEdxappUsernameSerializer
156151
157- @audit_drf_api (action = "Update an Edxapp user's Username." , method_name = ' eox_core_api_method' )
152+ @audit_drf_api (action = "Update an Edxapp user's Username." , method_name = " eox_core_api_method" )
158153 def patch (self , request , * args , ** kwargs ):
159154 """
160155 Allows to safely update an Edxapp user's Username along with the
161156 forum associated User.
162157
163- For now users that have different signup sources cannot be updated .
158+ This method is overridden to include explicit forum synchronization .
164159
165160 For example:
166161
@@ -175,7 +170,28 @@ def patch(self, request, *args, **kwargs):
175170 **Response values**
176171 User serialized.
177172 """
178- return super ().patch (request , * args , ** kwargs )
173+ query = self .get_user_query (request )
174+ user = get_edxapp_user (** query )
175+ data = request .data
176+
177+ with transaction .atomic ():
178+ serializer = self .get_serializer_class ()(user , data = data )
179+ serializer .is_valid (raise_exception = True )
180+ serializer .save ()
181+
182+ data = serializer .validated_data
183+ data ["user" ] = user
184+
185+ # Update user in cs_comments_service forums
186+ replace_username_cs_user (** data )
187+
188+ admin_fields = getattr (settings , "ACCOUNT_VISIBILITY_CONFIGURATION" , {}).get (
189+ "admin_fields" , {}
190+ )
191+ serialized_user = EdxappUserReadOnlySerializer (
192+ user , custom_fields = admin_fields , context = {"request" : request }
193+ )
194+ return Response (serialized_user .data )
179195
180196
181197class EdxappReplaceEmail (EdxappUserUpdateBase ):
@@ -187,18 +203,17 @@ def get_serializer_class(self):
187203 """Returns the serializer class to use."""
188204 return WrittableEdxappEmailSerializer
189205
190- @audit_drf_api (action = "Update an Edxapp user's Email." , method_name = ' eox_core_api_method' )
206+ @audit_drf_api (action = "Update an Edxapp user's Email." , method_name = " eox_core_api_method" )
191207 def patch (self , request , * args , ** kwargs ):
192208 """
193- Allows to safely update an Edxapp user's Email along with the
194- forum associated User.
209+ Allows to safely update an Edxapp user's Email address.
195210
196211 For now users that have different signup sources cannot be updated.
197212
198213 For example:
199214
200215 **Requests**:
201- PATCH <domain>/eox-core/support-api/v1/replace-email/?email=old_email
216+ PATCH <domain>/eox-core/support-api/v1/replace-email/?username=username
202217
203218 **Request body**
204219 {
0 commit comments