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

Feature/3573 autocheck article uploaded #2377

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
5 changes: 4 additions & 1 deletion doajtest/fixtures/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ def create_publisher_a():
return publisher


def create_maned_a():
def create_maned_a(save=False):
from portality import models
maned = models.Account(**AccountFixtureFactory.make_managing_editor_source())
maned.set_password("password")
if save:
maned.save(blocking=True)
return maned


Expand Down
2 changes: 1 addition & 1 deletion doajtest/fixtures/v2/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}

SEAL_FORM_EXPANDED = {
"doaj_seal": False,
"doaj_seal": [],
}

JOURNAL_LIKE_BIBJSON = {
Expand Down
4 changes: 2 additions & 2 deletions doajtest/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,9 @@ def assert_expected_dict(test_case: TestCase, target, expected: dict):
test_case.assertDictEqual(actual, expected)


def login(app_client, username, password, follow_redirects=True):
def login(app_client, email, password, follow_redirects=True):
return app_client.post(url_for('account.login'),
data=dict(user=username, password=password),
data=dict(user=email, password=password),
follow_redirects=follow_redirects)


Expand Down
5 changes: 2 additions & 3 deletions doajtest/unit/api_tests/test_api_crud_returnvalues.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from doajtest import helpers
from doajtest.helpers import DoajTestCase, with_es
from portality import models
from doajtest.fixtures import ApplicationFixtureFactory, ArticleFixtureFactory, JournalFixtureFactory
Expand Down Expand Up @@ -205,9 +206,7 @@ def test_04_article_structure_exceptions(self):

@staticmethod
def login(app, username, password):
return app.post('/account/login',
data=dict(username=username, password=password),
follow_redirects=True)
return helpers.login(app, username, password)

@staticmethod
def logout(app):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_04_maned_review_doaj_seal(self):
)

# set the seal to False using the form
fc.form.doaj_seal.data = False
fc.form.doaj_seal.data = []

# run the crosswalk, don't test it at all in this test
fc.form2target()
Expand All @@ -162,7 +162,7 @@ def test_04_maned_review_doaj_seal(self):
fc.source.set_seal(True)
fc.source2form()

assert fc.form.doaj_seal.data is True
assert 'y' in fc.form.doaj_seal.data

def test_05_maned_review_continuations(self):
# construct it from form data (with a known source)
Expand Down
37 changes: 37 additions & 0 deletions doajtest/unit/test_view_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import json

from doajtest import helpers
from doajtest.fixtures import JournalFixtureFactory
from doajtest.fixtures.accounts import create_maned_a
from doajtest.helpers import DoajTestCase
from portality import models
from portality.util import url_for


class TestViewAdmin(DoajTestCase):

def setUp(self):
super().setUp()
self.acc = create_maned_a(save=True)

def test_journal_article_info(self):
journal = models.Journal(
**JournalFixtureFactory.make_journal_source()
)
journal.save(blocking=True)
models.Journal.refresh()

with self.app_test.test_client() as client:
resp = helpers.login(client, self.acc.email, 'password')
assert resp.status_code == 200

resp = client.get(url_for("admin.journal_article_info", journal_id=journal.id))
assert resp.status_code == 200
assert json.loads(resp.data) == {'n_articles': 0}

def test_journal_article_info__not_found(self):
with self.app_test.test_client() as client:
helpers.login(client, self.acc.email, 'password')

resp = client.get(url_for("admin.journal_article_info", journal_id='aksjdlaksjdlkajsdlkajsdlk'))
assert resp.status_code == 404
22 changes: 11 additions & 11 deletions docs/dictionary.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
| Short | Description |
|---------|------------------------------|
| bgjob | background job |
| noti | notification |
| noqa | NO-QA (NO Quality Assurance) |
| inst | instance |
| fmt | format |
| exparam | extra parameter |
| maned | Managing Editor |
| gsheet | Google Sheet |
| svc | service |
| Short | Description |
|----------|------------------------------|
| bgjob | background job |
| noti | notification |
| noqa | NO-QA (NO Quality Assurance) |
| inst | instance |
| fmt | format |
| exparam | extra parameter |
| maned | Managing Editor |
| gsheet | Google Sheet |
| svc,serv | service |
4 changes: 2 additions & 2 deletions portality/crosswalks/journal_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def form2admin(cls, form, obj):
obj.set_editor(editor)

if getattr(form, "doaj_seal", None):
obj.set_seal(form.doaj_seal.data)
obj.set_seal('y' in form.doaj_seal.data)

@classmethod
def bibjson2form(cls, bibjson, forminfo):
Expand Down Expand Up @@ -457,7 +457,7 @@ def admin2form(cls, obj, forminfo):
if obj.editor is not None:
forminfo['editor'] = obj.editor

forminfo['doaj_seal'] = obj.has_seal()
forminfo['doaj_seal'] = ['y'] if obj.has_seal() else []


class JournalFormXWalk(JournalGenericXWalk):
Expand Down
23 changes: 15 additions & 8 deletions portality/forms/application_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1692,8 +1692,13 @@ class FieldDefinitions:
# ~~->$ DOAJSeal:FormField~~
DOAJ_SEAL = {
"name": "doaj_seal",
"label": "The journal may have fulfilled all the criteria for the Seal. Award the Seal?",
"label": "The journal may have fulfilled all the criteria for the Seal.",
"multiple": True,
"input": "checkbox",
"options": [
{"display": "Award the Seal?", "value": 'y'},
],

"validate": [
{
"only_if": {
Expand All @@ -1715,7 +1720,10 @@ class FieldDefinitions:
"the journal must use a persistent identifier"
}
}
]
],
"widgets": [
"article_info",
],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth adding a comment here that the article_info back-end is only accessible to admins. The DOAJ_SEAL also only appears in the admin form context, so that's all good, but I suppose we could change that at some point and not notice.

}

# FIXME: this probably shouldn't be in the admin form fieldsets, rather its own separate form
Expand Down Expand Up @@ -1976,7 +1984,7 @@ class FieldDefinitions:
"entry_template": "application_form/_entry_group.html",
"widgets": [
{"infinite_repeat": {"enable_on_repeat": ["textarea"]}},
"note_modal"
"note_modal",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extraneous comma added

],
"merge_disabled": "merge_disabled_notes",
}
Expand Down Expand Up @@ -3167,7 +3175,8 @@ def wtforms(field, settings):
"trim_whitespace": "formulaic.widgets.newTrimWhitespace", # ~~-> TrimWhitespace:FormWidget~~
"note_modal": "formulaic.widgets.newNoteModal", # ~~-> NoteModal:FormWidget~~,
"autocheck": "formulaic.widgets.newAutocheck", # ~~-> Autocheck:FormWidget~~
"issn_link": "formulaic.widgets.newIssnLink" # ~~-> IssnLink:FormWidget~~,
"issn_link" : "formulaic.widgets.newIssnLink", # ~~-> IssnLink:FormWidget~~,
"article_info": "formulaic.widgets.newArticleInfo", # ~~-> ArticleInfo:FormWidget~~
}


Expand Down Expand Up @@ -3375,10 +3384,8 @@ def wtform(formulaic_context, field, wtfargs):
HiddenFieldBuilder
]

ApplicationFormFactory = Formulaic(APPLICATION_FORMS, WTFORMS_BUILDERS, function_map=PYTHON_FUNCTIONS,
javascript_functions=JAVASCRIPT_FUNCTIONS)
JournalFormFactory = Formulaic(JOURNAL_FORMS, WTFORMS_BUILDERS, function_map=PYTHON_FUNCTIONS,
javascript_functions=JAVASCRIPT_FUNCTIONS)
ApplicationFormFactory = Formulaic(APPLICATION_FORMS, WTFORMS_BUILDERS, function_map=PYTHON_FUNCTIONS, javascript_functions=JAVASCRIPT_FUNCTIONS)
JournalFormFactory = Formulaic(JOURNAL_FORMS, WTFORMS_BUILDERS, function_map=PYTHON_FUNCTIONS, javascript_functions=JAVASCRIPT_FUNCTIONS)

if __name__ == "__main__":
"""
Expand Down
10 changes: 7 additions & 3 deletions portality/models/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def find_by_issns(cls, issns):
return articles

@classmethod
def count_by_issns(cls, issns):
q = ArticleQuery(issns=issns)
def count_by_issns(cls, issns, in_doaj=None):
q = ArticleQuery(issns=issns, in_doaj=in_doaj)
return cls.hit_count(q.query())

@classmethod
Expand Down Expand Up @@ -866,9 +866,10 @@ class ArticleQuery(object):
_issn_terms = { "terms" : {"index.issn.exact" : ["<list of issns here>"]} }
_volume_term = { "term" : {"bibjson.journal.volume.exact" : "<volume here>"} }

def __init__(self, issns=None, volume=None):
def __init__(self, issns=None, volume=None, in_doaj=None):
self.issns = issns
self.volume = volume
self.in_doaj = in_doaj

def query(self):
q = deepcopy(self.base_query)
Expand All @@ -883,6 +884,9 @@ def query(self):
vq["term"]["bibjson.journal.volume.exact"] = self.volume
q["query"]["bool"]["must"].append(vq)

if self.in_doaj is not None:
q["query"]["bool"]["must"].append({"term": {"admin.in_doaj": self.in_doaj}})

return q

class ArticleVolumesQuery(object):
Expand Down
35 changes: 33 additions & 2 deletions portality/static/js/formulaic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1155,14 +1155,14 @@ var formulaic = {

this._renderAutocheck = function(autocheck) {
let frag = "<li>";

if (autocheck.checked_by && doaj.autocheckers &&
doaj.autocheckers.registry.hasOwnProperty(autocheck.checked_by)) {
frag += (new doaj.autocheckers.registry[autocheck.checked_by]()).draw(autocheck)
} else {
frag += this._defaultRender(autocheck);
}

frag += `</li>`;
return frag;
}
Expand Down Expand Up @@ -2252,5 +2252,36 @@ var formulaic = {

this.init();
},

newArticleInfo : (params) => edges.instantiate(formulaic.widgets.ArticleInfo, params),
ArticleInfo: function ({formulaic, fieldDef, args}) {
const $sealEle = $('label[for=doaj_seal-0]');

if (!$sealEle.length) {
console.log('skip ArticleInfo, seal section not found')
return;
}

const idResult = window.location.pathname.match('/journal/([a-f0-9]+)')
if (!idResult) {
console.log('skip ArticleInfo, journal id not found')
return
}
const journalId = idResult[1]
fetch(`/admin/journal/${journalId}/article-info`)
.then(response => response.json())
.then(data => {
let articleText = `(This journal has ${data.n_articles} articles in DOAJ)`
if (data.n_articles > 0) {
const articlesUrl = `/admin/journal/${journalId}/article-info/admin-site-search`
articleText = `<a href="${articlesUrl}" target="_blank">${articleText}</a>`
}
$sealEle.html($sealEle.text() + ` ${articleText}`)
})
},




}
};
4 changes: 2 additions & 2 deletions portality/tasks/journal_bulk_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def run(self):
job.add_audit_message("Setting {f} to {x} for journal {y}".format(f=k, x=v, y=journal_id))
fc.form[k].data = v
else:
if v:
fc.form.doaj_seal.data = v
if v or (isinstance(v, str) and v.lower() == 'y'):
fc.form.doaj_seal.data = ['y']
updated = True

if note:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ <h2 class="form__header">{{ fs.label }}</h2>
{% set fs = formulaic_context.fieldset("seal") %}
{% if fs %}
<h2 class="form__header">{{ fs.label }}</h2>
<p>The journal may have fulfilled all the criteria for the Seal. </p>
{% for f in fs.fields() %}
{% set field_template = f.template %}
{% include field_template %}
Expand Down
33 changes: 29 additions & 4 deletions portality/view/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
from flask_login import current_user, login_required
from werkzeug.datastructures import MultiDict

from portality import dao
import portality.models as models
from portality import constants
from portality import dao
from portality import lock
from portality.background import BackgroundSummary
from portality.bll import DOAJ, exceptions
from portality.bll.exceptions import ArticleMergeConflict, DuplicateArticleException
from portality.bll.services.query import Query
from portality.core import app
from portality.crosswalks.application_form import ApplicationFormXWalk
from portality.decorators import ssl_required, restrict_to_role, write_required
Expand All @@ -28,8 +29,6 @@
from portality.ui.messages import Messages
from portality.util import flash_with_url, jsonp, make_json_resp, get_web_json_payload, validate_json
from portality.view.forms import EditorGroupForm, MakeContinuation

from portality.bll.services.query import Query
from portality.view.view_helper import exparam_editing_user

# ~~Admin:Blueprint~~
Expand Down Expand Up @@ -322,6 +321,31 @@ def journals_bulk_reinstate():
#
#####################################################################

@blueprint.route("/journal/<journal_id>/article-info/", methods=["GET"])
@login_required
def journal_article_info(journal_id):
j = models.Journal.pull(journal_id)
if j is None:
abort(404)

return {'n_articles': models.Article.count_by_issns(j.bibjson().issns(), in_doaj=True)}


@blueprint.route("/journal/<journal_id>/article-info/admin-site-search", methods=["GET"])
@login_required
def journal_article_info_admin_site_search(journal_id):
j = models.Journal.pull(journal_id)
if j is None:
abort(404)

issns = j.bibjson().issns()
if not issns:
abort(404)

target_url = '/admin/admin_site_search?source={"query":{"bool":{"must":[{"term":{"admin.in_doaj":true}},{"term":{"es_type.exact":"article"}},{"query_string":{"query":"%s","default_operator":"AND","default_field":"index.issn.exact"}}]}},"track_total_hits":true}'
return redirect(target_url % issns[0].replace('-', r'\\-'))


@blueprint.route("/journal/<journal_id>/continue", methods=["GET", "POST"])
@login_required
@ssl_required
Expand Down Expand Up @@ -432,7 +456,8 @@ def application(application_id):
flash(str(e))
return redirect(url_for("admin.application", application_id=ap.id, _anchor='cannot_edit'))
else:
return fc.render_template(obj=ap, lock=lockinfo, form_diff=form_diff, current_journal=current_journal, lcc_tree=lcc_jstree, autochecks=autochecks)
return fc.render_template(obj=ap, lock=lockinfo, form_diff=form_diff, current_journal=current_journal,
lcc_tree=lcc_jstree, autochecks=autochecks)


@blueprint.route("/application_quick_reject/<application_id>", methods=["POST"])
Expand Down
Loading