def get_revisions(endpoint, pid_value): """Get revisions of given record""" Transaction = transaction_class(RecordMetadata) pid_type = get_pid_type_from_endpoint(endpoint) record = get_db_record(pid_type, pid_value) revisions = [] for revision in reversed(record.revisions): transaction_id = revision.model.transaction_id user = Transaction.query.filter( Transaction.id == transaction_id).one().user if user: user_email = user.email else: user_email = 'system' revisions.append({ 'updated': revision.updated, 'revision_id': revision.revision_id, 'user_email': user_email, 'transaction_id': transaction_id, 'rec_uuid': record.id }) return jsonify(revisions)
def revert_to_revision(endpoint, pid_value): """Revert given record to given revision""" pid_type = get_pid_type_from_endpoint(endpoint) record = get_db_record(pid_type, pid_value) revision_id = request.json['revision_id'] record.revert(revision_id) db.session.commit() return jsonify(success=True)
def ajax_citations(): """Handler for datatables citations view""" recid = request.args.get('recid', '') endpoint = request.args.get('endpoint', '') pid_type = get_pid_type_from_endpoint(endpoint) pid = PersistentIdentifier.get(pid_type, recid) record = LiteratureSearch().get_source(pid.object_uuid) return jsonify({'data': get_and_format_citations(record)})
def ajax_references(): """Handler for datatables references view""" recid = request.args.get('recid', '') endpoint = request.args.get('endpoint', '') pid_type = get_pid_type_from_endpoint(endpoint) pid = PersistentIdentifier.get(pid_type, recid) record = LiteratureSearch().get_source(pid.object_uuid) return jsonify({"data": Reference(record).references()})
def ajax_references(): """Handler for datatables references view. .. deprecated:: 2018-06-07 """ recid = request.args.get('recid', '') endpoint = request.args.get('endpoint', '') pid_type = get_pid_type_from_endpoint(endpoint) pid = PersistentIdentifier.get(pid_type, recid) record = LiteratureSearch().get_source(pid.object_uuid) return jsonify({'data': get_and_format_references(record)})
def ajax_citations(): """Handler for datatables citations view .. deprecated:: 2018-08-23 """ recid = request.args.get('recid', '') endpoint = request.args.get('endpoint', '') pid_type = get_pid_type_from_endpoint(endpoint) pid = PersistentIdentifier.get(pid_type, recid) record = LiteratureSearch().get_source(pid.object_uuid) return jsonify({'data': get_and_format_citations(record)})
def ajax_citations(): """Handler for datatables citations view""" recid = request.args.get('recid', '') endpoint = request.args.get('endpoint', '') pid_type = get_pid_type_from_endpoint(endpoint) pid = PersistentIdentifier.get(pid_type, recid) record = LiteratureSearch().get_source(pid.object_uuid) return jsonify( { "data": Citation(record).citations() } )
def decorator(endpoint, pid_value, **kwargs): cache_key = 'editor-permission-{0}-{1}'.format(endpoint, pid_value) is_allowed = session.get(cache_key) if is_allowed is not None: if is_allowed: return fn(endpoint, pid_value, **kwargs) else: abort(403) pid_type = get_pid_type_from_endpoint(endpoint) record = get_db_record(pid_type, pid_value) is_allowed = has_update_permission(current_user, record) session[cache_key] = is_allowed if is_allowed: return fn(endpoint, pid_value, **kwargs) else: abort(403)
def get_remote_json(self, uri, **kwargs): parsed_uri = url_parse(uri) # Add http:// protocol so uri.netloc is correctly parsed. server_name = current_app.config.get('SERVER_NAME') parsed_server = url_parse(ensure_scheme(server_name)) if parsed_uri.netloc and parsed_uri.netloc != parsed_server.netloc: return super(AbstractRecordLoader, self).get_remote_json(uri, **kwargs) path_parts = parsed_uri.path.strip('/').split('/') if len(path_parts) < 2: current_app.logger.error('Bad JSONref URI: {0}'.format(uri)) return None endpoint = path_parts[-2] pid_type = get_pid_type_from_endpoint(endpoint) recid = path_parts[-1] res = self.get_record(pid_type, recid) return res
def decorator(endpoint, pid_value, **kwargs): cache_key = 'editor-permission-{0}-{1}'.format( endpoint, pid_value ) is_allowed = session.get(cache_key) if is_allowed is not None: if is_allowed: return fn(endpoint, pid_value, **kwargs) else: abort(403) pid_type = get_pid_type_from_endpoint(endpoint) record = get_db_record(pid_type, pid_value) is_allowed = has_update_permission(current_user, record) session[cache_key] = is_allowed if is_allowed: return fn(endpoint, pid_value, **kwargs) else: abort(403)
def test_get_pid_type_from_endpoint(): expected = 'lit' result = get_pid_type_from_endpoint('literature') assert expected == result