Exemple #1
0
def format_element(bfo, style, html_class='', link_label=None):
    """Print a link to BibEdit, if authorization is granted.

    :param style: the CSS style to be applied to the link.
    :param html_class: the class attribute to be applied to the link.
    :param link_label: Localized link label. Default: "Edit This Record"
                       (or its translated variant).
    """
    _ = gettext_set_language(bfo.lang)

    out = ""

    user_info = bfo.user_info
    if user_can_edit_record_collection(user_info, bfo.recID):
        linkattrd = {}
        if style != '':
            linkattrd['style'] = style
        if html_class != '':
            linkattrd['class'] = html_class
        out += create_html_link(
            CFG_BASE_URL +
            '/%s/edit/?ln=%s#state=edit&recid=%s' % (CFG_SITE_RECORD, bfo.lang,
                                                     str(bfo.recID)),
            {},
            link_label=link_label or _('Edit This Record'),
            linkattrd=linkattrd)

    return out
Exemple #2
0
def api():
    """Handle AJAX requests."""
    from invenio.ext.login import current_user
    from invenio.utils.json import json_unicode_to_utf8
    from invenio.legacy.bibedit.utils import user_can_edit_record_collection
    from invenio.legacy.bibedit.engine import perform_request_ajax

    uid = current_user.get_id()
    json_data = json.loads(request.form['jsondata'].encode("utf-8"))
    json_data = json_unicode_to_utf8(json_data)
    json_response = {'resultCode': 0, 'ID': json_data['ID']}

    recid = None
    if 'recID' in json_data:
        recid = int(json_data['recID'])
        json_response.update({'recID': recid})

    if json_data['requestType'] == "getRecord":
        # Authorize access to record.
        if not user_can_edit_record_collection(request, recid):
            json_response.update({'resultCode': 101})
            return json.dumps(json_response)

    # Handle AJAX request.
    json_response.update(perform_request_ajax(request, recid, uid,
                                              json_data))
    return jsonify(json_response)
Exemple #3
0
def format_element(bfo, style, css_class):
    """
    Prints a link to BibEdit, if authorization is granted

    @param style: the CSS style to be applied to the link.
    @param css_class: the CSS class to be applied to the link.
    """
    _ = gettext_set_language(bfo.lang)

    out = ""

    user_info = bfo.user_info
    if user_can_edit_record_collection(user_info, bfo.recID):
        linkattrd = {}
        if style != '':
            linkattrd['style'] = style
        if css_class != '':
            linkattrd['class'] = css_class
        out += create_html_link(current_app.config['CFG_SITE_URL'] +
               '/%s/edit/?ln=%s#state=edit&recid=%s' % (current_app.config['CFG_SITE_RECORD'], bfo.lang, str(bfo.recID)),
               {},
               link_label="<i class=\"icon-pencil\"></i> %s" % _("Edit"),
               linkattrd=linkattrd)

    return out
Exemple #4
0
def format_element(bfo, style, html_class='', link_label=None):
    """Print a link to BibEdit, if authorization is granted.

    :param style: the CSS style to be applied to the link.
    :param html_class: the class attribute to be applied to the link.
    :param link_label: Localized link label. Default: "Edit This Record"
                       (or its translated variant).
    """
    _ = gettext_set_language(bfo.lang)

    out = ""

    user_info = bfo.user_info
    if user_can_edit_record_collection(user_info, bfo.recID):
        linkattrd = {}
        if style != '':
            linkattrd['style'] = style
        if html_class != '':
            linkattrd['class'] = html_class
        out += create_html_link(
            CFG_BASE_URL + '/%s/edit/?ln=%s#state=edit&recid=%s' %
            (CFG_SITE_RECORD, bfo.lang, str(bfo.recID)), {},
            link_label=link_label or _('Edit This Record'),
            linkattrd=linkattrd)

    return out
Exemple #5
0
def api():
    """Handle AJAX requests."""
    from invenio.ext.login import current_user
    from invenio.utils.json import json_unicode_to_utf8
    from invenio.legacy.bibedit.utils import user_can_edit_record_collection
    from invenio.legacy.bibedit.engine import perform_request_ajax

    uid = current_user.get_id()
    json_data = json.loads(request.form['jsondata'].encode("utf-8"))
    json_data = json_unicode_to_utf8(json_data)
    json_response = {'resultCode': 0, 'ID': json_data['ID']}

    recid = None
    if 'recID' in json_data:
        recid = int(json_data['recID'])
        json_response.update({'recID': recid})

    if json_data['requestType'] == "getRecord":
        # Authorize access to record.
        if not user_can_edit_record_collection(request, recid):
            json_response.update({'resultCode': 101})
            return json.dumps(json_response)

    # Handle AJAX request.
    json_response.update(perform_request_ajax(request, recid, uid, json_data))
    return jsonify(json_response)
Exemple #6
0
def format_element(bfo, style, css_class):
    """
    Prints a link to BibEdit, if authorization is granted

    @param style: the CSS style to be applied to the link.
    @param css_class: the CSS class to be applied to the link.
    """
    _ = gettext_set_language(bfo.lang)

    out = ""

    user_info = bfo.user_info
    if user_can_edit_record_collection(user_info, bfo.recID):
        linkattrd = {}
        if style != '':
            linkattrd['style'] = style
        if css_class != '':
            linkattrd['class'] = css_class
        out += create_html_link(current_app.config['CFG_SITE_SECURE_URL'] +
               '/%s/edit/?ln=%s#state=edit&recid=%s' % (current_app.config['CFG_SITE_RECORD'], bfo.lang, str(bfo.recID)),
               {},
               link_label="<i class=\"icon-pencil\"></i> %s" % _("Edit"),
               linkattrd=linkattrd)

    return out
Exemple #7
0
def format_element(bfo, style):
    """Print a link to BibEdit, if authorization is granted.

    :param style: the CSS style to be applied to the link.
    """
    _ = gettext_set_language(bfo.lang)

    out = ""

    user_info = bfo.user_info
    if user_can_edit_record_collection(user_info, bfo.recID):
        linkattrd = {}
        if style != '':
            linkattrd['style'] = style
        out += create_html_link(
            CFG_BASE_URL + '/%s/edit/?ln=%s#state=edit&recid=%s' %
            (CFG_SITE_RECORD, bfo.lang, str(bfo.recID)), {},
            link_label=_("Edit This Record"),
            linkattrd=linkattrd)

    return out
Exemple #8
0
def format_element(bfo, style):
    """
    Prints a link to BibEdit, if authorization is granted

    @param style: the CSS style to be applied to the link.
    """
    _ = gettext_set_language(bfo.lang)

    out = ""

    user_info = bfo.user_info
    if user_can_edit_record_collection(user_info, bfo.recID):
        linkattrd = {}
        if style != '':
            linkattrd['style'] = style
        out += create_html_link(CFG_SITE_URL +
               '/%s/edit/?ln=%s#state=edit&recid=%s' % (CFG_SITE_RECORD, bfo.lang, str(bfo.recID)),
               {},
               link_label=_("Edit This Record"),
               linkattrd=linkattrd)

    return out
Exemple #9
0
    def index(self, req, form):
        """Handle all BibEdit requests.
        The responsibilities of this functions is:
        * JSON decoding and encoding.
        * Redirection, if necessary.
        * Authorization.
        * Calling the appropriate function from the engine.

        """
        uid = current_user.get_id()
        argd = wash_urlargd(form, {'ln': (str, CFG_SITE_LANG)})
        # Abort if the simplejson module isn't available
        if not CFG_JSON_AVAILABLE:
            title = 'Record Editor'
            body = '''Sorry, the record editor cannot operate when the
                `simplejson' module is not installed.  Please see the INSTALL
                file.'''
            return page(title       = title,
                        body        = body,
                        errors      = [],
                        warnings    = [],
                        uid         = uid,
                        language    = argd['ln'],
                        navtrail    = navtrail,
                        lastupdated = __lastupdated__,
                        req         = req,
                        body_css_classes = ['bibedit'])

        # If it is an Ajax request, extract any JSON data.
        ajax_request, recid = False, None
        if 'jsondata' in form:
            json_data = json.loads(str(form['jsondata']))
            # Deunicode all strings (Invenio doesn't have unicode
            # support).
            json_data = json_unicode_to_utf8(json_data)
            ajax_request = True
            if 'recID' in json_data:
                recid = json_data['recID']
            json_response = {'resultCode': 0, 'ID': json_data['ID']}

        # Authorization.
        if current_user.is_guest:
            # User is not logged in.
            if not ajax_request:
                # Do not display the introductory recID selection box to guest
                # users (as it used to be with v0.99.0):
                dummy_auth_code, auth_message = acc_authorize_action(req,
                                                                     'runbibedit')
                referer = '/edit/'
                if self.recid:
                    referer = '/%s/%s/edit/' % (CFG_SITE_RECORD, self.recid)
                return page_not_authorized(req=req, referer=referer,
                                           text=auth_message, navtrail=navtrail)
            else:
                # Session has most likely timed out.
                json_response.update({'resultCode': 100})
                return json.dumps(json_response)

        elif self.recid:
            # Handle RESTful calls from logged in users by redirecting to
            # generic URL.
            redirect_to_url(req, '%s/%s/edit/#state=edit&recid=%s&recrev=%s' % (
                    CFG_SITE_SECURE_URL, CFG_SITE_RECORD, self.recid, ""))

        elif recid is not None:
            json_response.update({'recID': recid})
            if json_data['requestType'] == "getRecord":
                # Authorize access to record.
                if not user_can_edit_record_collection(req, recid):
                    json_response.update({'resultCode': 101})
                    return json.dumps(json_response)

        # Handle request.
        if not ajax_request:
            # Show BibEdit start page.
            body, errors, warnings = perform_request_init(uid, argd['ln'], req, __lastupdated__)
            title = 'Record Editor'
            return page(title       = title,
                        body        = body,
                        errors      = errors,
                        warnings    = warnings,
                        uid         = uid,
                        language    = argd['ln'],
                        navtrail    = navtrail,
                        lastupdated = __lastupdated__,
                        req         = req,
                        body_css_classes = ['bibedit'])
        else:
            # Handle AJAX request.
            json_response.update(perform_request_ajax(req, recid, uid,
                                                      json_data))
            return json.dumps(json_response)