<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def acp_users_delete():
 """Delete or undelete an user account."""

    if not current_user.is_admin:
        return error("Not authorized to edit users.", 401)
    if not db:
        return error('The ACP is not available in single-user mode.', 500)

    form = UserDeleteForm()
    if not form.validate():
        return error("Bad Request", 400)
    user = get_user(int(request.form['uid']))
    direction = request.form['direction']
    if not user:
        return error("User does not exist.", 404)
    else:
        for p in PERMISSIONS:
            setattr(user, p, False)
        user.active = direction == 'undel'
        write_user(user)
        return redirect(url_for('acp_users') + '?status={_del}eted'.format(
            _del=direction))