Esempio n. 1
0
 def __init__(self, **kwargs):
     self.id = make_uuid()
     self.name = kwargs['name']
     self.short_name = kwargs['short_name']
     self.importer = kwargs['importer']
     self.data = kwargs.get('data', {})
     self.thumbnail_url = kwargs.get('thumbnail_url')
     self.container = kwargs.get('container')
Esempio n. 2
0
 def create(self, task_tmpl=None, rules_tmpl=None):
     task = task_tmpl or {}
     rules = task_tmpl or {}
     return dict(id=make_uuid(),
                 name='My Project Type',
                 tutorial='Do stuff',
                 description='This project is amazing',
                 parent_template_id=None,
                 importer=None,
                 min_answers=3,
                 max_answers=3,
                 task=task,
                 rules=rules)
Esempio n. 3
0
def reset_api_key():
    """Reset API-KEY for user"""
    if current_user.is_authenticated():
        title = "User: %s · Settings - Reset API KEY" % current_user.fullname
        if request.method == 'GET':
            return render_template('account/reset-api-key.html', title=title)
        else:
            user = db.session.query(model.User).get(current_user.id)
            user.api_key = model.make_uuid()
            db.session.commit()
            msg = gettext('New API-KEY generated')
            flash(msg, 'success')
            return redirect(url_for('account.settings'))
    else:
        return abort(403)
Esempio n. 4
0
def reset_api_key():
    """Reset API-KEY for user"""
    if current_user.is_authenticated():
        title = "User: %s · Settings - Reset API KEY" % current_user.fullname
        if request.method == 'GET':
            return render_template('account/reset-api-key.html',
                                   title=title)
        else:
            user = db.session.query(model.User).get(current_user.id)
            user.api_key = model.make_uuid()
            db.session.commit()
            msg = 'New API-KEY generated'
            flash(msg, 'success')
            return redirect(url_for('account.settings'))
    else:
        return abort(403)
Esempio n. 5
0
def get_template_framework():
    """Return the fields required for different parts of a template.

    A simple way to ensure we have the fields needed for the rest of this
    plugin. It will be up to the frontend to handle CRUD.
    """
    base = {
        'id': make_uuid(),
        'name': '',
        'description': '',
        'parent_template_id': None,
        'min_answers': 3,
        'max_answers': 3,
        'tutorial': ''
    }

    task = {
        'z3950': {
            'database': '',  # a key in z3950_databases
            'institutions': []
        },
        'iiif-annotation': {
            'mode': '',  # select or transcribe
            'tag': '',
            'objective': '',
            'guidance': '',
            'reject': [],
            'fields_schema': []  # Populated with vue-multiselect fields
        }
    }

    rules = {
        'whitespace': '',  # normalise, underscore or full_stop (if any)
        'case': '',  # title, lower or upper (if any)
        'trim_punctuation': False,
        'date_format': False,
        'dayfirst': False,
        'year_first': False,
        'remove_fragment_selector': False
    }

    z3950_databases = current_app.config.get('Z3950_DATABASES', {}).keys()
    response = dict(base=base,
                    rules=rules,
                    task=task,
                    z3950_databases=z3950_databases)
    return Response(json.dumps(response), mimetype='application/json')
Esempio n. 6
0
def reset_api_key(name):
    """
    Reset API-KEY for user.

    Returns a Jinja2 template.

    """
    user = user_repo.get_by_name(name)
    if not user:
        return abort(404)
    ensure_authorized_to('update', user)
    user.api_key = model.make_uuid()
    user_repo.update(user)
    cached_users.delete_user_summary(user.name)
    msg = gettext('New API-KEY generated')
    flash(msg, 'success')
    return redirect(url_for('account.profile', name=name))
Esempio n. 7
0
def reset_api_key(name):
    """
    Reset API-KEY for user.

    Returns a Jinja2 template.

    """
    user = user_repo.get_by_name(name)
    if not user:
        return abort(404)
    ensure_authorized_to('update', user)
    user.api_key = model.make_uuid()
    user_repo.update(user)
    cached_users.delete_user_summary(user.name)
    msg = gettext('New API-KEY generated')
    flash(msg, 'success')
    return redirect(url_for('account.profile', name=name))
Esempio n. 8
0
def reset_api_key(name):
    """
    Reset API-KEY for user.

    Returns a Jinja2 template.

    """
    user = User.query.filter_by(name=name).first()
    if not user:
        return abort(404)
    require.user.update(user)
    title = ("User: %s · Settings"
             "- Reset API KEY") % current_user.fullname
    user.api_key = model.make_uuid()
    db.session.commit()
    cached_users.delete_user_summary(user.name)
    msg = gettext('New API-KEY generated')
    flash(msg, 'success')
    return redirect(url_for('account.profile', name=name))
Esempio n. 9
0
def reset_api_key(name):
    """
    Reset API-KEY for user.

    Returns a Jinja2 template.

    """
    user = user_repo.get_by_name(name)
    if not user:
        return abort(404)
    require.user.update(user)
    title = ("User: %s · Settings"
             "- Reset API KEY") % current_user.fullname
    user.api_key = model.make_uuid()
    user_repo.update(user)
    cached_users.delete_user_summary(user.name)
    msg = gettext('New API-KEY generated')
    flash(msg, 'success')
    return redirect(url_for('account.profile', name=name))
Esempio n. 10
0
def reset_api_key(name):
    """
    Reset API-KEY for user.

    Returns a Jinja2 template.

    """
    if request.method == 'POST':
        user = user_repo.get_by_name(name)
        if not user:
            return abort(404)
        ensure_authorized_to('update', user)
        user.api_key = model.make_uuid()
        user_repo.update(user)
        cached_users.delete_user_summary(user.name)
        msg = gettext('New API-KEY generated')
        flash(msg, 'success')
        return redirect_content_type(url_for('account.profile', name=name))
    else:
        csrf = dict(form=dict(csrf=generate_csrf()))
        return jsonify(csrf)
Esempio n. 11
0
def reset_api_key(name):
    """
    Reset API-KEY for user.

    Returns a Jinja2 template.

    """
    if request.method == 'POST':
        user = user_repo.get_by_name(name)
        if not user:
            return abort(404)
        ensure_authorized_to('update', user)
        user.api_key = model.make_uuid()
        user_repo.update(user)
        cached_users.delete_user_summary(user.name)
        msg = gettext('New API-KEY generated')
        flash(msg, 'success')
        return redirect_content_type(url_for('account.profile', name=name))
    else:
        csrf = dict(form=dict(csrf=generate_csrf()))
        return jsonify(csrf)
Esempio n. 12
0
def reset_api_key():
    """
    Reset API-KEY for user.

    Returns a Jinja2 template.

    """
    if current_user.is_authenticated():
        title = ("User: %s · Settings" "- Reset API KEY") % current_user.fullname
        if request.method == "GET":
            return render_template("account/reset-api-key.html", title=title)
        else:
            user = db.session.query(model.User).get(current_user.id)
            user.api_key = model.make_uuid()
            db.session.commit()
            cached_users.delete_user_summary(user.name)
            msg = gettext("New API-KEY generated")
            flash(msg, "success")
            return redirect(url_for("account.settings"))
    else:
        return abort(403)
Esempio n. 13
0
def reset_api_key(name):
    """
    Reset API-KEY for user.

    Returns a Jinja2 template.

    """
    user = User.query.filter_by(name=name).first()
    if not user:
        return abort(404)
    if current_user.name != user.name:
        return abort(403)

    title = ("User: %s · Settings"
             "- Reset API KEY") % current_user.fullname
    user = db.session.query(model.user.User).get(current_user.id)
    user.api_key = model.make_uuid()
    db.session.commit()
    cached_users.delete_user_summary(user.name)
    msg = gettext('New API-KEY generated')
    flash(msg, 'success')
    return redirect(url_for('account.profile', name=name))
Esempio n. 14
0
def reset_api_key():
    """
    Reset API-KEY for user.

    Returns a Jinja2 template.

    """
    if current_user.is_authenticated():
        title = ("User: %s · Settings"
                 "- Reset API KEY") % current_user.fullname
        if request.method == 'GET':
            return render_template('account/reset-api-key.html',
                                   title=title)
        else:
            user = db.session.query(model.User).get(current_user.id)
            user.api_key = model.make_uuid()
            db.session.commit()
            cached_users.delete_user_summary(user.name)
            msg = gettext('New API-KEY generated')
            flash(msg, 'success')
            return redirect(url_for('account.settings'))
    else: # pragma: no cover
        return abort(403)