|
8 | 8 |
|
9 | 9 | import sentry_sdk
|
10 | 10 | from django.conf import settings
|
| 11 | +from django.db.models import QuerySet |
11 | 12 | from django.urls import reverse
|
12 | 13 | from django.utils.functional import classproperty
|
13 | 14 | from django.utils.translation import gettext as _
|
|
42 | 43 | IntegrationInstallationConfigurationError,
|
43 | 44 | )
|
44 | 45 | from sentry.silo.base import all_silo_function
|
| 46 | +from sentry.users.models.user import User |
45 | 47 | from sentry.users.services.user import RpcUser
|
46 | 48 | from sentry.users.services.user.service import user_service
|
47 | 49 | from sentry.utils.strings import truncatechars
|
@@ -162,6 +164,7 @@ def get_organization_config(self) -> list[dict[str, Any]]:
|
162 | 164 | context = organization_service.get_organization_by_id(
|
163 | 165 | id=self.organization_id, include_projects=False, include_teams=False
|
164 | 166 | )
|
| 167 | + assert context, "organizationcontext must exist to get org" |
165 | 168 | organization = context.organization
|
166 | 169 |
|
167 | 170 | has_issue_sync = features.has("organizations:integrations-issue-sync", organization)
|
@@ -366,7 +369,7 @@ def update_organization_config(self, data):
|
366 | 369 | if org_integration is not None:
|
367 | 370 | self.org_integration = org_integration
|
368 | 371 |
|
369 |
| - def _filter_active_projects(self, project_mappings: Sequence[IntegrationExternalProject]): |
| 372 | + def _filter_active_projects(self, project_mappings: QuerySet[IntegrationExternalProject]): |
370 | 373 | project_ids_set = {p["id"] for p in self.get_client().get_projects_list()}
|
371 | 374 |
|
372 | 375 | return [pm for pm in project_mappings if pm.external_id in project_ids_set]
|
@@ -403,16 +406,19 @@ def sync_metadata(self):
|
403 | 406 | except ApiError as e:
|
404 | 407 | raise IntegrationError(self.message_from_error(e))
|
405 | 408 |
|
406 |
| - self.model.name = server_info["serverTitle"] |
| 409 | + metadata = self.model.metadata.copy() |
| 410 | + name = server_info["serverTitle"] |
407 | 411 |
|
408 | 412 | # There is no Jira instance icon (there is a favicon, but it doesn't seem
|
409 | 413 | # possible to query that with the API). So instead we just use the first
|
410 | 414 | # project Icon.
|
411 | 415 | if len(projects) > 0:
|
412 | 416 | avatar = projects[0]["avatarUrls"]["48x48"]
|
413 |
| - self.model.metadata.update({"icon": avatar}) |
| 417 | + metadata.update({"icon": avatar}) |
414 | 418 |
|
415 |
| - self.model.save() |
| 419 | + integration_service.update_integration( |
| 420 | + integration_id=self.model.id, name=name, metadata=metadata |
| 421 | + ) |
416 | 422 |
|
417 | 423 | def get_link_issue_config(self, group, **kwargs):
|
418 | 424 | fields = super().get_link_issue_config(group, **kwargs)
|
@@ -528,7 +534,9 @@ def create_comment(self, issue_id, user_id, group_note):
|
528 | 534 |
|
529 | 535 | def create_comment_attribution(self, user_id, comment_text):
|
530 | 536 | user = user_service.get_user(user_id=user_id)
|
531 |
| - attribution = f"{user.name} wrote:\n\n" |
| 537 | + username = "Unknown User" if user is None else user.name |
| 538 | + |
| 539 | + attribution = f"{username} wrote:\n\n" |
532 | 540 | return f"{attribution}{{quote}}{comment_text}{{quote}}"
|
533 | 541 |
|
534 | 542 | def update_comment(self, issue_id, user_id, group_note):
|
@@ -639,14 +647,7 @@ def build_dynamic_field(self, field_meta, group=None):
|
639 | 647 | or schema["type"] == "issuelink"
|
640 | 648 | ):
|
641 | 649 | fieldtype = "select"
|
642 |
| - organization = ( |
643 |
| - group.organization |
644 |
| - if group |
645 |
| - else organization_service.get_organization_by_id( |
646 |
| - id=self.organization_id, include_projects=False, include_teams=False |
647 |
| - ).organization |
648 |
| - ) |
649 |
| - fkwargs["url"] = self.search_url(organization.slug) |
| 650 | + fkwargs["url"] = self.search_url(self.organization.slug) |
650 | 651 | fkwargs["choices"] = []
|
651 | 652 | elif schema["type"] in ["timetracking"]:
|
652 | 653 | # TODO: Implement timetracking (currently unsupported altogether)
|
@@ -761,7 +762,7 @@ def fetch_issue_create_meta(self, client, project_id):
|
761 | 762 | return meta
|
762 | 763 |
|
763 | 764 | @all_silo_function
|
764 |
| - def get_create_issue_config(self, group: Group | None, user: RpcUser, **kwargs): |
| 765 | + def get_create_issue_config(self, group: Group | None, user: RpcUser | User, **kwargs): |
765 | 766 | """
|
766 | 767 | We use the `group` to get three things: organization_slug, project
|
767 | 768 | defaults, and default title and description. In the case where we're
|
|
0 commit comments