Dear Alexander,

(project-cdsware-users mailing list added in CC as this topic might be
of interest to others as well :-) ).

Il giorno ven, 14/01/2011 alle 13.26 +0100, Alexander Wagner ha
scritto: 
> I'm trying to find my way through the new embargo functions you
> introduced some time ago. For this I use the current 1.0rc0 on a Debian
> testing VM with the usual test data loaded and try to apply an embargo
> to record 97, just as an example.
> 
>  From the docs I understand that I have to set the firerule for the
> document in question like
> 
>         DENY UNTIL "2011-01-12"
>         ALLOW ALL
> 
> This should block the document till yesterday and open it up for the
> world today. Right?
> 
> As this document is now already in the collection, I try to use
> bibdocfile to apply the rule. From the docs this should be done by
> 
>         $ ./bibdocfile -r 97 --set-restriction='...'
> 
> And concerning the ... I run into an issue. As I understand the
> firerules language I have to put each stanza in a separate row. I tried
> to do this by adding a ^M ctlr-char into the ''. It also seems that I
> get the rule applied, at least the --get-info reads
> 
> [...]
> 97:86:::docname=convert_SCAN-0005061
> 97:86:::doctype=Main
> 97:86:::status=DENY UNTIL "2011-01-12"
> ALLOW ALL
> 97:86:::basedir=/opt/invenio/var/data/files/g0/86
> [...]
> 
> However, if I try to access the document today it is locked. What am I
> doing wrong here?

Great job for using ^M character! The usage is almost correct but for
the missing "firerole:" prefix in front of it. You should in fact
specify the kind of restriction which can be "email:", "group:",
"role:", "firerole:" or "status:". If you don't specify the "firerole:"
prefix, than the "status:" prefix will be used to retain back-ward
compatibility with the past. (where only traditional WebAccess based
authorizations where possible using the 'viewrestrdoc' action with the
'status' parameter).

> And while I am at it: is there a way to apply an embargo from the web
> frontend? The FFT-field is not part of the MARC. The above cli interface
> is fine with me but our collegue who will have to set those embargos on
> a regular basis would feel more comfortable there.
> 
> Thank you in advance for your reply!

Not yet out of the box. What you can do is to create a submission
interface in WebSubmit and plug somewhere an ad-hoc WebSubmit function
that would iterate over all the BibDocFiles attached to a record and set
the restriction to a given rule (that, since it specify a given date,
must be computed on the fly).

I attach an example of such function (note that such function might be
available in the next release candidates, so if you decide to use and
modify it, please give it another name to avoid having your version
being overwritten by a make install).

In order to use it just put it
into /opt/invenio/lib/python/invenio/websubmit_functions

and add it as well through the WebSubmit web interface. It expect two
paramters: "date_file" and "date_format".

Cheers!
Samuele

-- 
Samuele Kaplun
Invenio Developer ** <http://invenio-software.org/>
## This file is part of Invenio.
## Copyright (C) 2011 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

import os
import time

from invenio.bibdocfile import BibRecDocs

def Set_Embargo(parameters, curdir, form):
    """set the embargo on all the documents of a given record.
    @param date_file: the file from which to read the embargo end date.
    @param date_format: the format in which the date in L{date_file} is
        expected to be found. (default C{%Y-%m-%d})
    @note: this function should be used after any file that need to
        be added to a record has been added, that is after any call to
        e.g. L{Move_Files_to_Storage}
    @note: This function expect C{sysno} to exist and be set to the current record.
        (that means it should be called after L{Get_Recid} or L{Create_Recid})
    """
    ## Let's retrieve the date from date_file.
    date_file = parameters['date_file']
    if not date_file:
        return
    date = open(os.path.join(curdir, date_file)).read().strip()
    if not date:
        return

    ## Let's retrieve the expected date format.
    date_format = parameters['date_format'].strip()
    if not date_format:
        date_format = '%Y-%m-%d'

    ## Date normalization.
    date = time.strftime("%Y-%m-%d", time.strptime(date, date_format))

    ## Let's prepare the firerole rule.
    firerole = """\
deny until "%s"
allow all
""" % date

    ## Applying the embargo.
    for bibdoc in BibRecDocs(sysno).list_bibdocs():
        bibdoc.set_status("firerole: %s")

Reply via email to