Skip to content

Commit

Permalink
Merge pull request #1378 from glogiotatidis/remote-obsolete-CMR-from-…
Browse files Browse the repository at this point in the history
…targets

Remove obsolete CMR from Target.
  • Loading branch information
glogiotatidis committed May 13, 2020
2 parents 0910a3b + e4261e6 commit e521ea3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 45 deletions.
8 changes: 0 additions & 8 deletions snippets/base/admin/adminmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,9 +934,6 @@ class TargetAdmin(RelatedJobsMixin, admin.ModelAdmin):
'related_total_jobs',
'related_published_jobs',
]
filter_horizontal = [
'client_match_rules',
]
search_fields = [
'name',
]
Expand Down Expand Up @@ -983,11 +980,6 @@ class TargetAdmin(RelatedJobsMixin, admin.ModelAdmin):
'filtr_firefox_service',
),
}),
('Advanced Targeting', {
'fields': (
'client_match_rules',
)
}),
('Jobs', {
'fields': (
'related_published_jobs',
Expand Down
10 changes: 2 additions & 8 deletions snippets/base/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def match_client(self, client):

class JobQuerySet(QuerySet):
def match_client(self, client):
from snippets.base.models import CHANNELS, ClientMatchRule, Target
from snippets.base.models import CHANNELS, Target

# Retrieve the first channel that starts with the client's channel.
# Allows things like "release-cck-mozilla14" to match "release".
Expand All @@ -112,13 +112,7 @@ def match_client(self, client):
Q(snippet__locale__code__contains=full_locale))
jobs = jobs.filter(targets__in=targets)

# Filter based on ClientMatchRules
passed_rules, failed_rules = (ClientMatchRule.objects
.filter(target__jobs__in=jobs)
.distinct()
.evaluate(client))

return jobs.exclude(targets__client_match_rules__in=failed_rules).distinct()
return jobs


class JobManager(Manager):
Expand Down
17 changes: 17 additions & 0 deletions snippets/base/migrations/0035_remove_target_client_match_rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 2.2.10 on 2020-05-11 12:24

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('base', '0034_auto_20200323_1036'),
]

operations = [
migrations.RemoveField(
model_name='target',
name='client_match_rules',
),
]
2 changes: 0 additions & 2 deletions snippets/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,6 @@ class Target(models.Model):
on_startpage_6 = models.BooleanField(default=True, verbose_name='Activity Stream Router',
db_index=True)

client_match_rules = models.ManyToManyField(
ClientMatchRule, blank=True, verbose_name='Client Match Rules')
filtr_is_default_browser = models.CharField(max_length=10, blank=True, default='')
filtr_profile_age_created = models.CharField(max_length=250, blank=True, default='')
filtr_firefox_version = models.CharField(max_length=10, blank=True, default='')
Expand Down
8 changes: 0 additions & 8 deletions snippets/base/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@ class TargetFactory(factory.django.DjangoModelFactory):
class Meta:
model = models.Target

@factory.post_generation
def client_match_rules(self, create, extracted, **kwargs):
if not create:
return

if extracted:
self.client_match_rules.add(*extracted)


class CampaignFactory(factory.django.DjangoModelFactory):
name = factory.Sequence(lambda n: 'Campaign {0}'.format(n))
Expand Down
21 changes: 2 additions & 19 deletions snippets/base/tests/test_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,37 +228,20 @@ def _assert_client_matches_jobs(self, client_attrs, jobs):
self.assertEqual(set(matched_jobs), set(jobs))

def test_match_client_base(self):
client_match_rule_pass_1 = tests.ClientMatchRuleFactory(channel='nightly')
client_match_rule_pass_2 = tests.ClientMatchRuleFactory(channel='/(beta|nightly)/')
client_match_rule_fail = tests.ClientMatchRuleFactory(channel='release')

# Matching snippets.
snippet_1 = tests.JobFactory.create(
targets=[
tests.TargetFactory(on_release=False, on_nightly=True,
client_match_rules=[client_match_rule_pass_1])
tests.TargetFactory(on_release=False, on_nightly=True)
])
snippet_2 = tests.JobFactory.create(
targets=[
tests.TargetFactory(on_release=False, on_beta=True, on_nightly=True,
client_match_rules=[client_match_rule_pass_2])
tests.TargetFactory(on_release=False, on_beta=True, on_nightly=True)
])
snippet_3 = tests.JobFactory.create(
targets=[tests.TargetFactory(on_release=False, on_nightly=True)])

# Not matching snippets.
tests.JobFactory.create(targets=[tests.TargetFactory(on_release=False, on_beta=True)])

tests.JobFactory.create(
targets=[
tests.TargetFactory(on_nightly=True, client_match_rules=[client_match_rule_fail])
])
tests.JobFactory.create(
targets=[
tests.TargetFactory(
on_nightly=True,
client_match_rules=[client_match_rule_fail, client_match_rule_pass_2])
])
client = self._build_client(channel='nightly')

snippets = Job.objects.match_client(client)
Expand Down

0 comments on commit e521ea3

Please sign in to comment.