MCPcopy
hub / github.com/PostHog/posthog / update

Method update

posthog/api/user.py:149–195  ·  view source on GitHub ↗
(self, instance: "User", validated_data: Any)

Source from the content-addressed store, hash-verified

147 return value
148
149 def update(self, instance: "User", validated_data: Any) -> Any:
150
151 # Update current_organization and current_team
152 current_organization = validated_data.pop("set_current_organization", None)
153 current_team = validated_data.pop("set_current_team", None)
154 if current_organization:
155 if current_team and not current_organization.teams.filter(pk=current_team.pk).exists():
156 raise serializers.ValidationError(
157 {"set_current_team": ["Team must belong to the same organization in set_current_organization."]}
158 )
159
160 validated_data["current_organization"] = current_organization
161 validated_data["current_team"] = current_team if current_team else current_organization.teams.first()
162 elif current_team:
163 validated_data["current_team"] = current_team
164 validated_data["current_organization"] = current_team.organization
165
166 if (
167 "email" in validated_data
168 and validated_data["email"].lower() != instance.email.lower()
169 and is_email_available()
170 ):
171 send_email_change_emails.delay(
172 timezone.now().isoformat(), instance.first_name, instance.email, validated_data["email"]
173 )
174
175 # Update password
176 current_password = validated_data.pop("current_password", None)
177 password = self.validate_password_change(
178 cast(User, instance), current_password, validated_data.pop("password", None)
179 )
180
181 if validated_data.get("notification_settings"):
182 validated_data["partial_notification_settings"] = validated_data.pop("notification_settings")
183
184 updated_attrs = list(validated_data.keys())
185 instance = cast(User, super().update(instance, validated_data))
186
187 if password:
188 instance.set_password(password)
189 instance.save()
190 update_session_auth_hash(self.context["request"], instance)
191 updated_attrs.append("password")
192
193 report_user_updated(instance, updated_attrs)
194
195 return instance
196
197 def to_representation(self, instance: Any) -> Any:
198 user_identify.identify_task.delay(user_id=instance.id)

Callers 15

__init__Method · 0.45
report_user_signed_upFunction · 0.45
_get_cohort_filtersMethod · 0.45
_get_limit_offsetMethod · 0.45
_get_search_clauseMethod · 0.45
convert_to_comparisonFunction · 0.45
_format_all_queryFunction · 0.45
get_queryMethod · 0.45
build_conditionsMethod · 0.45
get_queryMethod · 0.45
get_queryMethod · 0.45

Calls 7

is_email_availableFunction · 0.90
report_user_updatedFunction · 0.90
listFunction · 0.85
filterMethod · 0.80
getMethod · 0.65
saveMethod · 0.45

Tested by 8

_create_eventsFunction · 0.36
_single_step_funnelMethod · 0.36
_basic_funnelMethod · 0.36
_create_all_events_rawFunction · 0.36
_test_usage_reportMethod · 0.36
_create_eventFunction · 0.36