示例#1
0
def inject_globals():
    from art17.auth import current_user

    cfg = get_config()

    today = date.today()
    if cfg.start_date:
        if cfg.end_date:
            consultation_started = cfg.start_date <= today <= cfg.end_date
        else:
            consultation_started = cfg.start_date <= today
    else:
        consultation_started = False

    is_public = not current_user.is_authenticated() or is_public_user()

    return {
        'APP_BREADCRUMBS': [('Article 17', flask.url_for(HOMEPAGE_VIEW_NAME))],
        'consultation_started': consultation_started,
        'today': today,
        'start_date': cfg.start_date,
        'end_date': cfg.end_date,
        'is_public': is_public,
        'current_user': current_user,
    }
示例#2
0
def must_edit_ref(assessment):
    if not current_user.is_authenticated() or not assessment:
        return False
    if assessment.user_id == current_user.id:
        return False

    return etc_perm.can() or admin_perm.can()
示例#3
0
def must_edit_ref(assessment):
    if not current_user.is_authenticated() or not assessment:
        return False
    if assessment.user_id == current_user.id:
        return False

    return etc_perm.can() or admin_perm.can()
def can_toggle_read(comment):
    if not comment or not current_user.is_authenticated():
        return False

    if comment.author_id == current_user.id:
        return False

    return True
示例#5
0
def can_toggle_read(comment):
    if not comment or not current_user.is_authenticated():
        return False

    if comment.author_id == current_user.id:
        return False

    return True
示例#6
0
def can_edit_comment(comment):
    if not comment or (not current_user.is_authenticated() and not EU_ASSESSMENT_MODE):
        return False
    if comment and comment.record and comment.record.dataset and \
            comment.record.dataset.is_readonly:
        return False
    return (not comment.record.deleted and not comment.deleted and
            comment.author_id == current_user.id and not sta_cannot_change())
示例#7
0
def can_preview_progress():
    if consultation_ended():
        return True

    if not current_user.is_authenticated():
        return False

    return current_user.has_role('etc') or current_user.has_role('admin')
示例#8
0
def can_preview_progress():
    if consultation_ended():
        return True

    if not current_user.is_authenticated():
        return False

    return current_user.has_role('etc') or current_user.has_role('admin')
def can_edit_comment(comment):
    if not comment or (not current_user.is_authenticated()
                       and not EU_ASSESSMENT_MODE):
        return False
    if comment and comment.record and comment.record.dataset and \
            comment.record.dataset.is_readonly:
        return False
    return (not comment.record.deleted and not comment.deleted
            and comment.author_id == current_user.id
            and not sta_cannot_change())
示例#10
0
def can_delete_comment(comment):
    if not comment or not current_user.is_authenticated():
        return False

    if comment.author_id == current_user.id:
        if sta_cannot_change():
            return False
        return True

    return admin_perm.can()
示例#11
0
def can_delete_comment(comment):
    if not comment or not current_user.is_authenticated():
        return False

    if comment.author_id == current_user.id:
        if sta_cannot_change():
            return False
        return True

    return admin_perm.can()
示例#12
0
 def dispatch_request(self):
     if not current_user.is_authenticated():
         raise PermissionDenied
     period = request.args.get('period') or get_default_period()
     period_obj = Dataset.query.get(period)
     history = self.get_history(period)
     return render_template(
         self.template,
         history=history,
         subject_name=self.subject_name,
         summary_endpoint=self.summary_endpoint,
         period=period_obj,
     )
示例#13
0
 def dispatch_request(self):
     if not current_user.is_authenticated():
         raise PermissionDenied
     period = request.args.get('period') or get_default_period()
     period_obj = Dataset.query.get(period)
     history = self.get_history(period)
     return render_template(
         self.template,
         history=history,
         subject_name=self.subject_name,
         summary_endpoint=self.summary_endpoint,
         period=period_obj,
     )
示例#14
0
def login():
    if current_user.is_authenticated():
        flash('You are already logged in.')
        return redirect(url_for(HOMEPAGE_VIEW_NAME))

    form = LoginForm(request.form)

    if request.method == 'POST' and form.validate():
        username = request.form.get('username')
        password = request.form.get('password')
        try:
            models.RegisteredUser.try_login(username, password)
        except ldap.INVALID_CREDENTIALS:

            try_local_login(username, password, form)
            if not current_user.is_authenticated():
                flash('Invalid username or password. Please try again.',
                      'danger')
                return render_template('login.html', form=form)

        user = models.RegisteredUser.query.filter_by(id=username).first()

        if not user:
            user = models.RegisteredUser(id=username,
                                         password=encrypt_password(password),
                                         is_ldap=True,
                                         account_date=datetime.now())
            models.db.session.add(user)
            models.db.session.commit()
        login_user(user)
        g.user = user
        flash('You have successfully logged in.', 'success')
        return redirect(url_for(HOMEPAGE_VIEW_NAME))

    if form.errors:
        flash(form.errors, 'danger')

    return render_template('login.html', form=form)
示例#15
0
def inject_globals():
    from art17.auth import current_user

    cfg = get_config()

    today = date.today()
    if cfg.start_date:
        if cfg.end_date:
            consultation_started = cfg.start_date <= today <= cfg.end_date
        else:
            consultation_started = cfg.start_date <= today
    else:
        consultation_started = False

    is_public = not current_user.is_authenticated() or is_public_user()

    return {
        'APP_BREADCRUMBS': [('Article 17', flask.url_for(HOMEPAGE_VIEW_NAME))],
        'consultation_started': consultation_started,
        'today': today,
        'start_date': cfg.start_date,
        'end_date': cfg.end_date,
        'is_public': is_public,
    }
示例#16
0
def can_post_comment(record):

    if EU_ASSESSMENT_MODE:
        return True
    if not current_user.is_authenticated():
        return False
    if record.dataset and record.dataset.is_readonly:
        return False
    can_add = False
    if sta_cannot_change():
        can_add = False
    elif sta_perm.can() or nat_perm.can():
        if (record.user.has_role('nat') and record.user_id == current_user.id) \
                or not record.user or record.user.has_role('stakeholder'):
                can_add = True
    else:
        can_add = True

    if can_add:
        authors = [c.author_id for c in record.comments]
        if current_user.id in authors:
            return False

    return not record.deleted and can_add
示例#17
0
def can_post_comment(record):

    if EU_ASSESSMENT_MODE:
        return True
    if not current_user.is_authenticated():
        return False
    if record.dataset and record.dataset.is_readonly:
        return False
    can_add = False
    if sta_cannot_change():
        can_add = False
    elif sta_perm.can() or nat_perm.can():
        if (record.user.has_role('nat') and record.user_id == current_user.id) \
                or not record.user or record.user.has_role('stakeholder'):
            can_add = True
    else:
        can_add = True

    if can_add:
        authors = [c.author_id for c in record.comments]
        if current_user.id in authors:
            return False

    return not record.deleted and can_add
示例#18
0
def can_view_details():
    if not current_user.is_authenticated():
        return False

    # return current_user.has_role('etc') or current_user.has_role('admin')
    return current_user.has_role('admin')
示例#19
0
def can_view_details():
    if not current_user.is_authenticated():
        return False

    # return current_user.has_role('etc') or current_user.has_role('admin')
    return current_user.has_role('admin')
示例#20
0
def can_select_assessor():
    if not current_user.is_authenticated():
        return False

    return current_user.has_role('admin')
示例#21
0
def can_select_assessor():
    if not current_user.is_authenticated():
        return False

    return current_user.has_role('admin')