Skip to content

Commit

Permalink
Made it so that compliance_checks receives a parameter in order to de…
Browse files Browse the repository at this point in the history
…termine whether and Article is being updated. If so, it treats articles published before 2023 normally rather than marking them as compliant.
  • Loading branch information
Lorenzovagliano committed Oct 14, 2024
1 parent 236aa07 commit 3103fe0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
2 changes: 1 addition & 1 deletion scoap3/articles/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def preview_link(self, obj):
def make_compliance_check(self, request, queryset):
ids = []
for obj in queryset:
compliance_checks.delay(obj.id)
compliance_checks.delay(obj.id, True)
ids.append(str(obj.id))
messages.success(
request,
Expand Down
24 changes: 17 additions & 7 deletions scoap3/articles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,20 @@ class Meta:
ordering = ["id"]

@hook(AFTER_UPDATE, on_commit=True)
def on_update(self):
self.on_save(after_update=True)

@hook(AFTER_CREATE, on_commit=True)
def on_save(self):
def on_create(self):
self.on_save(after_update=False)

def on_save(self, after_update):
from scoap3.articles.tasks import compliance_checks

compliance_checks.delay(self.id)
if after_update:
compliance_checks.delay(self.id, True)
else:
compliance_checks.delay(self.id, False)


class ArticleFile(models.Model):
Expand Down Expand Up @@ -125,7 +134,7 @@ class ComplianceReport(models.Model):
def __str__(self):
return f"Compliance Report for {self.article.title} on {self.report_date.strftime('%Y-%m-%d')}"

def is_compliant(self):
def is_compliant(self, after_update):
# If article is part of the following jouranls list, we
# should not take into account the ARXIV category compliance
JOURNALS_SKIP_COMPLIANCE = [
Expand All @@ -141,10 +150,11 @@ def is_compliant(self):
):
_check_arxiv_category = self.check_arxiv_category

if isinstance(
self.article.publication_date, datetime.date
) and self.article.publication_date < date(2023, 1, 1):
return True
if not after_update:
if isinstance(
self.article.publication_date, datetime.date
) and self.article.publication_date < date(2023, 1, 1):
return True

return all(
[
Expand Down
4 changes: 2 additions & 2 deletions scoap3/articles/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def check_contains_funded_by_scoap3(article):


@shared_task(name="compliance_checks", acks_late=True)
def compliance_checks(article_id):
def compliance_checks(article_id, after_update):
try:
article = Article.objects.get(id=article_id)
except Article.DoesNotExist:
Expand Down Expand Up @@ -230,7 +230,7 @@ def compliance_checks(article_id):
check_contains_funded_by_scoap3=check_funded_by_scoap3_compliance,
check_contains_funded_by_scoap3_description=check_funded_by_scoap3_description,
)
report.compliant = report.is_compliant()
report.compliant = report.is_compliant(after_update)
report.save()
logger.info("Compliance checks completed for article %s", article_id)
return f"Compliance checks completed for article {article_id}"
Expand Down
35 changes: 22 additions & 13 deletions scoap3/articles/tests/test_article_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_create_article(self):
)
self.article.related_licenses.add(self.license)
self.article.save()
compliance_checks(self.article.id)
compliance_checks(self.article.id, False)

article = Article.objects.get(id=self.article.id)
report = article.report.first()
Expand All @@ -108,21 +108,21 @@ def test_create_article_with_not_compliant_doi(self):
article_id=self.article_with_not_compliant_doi,
)

compliance_checks(self.article_with_not_compliant_doi.id)
compliance_checks(self.article_with_not_compliant_doi.id, False)
article = Article.objects.get(id=self.article_with_not_compliant_doi.id)
report = article.report.first()

self.assertEqual(report.check_doi_registration_time, False)

def test_create_article_with_missing_compliant_doi(self):
compliance_checks(self.article_with_not_compliant_doi.id)
compliance_checks(self.article_with_not_compliant_doi.id, False)
article = Article.objects.get(id=self.article_with_not_compliant_doi.id)
report = article.report.first()

self.assertEqual(report.check_doi_registration_time, False)

def test_create_article_with_not_compliant_title(self):
compliance_checks(self.article_with_not_compliant_title.id)
compliance_checks(self.article_with_not_compliant_title.id, False)
article = Article.objects.get(id=self.article_with_not_compliant_title.id)
report = article.report.first()

Expand All @@ -136,7 +136,7 @@ def test_create_article_with_not_compliant_file_format_no_publication_info(self)
filetype=file_format,
)

compliance_checks(self.article.id)
compliance_checks(self.article.id, False)
article = Article.objects.get(id=self.article.id)
report = article.report.first()

Expand All @@ -160,7 +160,7 @@ def test_create_article_with_compliant_file_format(self):
filetype=file_format,
)

compliance_checks(self.article.id)
compliance_checks(self.article.id, False)
article = Article.objects.get(id=self.article.id)
report = article.report.first()
self.assertEqual(report.check_required_file_formats, True)
Expand All @@ -183,7 +183,7 @@ def test_create_article_with_not_compliant_file_format(self):
filetype=file_format,
)

compliance_checks(self.article.id)
compliance_checks(self.article.id, False)
article = Article.objects.get(id=self.article.id)
report = article.report.first()
self.assertEqual(report.check_required_file_formats, False)
Expand All @@ -204,7 +204,7 @@ def test_create_article_with_not_compliant_arxiv_category(self):
category="eess-as",
article_id=self.article,
)
compliance_checks(self.article.id)
compliance_checks(self.article.id, False)
article = Article.objects.get(id=self.article.id)
report = article.report.first()
self.assertEqual(report.check_arxiv_category, False)
Expand All @@ -217,7 +217,7 @@ def test_create_author_with_no_affiliation(self):
email="[email protected]",
author_order=100,
)
compliance_checks(self.article.id)
compliance_checks(self.article.id, False)
article = Article.objects.get(id=self.article.id)
report = article.report.first()
self.assertEqual(report.check_authors_affiliation, False)
Expand All @@ -244,7 +244,7 @@ def test_create_author_with_affiliation(self):
)
affiliation.author_id.set(author_id)

compliance_checks(self.article.id)
compliance_checks(self.article.id, False)
article = Article.objects.get(id=self.article.id)
report = article.report.first()
self.assertEqual(report.check_authors_affiliation, True)
Expand All @@ -267,19 +267,28 @@ def test_create_article_with_not_compliant_category_having_not_partial_journal(
category="hep-th",
article_id=self.article,
)
compliance_checks(self.article.id)
compliance_checks(self.article.id, False)
article = Article.objects.get(id=self.article.id)
report = article.report.first()
self.assertEqual(report.check_arxiv_category, False)

def test_create_article_published_before_2023(self):
compliance_checks(self.article_published_before_2023.id)
compliance_checks(self.article_published_before_2023.id, False)
report = self.article_published_before_2023.report.first()

self.assertEqual(report.compliant, True)

def test_update_non_compliant_article_published_before_2023(self):
compliance_checks(self.article_published_before_2023.id, False)
report = self.article_published_before_2023.report.first()
self.assertEqual(report.compliant, True)

compliance_checks(self.article_published_before_2023.id, True)
report = self.article_published_before_2023.report.first()
self.assertEqual(report.compliant, False)

def test_mark_article_with_reports_as_compliant(self):
compliance_checks(self.article.id)
compliance_checks(self.article.id, False)
make_compliant(Article.objects.all())
report = self.article.report.first()

Expand Down

0 comments on commit 3103fe0

Please sign in to comment.