Skip to content

Commit

Permalink
Fir 307 (#52)
Browse files Browse the repository at this point in the history
* Add new FeatureTeam model

FIR-307

* set Admin register for FeatureTeam

FIR-307

* remove qualifier code

* Feature Team as mandatory pick at front end

FIR-307

* add migrations to raid app

FIR-307

---------

Co-authored-by: Roc Itxart <[email protected]>
  • Loading branch information
juanjogarciatorres43 and rocitxart authored May 8, 2024
1 parent 939bc9f commit 4f358db
Show file tree
Hide file tree
Showing 21 changed files with 169 additions and 520 deletions.
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ ENABLE_RAID=False

RAID_DEFAULT_JIRA_QRAFT_USER_ID="XXXXXXXX" #gitleaks:allow
RAID_JIRA_PROJECT_KEY="T2"
RAID_QUALIFIER_URL="https://mycompany.atlassian.local/secure/RapidBoard.jspa?rapidView=12345"


FF_SLACK_SKIP_CHECKS=true
# Disable SSO redirect for local dev by setting to true. When SSO is disabled, go to /admin/ to login
Expand Down
30 changes: 30 additions & 0 deletions src/firefighter/api/migrations/0003_alter_apitokenproxy_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 4.2.11 on 2024-04-30 15:39

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("api", "0002_alter_apitokenproxy_options"),
]

operations = [
migrations.AlterModelOptions(
name="apitokenproxy",
options={
"default_permissions": [],
"permissions": [
("can_edit_any", "Can reassign token to any user"),
("can_add_any", "Can add token to any user"),
("can_view_any", "Can view token of all users"),
("can_delete_any", "Can delete token of any user"),
("can_add_own", "Can add own tokens"),
("can_view_own", "Can view own tokens"),
("can_delete_own", "Can delete own tokens"),
],
"verbose_name": "API Token",
"verbose_name_plural": "API Tokens",
},
),
]
3 changes: 0 additions & 3 deletions src/firefighter/firefighter/settings/components/raid.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,5 @@
RAID_JIRA_PROJECT_KEY: str = config("RAID_JIRA_PROJECT_KEY")
"The Jira project key to use for creating issues, e.g. 'INC'"

RAID_QUALIFIER_URL: str = config("RAID_QUALIFIER_URL")
"Link to the board with issues to qualify"

RAID_JIRA_USER_IDS: dict[str, str] = {}
"Mapping of domain to default Jira user ID"
10 changes: 10 additions & 0 deletions src/firefighter/incidents/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from firefighter.incidents.models.metric_type import IncidentMetric, MetricType
from firefighter.incidents.models.milestone_type import MilestoneType
from firefighter.incidents.models.priority import Priority
from firefighter.raid.models import FeatureTeam

if TYPE_CHECKING:
from collections.abc import MutableSequence
Expand Down Expand Up @@ -174,6 +175,15 @@ def get_readonly_fields(
return self.readonly_fields


@admin.register(FeatureTeam)
class FeatureTeamAdmin(admin.ModelAdmin[FeatureTeam]):
model = FeatureTeam
list_display = [
"name",
"jira_project_key",
]


@admin.register(Severity)
class SeverityAdmin(admin.ModelAdmin[Severity]):
model = Severity
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 4.2.11 on 2024-04-30 15:39

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("incidents", "0001_initial_oss"),
]

operations = [
migrations.AlterField(
model_name="severity",
name="name",
field=models.CharField(max_length=128, unique=True),
),
migrations.AlterField(
model_name="user",
name="password",
field=models.CharField(max_length=128, verbose_name="password"),
),
migrations.CreateModel(
name="FeatureTeam",
fields=[
("id", models.AutoField(primary_key=True, serialize=False)),
("name", models.CharField(max_length=80)),
("jira_project_key", models.CharField(max_length=10, unique=True)),
],
options={
"unique_together": {("name", "jira_project_key")},
"verbose_name": "Feature Team",
"verbose_name_plural": "Feature Teams",
},
),
]
16 changes: 16 additions & 0 deletions src/firefighter/incidents/migrations/0003_delete_featureteam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.11 on 2024-05-03 09:13

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("incidents", "0002_alter_severity_name_alter_user_password_featureteam"),
]

operations = [
migrations.DeleteModel(
name="FeatureTeam",
),
]
5 changes: 0 additions & 5 deletions src/firefighter/incidents/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,3 @@
Args:
incident (Incident): The incident for which to create a conversation.
"""


new_qualifier = django.dispatch.Signal()
"""Signal sent when a new qualifier.
"""
87 changes: 0 additions & 87 deletions src/firefighter/raid/admin.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from django.contrib import admin
from django.utils.translation import gettext_lazy as _

from firefighter.jira_app.admin import JiraIssueAdmin
from firefighter.raid.models import (
JiraTicket,
JiraTicketImpact,
Qualifier,
QualifierRotation,
RaidArea,
)

if TYPE_CHECKING:
from django.db.models.query import QuerySet
from django.forms.models import ModelForm
from django.http import HttpRequest


class JiraTicketImpactInline(admin.TabularInline[JiraTicketImpact, JiraTicket]):
model = JiraTicketImpact
Expand All @@ -38,83 +28,6 @@ class JiraTicketAdmin(JiraIssueAdmin):
inlines = [JiraTicketImpactInline]


@admin.register(QualifierRotation)
class QualifierRotationAdmin(admin.ModelAdmin[QualifierRotation]):
model = QualifierRotation
list_display = ["day", "jira_user", "protected"]
list_select_related = ["jira_user", "jira_user__user"]
list_display_links = ["day"]

ordering = ["-day"]
search_fields = ["day", "jira_user__user__username"]
date_hierarchy = "day"

autocomplete_fields = ["jira_user"]

def has_add_permission(
self, _request: HttpRequest, _obj: QualifierRotation | None = None
) -> bool:
return False

def has_delete_permission(
self, _request: HttpRequest, _obj: QualifierRotation | None = None
) -> bool:
return False

def save_model(
self,
request: HttpRequest,
obj: QualifierRotation,
form: ModelForm[QualifierRotation],
change: bool, # noqa: FBT001
) -> None:
obj.protected = True
super().save_model(request, obj, form, change)

@admin.action(description="Unprotect rotation date", permissions=["change"])
def make_unprotected(
self, _request: HttpRequest, queryset: QuerySet[QualifierRotation]
) -> None:
queryset.update(protected=False)

actions = [make_unprotected]

fieldsets = (
(
_("Rotation"),
{
"fields": (
"day",
"jira_user",
)
},
),
(
_("Protected"),
{
"fields": ("protected",),
},
),
)


@admin.register(Qualifier)
class QualifiersListAdmin(admin.ModelAdmin[Qualifier]):
model = Qualifier
list_display = ["jira_user"]
list_select_related = ["jira_user", "jira_user__user"]

ordering = ["id"]
search_fields = ["jira_user__user__username"]

autocomplete_fields = ["jira_user"]

def has_change_permission(
self, _request: HttpRequest, _obj: Qualifier | None = None
) -> bool:
return False


@admin.register(RaidArea)
class RaidAreaAdmin(admin.ModelAdmin[RaidArea]):
model = RaidArea
Expand Down
1 change: 0 additions & 1 deletion src/firefighter/raid/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def ready(self) -> None:
from firefighter.raid.signals import (
incident_created,
incident_updated,
update_qualifiers_rotation,
)
from firefighter.raid.views.open_normal import (
OpeningRaidCustomerModal,
Expand Down
3 changes: 0 additions & 3 deletions src/firefighter/raid/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,11 @@ def create_issue( # noqa: PLR0912, PLR0913, C901, PLR0917
area: str | None = None,
environments: list[str] | None = None,
project: str | None = None,
qualifier: str | None = None,
) -> JiraObject:
description_addendum: list[str] = []
extra_args: dict[str, Any] = {}
if assignee:
extra_args["assignee"] = {"id": assignee}
if qualifier:
extra_args["customfield_10892"] = {"id": qualifier}
if labels is None:
labels = [""]
if priority is None:
Expand Down
22 changes: 5 additions & 17 deletions src/firefighter/raid/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
SlackMessageRaidCreatedIssue,
SlackMessageRaidModifiedIssue,
)
from firefighter.raid.models import JiraTicket, JiraUser, RaidArea
from firefighter.raid.models import FeatureTeam, JiraTicket, RaidArea
from firefighter.raid.service import (
create_issue_customer,
create_issue_documentation_request,
create_issue_feature_request,
create_issue_internal,
create_issue_seller,
get_current_qualifier,
get_jira_user_from_user,
)
from firefighter.raid.utils import get_domain_from_email
Expand All @@ -39,6 +38,7 @@

from firefighter.incidents.models.impact import ImpactLevel
from firefighter.incidents.models.user import User
from firefighter.jira_app.models import JiraUser
from firefighter.raid.types import JiraObject
from firefighter.slack.messages.base import SlackMessageSurface

Expand Down Expand Up @@ -76,11 +76,9 @@ class CreateNormalIncidentFormBase(CreateIncidentFormBase):
min_length=10,
max_length=1200,
)

suggested_team_routing = forms.CharField(
label="Feature Team or Train to be routed",
max_length=128,
min_length=2,
suggested_team_routing = forms.ModelChoiceField(
queryset=FeatureTeam.objects.only("name"),
label="Feature Team or Train",
required=True,
)
priority = forms.ModelChoiceField(
Expand Down Expand Up @@ -283,7 +281,6 @@ def process_jira_issue(
def set_jira_ticket_watchers_raid(jira_ticket: JiraTicket) -> None:
issue_id = jira_ticket.id
reporter = jira_ticket.reporter.id
qualifier = get_current_qualifier().id

try:
default_jira_user = jira_client.get_jira_user_from_jira_id(
Expand All @@ -299,15 +296,6 @@ def set_jira_ticket_watchers_raid(jira_ticket: JiraTicket) -> None:
logger.exception(
f"Could not add the watcher {jira_ticket.reporter.id} to the ticket {issue_id}"
)

if qualifier != RAID_DEFAULT_JIRA_QRAFT_USER_ID:
try:
jira_client.jira.add_watcher(issue=issue_id, watcher=qualifier)

except JiraAPIError:
logger.exception(
f"Could not add the watcher {jira_ticket.reporter.id} to the ticket {issue_id}"
)
try:
jira_client.jira.remove_watcher(issue=issue_id, watcher=default_jira_user)

Expand Down
Loading

0 comments on commit 4f358db

Please sign in to comment.