Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"rename" CinderJob.decision_id to decision_cinder_id #22000

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/olympia/abuse/cinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def report_additional_context(self):
if response.status_code != 202:
raise ConnectionError(response.content)

def appeal(self, *, decision_id, appeal_text, appealer):
def appeal(self, *, decision_cinder_id, appeal_text, appealer):
if self.type is None:
# type needs to be defined by subclasses
raise NotImplementedError
Expand All @@ -140,7 +140,7 @@ def appeal(self, *, decision_id, appeal_text, appealer):
'appealer_entity_type': appealer.type,
'appealer_entity': appealer.get_attributes(),
'reasoning': self.get_str(appeal_text),
'decision_to_appeal_id': decision_id,
'decision_to_appeal_id': decision_cinder_id,
}
response = requests.post(url, json=data, headers=self.get_cinder_http_headers())
if response.status_code == 201:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.10 on 2024-03-12 09:55

from django.db import migrations, models


def copy_decision_id_to_decision_cinder_id(apps, schema_editor):
CinderJob = apps.get_model('abuse', 'CinderJob')
CinderJob.objects.update(decision_cinder_id=models.F('decision_id'))


class Migration(migrations.Migration):

dependencies = [
('abuse', '0025_cinderjob_resolvable_in_reviewer_tools_and_more'),
]

operations = [
migrations.AddField(
model_name='cinderjob',
name='decision_cinder_id',
field=models.CharField(default=None, max_length=36, null=True, unique=True),
),
migrations.RunPython(copy_decision_id_to_decision_cinder_id)
]
18 changes: 10 additions & 8 deletions src/olympia/abuse/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ class CinderJob(ModelBase):
decision_action = models.PositiveSmallIntegerField(
default=DECISION_ACTIONS.NO_DECISION, choices=DECISION_ACTIONS.choices
)
decision_id = models.CharField(max_length=36, default=None, null=True, unique=True)
decision_cinder_id = models.CharField(
max_length=36, default=None, null=True, unique=True
)
decision_date = models.DateTimeField(default=None, null=True)
decision_notes = models.TextField(max_length=1000, blank=True)
policies = models.ManyToManyField(to='abuse.CinderPolicy')
Expand Down Expand Up @@ -125,7 +127,7 @@ def can_be_appealed(self, *, is_reporter, abuse_report=None):
"""
now = datetime.now()
base_criteria = (
self.decision_id
self.decision_cinder_id
and self.decision_date
and self.decision_date >= now - timedelta(days=APPEAL_EXPIRATION_DAYS)
# Can never appeal an original decision that has been appealed and
Expand Down Expand Up @@ -167,7 +169,7 @@ def appealed_decision_already_made(self):
"""
Whether or not an appeal was already made for that job with a decision.
"""
return getattr(self.appeal_job, 'decision_id', None)
return getattr(self.appeal_job, 'decision_cinder_id', None)

@classmethod
def get_entity_helper(cls, abuse_report, *, resolved_in_reviewer_tools=False):
Expand Down Expand Up @@ -268,7 +270,7 @@ def report(cls, abuse_report):
def process_decision(
self,
*,
decision_id,
decision_cinder_id,
decision_date,
decision_action,
decision_notes,
Expand All @@ -279,7 +281,7 @@ def process_decision(
See resolve_job for reviewer tools originated decisions."""
existing_decision = (self.appealed_jobs.first() or self).decision_action
self.update(
decision_id=decision_id,
decision_cinder_id=decision_cinder_id,
decision_date=decision_date,
decision_action=decision_action,
decision_notes=decision_notes[
Expand Down Expand Up @@ -343,7 +345,7 @@ def appeal(self, *, abuse_report, appeal_text, user, is_reporter):
resolved_in_reviewer_tools=self.resolvable_in_reviewer_tools,
)
appeal_id = entity_helper.appeal(
decision_id=self.decision_id,
decision_cinder_id=self.decision_cinder_id,
appeal_text=appeal_text,
appealer=appealer_entity,
)
Expand Down Expand Up @@ -376,7 +378,7 @@ def resolve_job(self, *, log_entry):
.filter(reason__cinder_policy__isnull=False)
.values_list('reason__cinder_policy', flat=True)
).without_parents_if_their_children_are_present()
decision_id = entity_helper.create_decision(
decision_cinder_id = entity_helper.create_decision(
reasoning=log_entry.details.get('comments', ''),
policy_uuids=[policy.uuid for policy in policies],
)
Expand All @@ -385,7 +387,7 @@ def resolve_job(self, *, log_entry):
self.update(
decision_action=decision_action,
decision_date=datetime.now(),
decision_id=decision_id,
decision_cinder_id=decision_cinder_id,
)
self.policies.set(policies)
action_helper = self.get_action_helper(existing_decision)
Expand Down
4 changes: 2 additions & 2 deletions src/olympia/abuse/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ def report_to_cinder(abuse_report_id):
@task
@use_primary_db
def appeal_to_cinder(
*, decision_id, abuse_report_id, appeal_text, user_id, is_reporter
*, decision_cinder_id, abuse_report_id, appeal_text, user_id, is_reporter
):
try:
cinder_job = CinderJob.objects.get(decision_id=decision_id)
cinder_job = CinderJob.objects.get(decision_cinder_id=decision_cinder_id)
if abuse_report_id:
abuse_report = AbuseReport.objects.get(id=abuse_report_id)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/olympia/abuse/templates/abuse/appeal.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div role="main" class="generic-content">
<section>
<h2>{{ _('Appeal reviewer decision') }}</h2>
<h3>{{ _('Decision {0}')|format_html(decision_id) }}</h3>
<h3>{{ _('Decision {0}')|format_html(decision_cinder_id) }}</h3>
</section>
<section>
{% if appeal_processed %}
Expand Down
8 changes: 6 additions & 2 deletions src/olympia/abuse/tests/test_cinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def _test_appeal(self, appealer, cinder_instance=None):
)
assert (
cinder_instance.appeal(
decision_id=fake_decision_id, appeal_text='reason', appealer=appealer
decision_cinder_id=fake_decision_id,
appeal_text='reason',
appealer=appealer,
)
== '67890-abc'
)
Expand All @@ -148,7 +150,9 @@ def _test_appeal(self, appealer, cinder_instance=None):
)
with self.assertRaises(ConnectionError):
cinder_instance.appeal(
decision_id=fake_decision_id, appeal_text='reason', appealer=appealer
decision_cinder_id=fake_decision_id,
appeal_text='reason',
appealer=appealer,
)

def test_appeal_anonymous(self):
Expand Down