Commit a69b0793 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Protect harvester (same automate different category).

parent b9a6e127
......@@ -78,6 +78,7 @@
'Binary files': 'fichiers binaires',
'Book': 'Ouvrage',
'book': 'ouvrage',
'but with different category: %s': 'mais avec une catégorie différente : %s',
'cache': 'cache',
'can be applied on any field of the table using the SQL WHERE syntax. Be aware that foreign key are not resolved (see smart_query in the web2py)': 'Peu être appliqué à tous le champs de la table publications en utilisant la syntaxe SQL WHERE. Attention, les clés étrangères ne sont pas résolues (voir le chapitre smart_query dans la documentation web2py)',
"can be applied on any field of the table using the where syntax. don't work with the foreign table (see smart_query in the web2py)": "can be applied on any field of the table using the where syntax. don't work with the foreign table (see smart_query in the web2py)",
......@@ -86,6 +87,7 @@
"Can't delete the undef row.": "Can't delete the undef row.",
"Can't delete this record since several publications refer to it.": 'Impossible de détruire cet enregistrement car des publications lui font référence.',
"Can't insert the article.": 'Impossible de créer cet article.',
"Can't insert the harvester.": "Impossible de créer ce moissonneur.",
"Can't insert the report.": 'Impossible de créer ce rapport.',
"Can't insert the talk/proceeding.": 'Impossible de créer cet acte ou présentation.',
"Can't updated a publication marked OK.": "Impossible d'actualiser une publication marquée OK.",
......@@ -274,6 +276,7 @@
'guides': 'guides',
'Harvest': 'Moissonner',
'Harvester': 'Moissonneur',
'Harvester already exists with the same automaton ': 'Un moissonneur existe déjà avec le même automate ',
'Harvester parameters not defined in the database.': 'Les paramètres du moissoneur ne sont pas définis dans la base de données.',
'Harvester took %s seconds': 'La moisson à durée %s secondes',
'Harvester(s)': 'Moissonneur(s)',
......
......@@ -10,6 +10,7 @@ import plugin_dbui as dbui
from callbacks import (INHIBIT_CASCADE_DELETE,
INHIBIT_DUPLICATE_PUBLICATION,
INHIBIT_HARVESTER_ON_CATEGORY,
INHIBIT_PUBLICATION_DELETE_ON_OK,
INHIBIT_PUBLICATION_UPDATE_ON_OK)
......
......@@ -28,6 +28,8 @@ db.define_table("harvesters",
Field("scan", "boolean", comment=tp_scan, default=False),
migrate="harvesters.table")
db.harvesters._before_insert.append(INHIBIT_HARVESTER_ON_CATEGORY)
db.harvesters.collections.filter_in = dbui.CLEAN_SPACES
db.harvesters.controller.filter_in = dbui.CLEAN_SPACES
db.harvesters.host.filter_in = dbui.CLEAN_SPACES
......
......@@ -8,29 +8,29 @@ from check_tools import (duplicate_article,
duplicate_conference,
duplicate_report)
from gluon import current
from plugin_dbui import (CALLBACK_ERRORS,
get_id,
from plugin_dbui import (CALLBACK_ERRORS,
get_id,
get_where_query)
def INHIBIT_CASCADE_DELETE(set):
"""Inhibit the delete when publications use the reference field.
@type set: gluon.dal.Set
@param set:
@rtype: bool
@return:
"""
db, T = current.globalenv['db'], current.T
field = set.query.first
# protection
# the query of the set should be "table.id == 45"
if field._db._adapter.EQ != set.query.op:
return False
# protection
# check that the table is ones of the publication reference tables
tables = (db.authors_roles,
......@@ -42,14 +42,14 @@ def INHIBIT_CASCADE_DELETE(set):
db.reports,
db.status,
db.teams)
if field._table not in tables:
return False
# inhibit the delete if publications use the reference field
query = get_where_query(db.publications)
query = (query) & (set.query)
if db(query).count():
field._table[CALLBACK_ERRORS] = \
T("Can't delete this record since several publications refer to it.")
......@@ -60,17 +60,17 @@ def INHIBIT_CASCADE_DELETE(set):
def INHIBIT_DUPLICATE_PUBLICATION(publication):
"""Inhibit the insert operation when the publication already exists.
@type publication: dict
@param publication: publications fields passed to insert
@rtype: bool
@return: C{True} when the insert is inhibited
"""
db, T = current.globalenv['db'], current.T
id_category = publication['id_categories']
# articles
id_cats = (get_id(db.categories, code='ACL'),
get_id(db.categories, code='ACLN'))
......@@ -78,7 +78,7 @@ def INHIBIT_DUPLICATE_PUBLICATION(publication):
if id_category in id_cats:
ids = duplicate_article(publication)
if ids:
db.publications[CALLBACK_ERRORS] = [
T("Can't insert the article."),
T("An article already exists with the same:"),
......@@ -86,14 +86,14 @@ def INHIBIT_DUPLICATE_PUBLICATION(publication):
T("• or publisher, volume and pages"),
T("• or publisher and title."),
T("See publication id(s) %s") % ', '.join(ids)]
return True
# talks and proceedings
id_cats = (get_id(db.categories, code='ACTI'),
get_id(db.categories, code='ACTN'),
get_id(db.categories, code='COM'))
if id_category in id_cats:
ids = duplicate_conference(publication)
if ids:
......@@ -105,12 +105,12 @@ def INHIBIT_DUPLICATE_PUBLICATION(publication):
T("• or title, conference date and town"),
T("• or title, conference title and town"),
T("See publication id(s) %s") % ', '.join(ids)]
return True
# reports
id_cats = (get_id(db.categories, code='AP'),)
if id_category in id_cats:
ids = duplicate_report(publication)
if ids:
......@@ -119,21 +119,63 @@ def INHIBIT_DUPLICATE_PUBLICATION(publication):
T("Can't insert the report."),
T("A report already exists with the same title"),
T("See publication id(s) %s") % ', '.join(ids)]
return True
return False
def INHIBIT_HARVESTER_ON_CATEGORY(harvester):
"""Inhibit the insert of similar harvesters.
For a project, one automaton can only proceed publication
of the same code, e.g ACL or ACLN but not both
@type harvester: dict
@param harvester: harvester fields passed to insert
@rtype: bool
@return: C{True} when the insert is inhibited
"""
db, T = current.globalenv['db'], current.T
# a new harvester
id_harvester = get_id(db.harvesters,
controller=harvester['controller'],
host=harvester['host'],
id_projects=harvester['id_projects'],
id_teams=harvester['id_teams'])
if not id_harvester:
return False
# for a project, one automaton can only proceed publication
# of the same code, e.g ACL or ACLN but not both
id_category = db.harvesters[id_harvester].id_categories
if id_category != harvester['id_categories']:
code = db.categories[id_category].code
db.harvesters[CALLBACK_ERRORS] = [
T("Can't insert the harvester."),
T("Harvester already exists with the same automaton "),
T("but with different category: %s") % code]
return True
return False
def INHIBIT_PUBLICATION_DELETE_ON_OK(s):
"""Inhibit the delete operation when the status of the publication is OK.
@type s: gluon.dal.Set
@param s: Set object used for delete.
@rtype: bool
@return: C{True} when the delete is inhibited
"""
db, T = current.globalenv['db'], current.T
id_ok = get_id(db.status, code='OK')
......@@ -143,44 +185,44 @@ def INHIBIT_PUBLICATION_DELETE_ON_OK(s):
# in cascade delete the query is "publications.id_teams IN (21)"
if s.query.first is not db.publications.id:
return False
id = s.query.second
return False
id = s.query.second
if db.publications[id].id_status == id_ok:
db.publications[CALLBACK_ERRORS] = \
T("Can't delete a publication marked OK.")
return True
return False
def INHIBIT_PUBLICATION_UPDATE_ON_OK(s, f):
"""Inhibit the update operation when the status of the publication is OK.
@type s: gluon.dal.Set
@param s: Set object used for update.
@type f: dict
@param f: the dict of publications fields passed to update
@rtype: bool
@return: C{True} when the update is inhibited
"""
db, T = current.globalenv['db'], current.T
id_ok = get_id(db.status, code='OK')
# protection
# the query of the set should be "publications.id == 45"
if s.query.first is not db.publications.id:
if s.query.first is not db.publications.id:
return False
id = s.query.second
if db.publications[id].id_status == id_ok:
db.publications[CALLBACK_ERRORS] = \
T("Can't updated a publication marked OK.")
return True
return False
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment