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

Add compliance flag #183

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions scoap3/articles/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ComplianceReportAdmin(admin.ModelAdmin):
"check_arxiv_category",
"check_article_type",
"check_doi_registration_time",
"check_authors_affiliation",
"get_is_compliant",
"report_date",
]
Expand All @@ -50,6 +51,8 @@ class ComplianceReportAdmin(admin.ModelAdmin):
"check_article_type_description",
"check_doi_registration_time",
"check_doi_registration_time_description",
"check_authors_affiliation",
"check_authors_affiliation_description",
]
readonly_fields = [
"article",
Expand All @@ -65,6 +68,8 @@ class ComplianceReportAdmin(admin.ModelAdmin):
"check_article_type_description",
"check_doi_registration_time",
"check_doi_registration_time_description",
"check_authors_affiliation",
"check_authors_affiliation_description",
]

list_filter = [
Expand All @@ -77,6 +82,7 @@ class ComplianceReportAdmin(admin.ModelAdmin):
"article_id__report__check_arxiv_category",
"article_id__report__check_article_type",
"article_id__report__check_doi_registration_time",
"article_id__report__check_authors_affiliation",
]

actions = ["export_as_csv"]
Expand Down Expand Up @@ -154,6 +160,8 @@ class ArticleComplianceReportInline(admin.StackedInline):
"check_article_type_description",
"check_doi_registration_time",
"check_doi_registration_time_description",
"check_authors_affiliation",
"check_authors_affiliation_description",
]
can_delete = False
can_create = False
Expand All @@ -172,6 +180,10 @@ class ArticleComplianceReportInline(admin.StackedInline):
"check_doi_registration_time",
"check_doi_registration_time_description",
),
(
"check_authors_affiliation",
"check_authors_affiliation_description",
),
]
},
),
Expand Down Expand Up @@ -228,6 +240,7 @@ class ArticleAdmin(admin.ModelAdmin):
"check_arxiv_category",
"check_article_type",
"check_doi_registration_time",
"check_authors_affiliation",
"_updated_at",
"_created_at",
]
Expand All @@ -247,6 +260,7 @@ class ArticleAdmin(admin.ModelAdmin):
"report__check_arxiv_category",
"report__check_article_type",
"report__check_doi_registration_time",
"report__check_authors_affiliation",
]
inlines = [ArticleAuthorsInline, ArticleComplianceReportInline]

Expand Down Expand Up @@ -324,6 +338,13 @@ def check_doi_registration_time(self, obj):
return report.check_doi_registration_time
return False

@admin.display(description="Author affiliations", boolean=True)
def check_authors_affiliation(self, obj):
report = obj.report.first()
if report:
return report.check_authors_affiliation
return False


class ArticleIdentifierAdmin(admin.ModelAdmin):
list_display = ["article_id", "identifier_type", "identifier_value"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.5 on 2024-02-21 14:46

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("articles", "0013_compliancereport_check_article_type_description_and_more"),
]

operations = [
migrations.AddField(
model_name="compliancereport",
name="check_authors_affiliation",
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name="compliancereport",
name="check_authors_affiliation_description",
field=models.TextField(blank=True, default=""),
),
]
3 changes: 3 additions & 0 deletions scoap3/articles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class ComplianceReport(models.Model):
check_article_type_description = models.TextField(blank=True, default="")
check_doi_registration_time = models.BooleanField(default=False)
check_doi_registration_time_description = models.TextField(blank=True, default="")
check_authors_affiliation = models.BooleanField(default=False)
check_authors_affiliation_description = models.TextField(blank=True, default="")

def __str__(self):
return f"Compliance Report for {self.article.title} on {self.report_date.strftime('%Y-%m-%d')}"
Expand All @@ -113,5 +115,6 @@ def is_compliant(self):
self.check_arxiv_category,
self.check_article_type,
self.check_doi_registration_time,
self.check_authors_affiliation,
]
)
16 changes: 16 additions & 0 deletions scoap3/articles/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from django_opensearch_dsl.registries import registry

from scoap3.articles.models import Article, ComplianceReport
from scoap3.authors.models import Author
from scoap3.misc.models import Affiliation
from scoap3.misc.utils import fetch_doi_registration_date

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -122,6 +124,14 @@ def check_doi_registration_time(obj):
return False, "DOI not found in our system."


def check_authors_affiliation(article):
authors = Author.objects.filter(article_id=article)
for author in authors:
affiliations = Affiliation.objects.filter(author_id=author)
if len(affiliations) < 1:
return False, "Author does not have affiliations"
return True, "Authors' affiliations are compliant"

@shared_task(name="compliance_checks", acks_late=True)
def compliance_checks(article_id):
try:
Expand All @@ -145,6 +155,10 @@ def compliance_checks(article_id):
article
)
check_license_compliance, check_license_description = check_license(article)
(
check_affiliations_compliance,
check_affiliations_description,
) = check_authors_affiliation(article)

article.report.all().delete()

Expand All @@ -160,6 +174,8 @@ def compliance_checks(article_id):
check_file_formats_description=check_file_formats_description,
check_license=check_license_compliance,
check_license_description=check_license_description,
check_authors_affiliation=check_affiliations_compliance,
check_authors_affiliation_description=check_affiliations_description,
)
report.save()
logger.info("Compliance checks completed for article %s", article_id)
Expand Down
50 changes: 49 additions & 1 deletion scoap3/articles/tests/test_article_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
ComplianceReport,
)
from scoap3.articles.tasks import compliance_checks
from scoap3.misc.models import ArticleArxivCategory, License, PublicationInfo, Publisher
from scoap3.authors.models import Author
from scoap3.misc.models import (
Affiliation,
ArticleArxivCategory,
Country,
License,
PublicationInfo,
Publisher,
)


@pytest.mark.django_db
Expand Down Expand Up @@ -147,6 +155,46 @@ def test_create_article_with_not_compliant_arxiv_category(self):
report = article.report.first()
self.assertEqual(report.check_arxiv_category, False)

def test_create_author_with_no_affiliation(self):
Author.objects.create(
article_id=self.article,
last_name="ExampleSurname",
first_name="ExampleName",
email="[email protected]",
author_order=100,
)
compliance_checks(self.article.id)
article = Article.objects.get(id=self.article.id)
report = article.report.first()
self.assertEqual(report.check_authors_affiliation, False)

def test_create_author_with_affiliation(self):
Author.objects.create(
article_id=self.article,
last_name="ExampleSurname",
first_name="ExampleName",
email="[email protected]",
author_order=100,
)
Country.objects.create(
code="BE",
name="Belgium",
)
author_id = (
Author.objects.get(last_name="ExampleSurname", first_name="ExampleName"),
)
affiliation = Affiliation.objects.create(
country=Country.objects.get(code="BE", name="Belgium"),
value="Example",
organization="Example Organization",
)
affiliation.author_id.set(author_id)

compliance_checks(self.article.id)
article = Article.objects.get(id=self.article.id)
report = article.report.first()
self.assertEqual(report.check_authors_affiliation, True)

def test_create_article_with_not_compliant_category_having_not_partial_journal(
self,
):
Expand Down
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"dependencies": {
"@ant-design/cssinjs": "^1.17.2",
"antd": "^5.10.1",
"better-react-mathjax": "^2.0.3",
"lodash.isequal": "^4.5.0",
"moment": "^2.29.4",
"next": "13.5.5",
"nextjs-progressbar": "^0.0.16",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-html-parser": "^2.0.2",
"react-mathjax2": "^0.0.2",
"react-vis": "^1.12.1"
},
"devDependencies": {
Expand Down
32 changes: 25 additions & 7 deletions ui/src/components/search/ResultItem.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from "react";
import ReactHtmlParser from "react-html-parser";
import { MathJax } from "better-react-mathjax";
import { Text } from "react-mathjax2";

import { ArticleIdentifier, Result } from "@/types";
import PublicationInfo from "../shared/PublicationInfo";
import Authors from "../shared/Authors";
import { resolveIdentifierLink } from "@/utils/utils";
import {
cleanText,
renderComplexSytnax,
resolveIdentifierLink,
} from "@/utils/utils";
import FulltextFiles from "../shared/FulltextFiles";

interface ResultItemProps {
Expand All @@ -27,7 +30,15 @@ const ResultItem: React.FC<ResultItemProps> = ({ article }) => {
return (
<li className="search-results-record border-0 border-b border-solid border-slate-200 py-6">
<a href={`/records/${article?.id}`} className="mb-2 block text-lg">
<MathJax inline>{ReactHtmlParser(article?.title)}</MathJax>
<Text
text={
<span
dangerouslySetInnerHTML={{
__html: renderComplexSytnax(cleanText(article?.title)),
}}
/>
}
/>
</a>
<div className="mb-2">
<Authors authors={article?.authors} page="search" />
Expand All @@ -36,9 +47,16 @@ const ResultItem: React.FC<ResultItemProps> = ({ article }) => {
- {article?.publication_date}
</small>
</div>
<p className="search-results-record-abstract mb-4">
<MathJax inline>{ReactHtmlParser(article?.abstract)}</MathJax>
</p>
<Text
text={
<p
className="search-results-record-abstract mb-4"
dangerouslySetInnerHTML={{
__html: renderComplexSytnax(cleanText(article?.abstract)),
}}
/>
}
/>
<div className="lg:flex justify-between items-end">
<div>
<span className="text-sm">Published in: </span>
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/search/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ const SearchResults: React.FC<SearchResultsProps> = ({
onChange={sortResults}
defaultValue="_updated_at"
>
<div>
<Select.OptGroup>
<DownOutlined />
</div>
</Select.OptGroup>
</Select>
</div>
)}
Expand Down
9 changes: 2 additions & 7 deletions ui/src/components/search/YearFacet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const YearFacet: React.FC<YearFacetProps> = ({ data, params }) => {
<Card title="Year" className="search-facets-facet mb-5">
<div>
{!isEqual(initialData, filters) && (
<div className="text-right">
<div className="text-right mb-3">
<Button
onClick={resetFilters}
className="ml-1"
Expand All @@ -143,12 +143,6 @@ const YearFacet: React.FC<YearFacetProps> = ({ data, params }) => {
margin={0}
className="year-facet"
>
<VerticalBarSeries
className="skeleton-data"
color="#f5f5f5"
data={initialData}
onValueClick={onBarClick}
/>
{hoveredBar && <Hint value={hoveredBar} />}
<VerticalBarSeries
className="current-data"
Expand All @@ -157,6 +151,7 @@ const YearFacet: React.FC<YearFacetProps> = ({ data, params }) => {
onValueClick={onBarClick}
onValueMouseOver={onBarMouseHover}
onValueMouseOut={onBarMouseOut}
barWidth={0.5}
/>
</XYPlot>
</div>
Expand Down
Loading
Loading