Esempio n. 1
0
def disable_user(user_id=None):
    """Set enabled flag to False for user_id."""
    if user_id:
        user = user_repo.get(user_id)
        if user:
            # avoid disabling admin/subadmin user by subadmin with direct url
            if not can_update_user_info(current_user, user)[0]:
                return abort(403)

            user.enabled = False
            user_repo.update(user)
            msg = generate_manage_user_email(user, "disable")
            if msg:
                mail_queue.enqueue(send_mail, msg)
            return redirect(url_for('.manageusers'))
    msg = "User not found"
    return format_error(msg, 404)
Esempio n. 2
0
def enable_user(user_id=None):
    """Set enabled flag to True for user_id."""
    if user_id:
        user = user_repo.get(user_id)
        if user:
            # avoid enabling admin/subadmin user by subadmin with direct url
            if not can_update_user_info(current_user, user)[0]:
                return abort(403)

            user.enabled = True
            user.last_login = make_timestamp()
            user_repo.update(user)
            msg = generate_manage_user_email(user, "enable")
            if msg:
                mail_queue.enqueue(send_mail, msg)
            return redirect(url_for(".manageusers"))
    msg = "User not found"
    return format_error(msg, 404)
Esempio n. 3
0
def disable_users_job():
    from sqlalchemy.sql import text
    from pybossa.model.user import User
    from pybossa.core import db, user_repo
    from pybossa.util import generate_manage_user_email
    sql = text('''Select id
                  FROM public.user
                  WHERE current_timestamp - to_timestamp(last_login, 'YYYY-MM-DD"T"HH24:MI:SS.US') > interval '3 month'
                  AND enabled = true AND admin = false;
               ''')
    results = db.slave_session.execute(sql)
    for row in results:
        user = User.query.get(row.id)
        user.enabled = False
        user_repo.update(user)
        msg = generate_manage_user_email(user, "disable")
        if msg:
            send_mail(msg)
    return True
Esempio n. 4
0
def enable_user(user_id=None):
    """Set enabled flag to True for user_id."""
    try:
        if user_id:
            user = user_repo.get(user_id)
            if user:
                # avoid enabling admin/subadmin user by subadmin with direct url
                if not can_update_user_info(current_user, user):
                    return abort(403)

                user.enabled = True
                user_repo.update(user)
                msg = generate_manage_user_email(user, "enable")
                if msg:
                    mail_queue.enqueue(send_mail, msg)
                return redirect(url_for(".manageusers"))
        msg = "User not found"
        return format_error(msg, 404)
    except Exception as e:  # pragma: no cover
        current_app.logger.error(e)
        return abort(500)