Ejemplo n.º 1
0
def statusize():
    """Posts a status from the web."""
    db = get_session(current_app)

    user_id = session.get('user_id')
    if not user_id:
        return forbidden('You must be logged in to statusize!')

    user = db.query(User).get(user_id)

    message = request.form.get('message', '')

    if not message:
        return page_not_found('You cannot statusize nothing!')

    status = Status(user_id=user.id, content=message, content_html=message)

    project = request.form.get('project', '')
    if project:
        project = db.query(Project).filter_by(id=project).first()
        if project:
            status.project_id = project.id

    # TODO: reply handling

    db.add(status)
    db.commit()

    # Try to go back from where we came.
    referer = request.headers.get('referer', url_for('status.index'))
    redirect_url = request.form.get('redirect_to', referer)
    return redirect(redirect_url)
Ejemplo n.º 2
0
def statusize():
    """Posts a status from the web."""
    db = get_session(current_app)

    user_id = session.get('user_id')
    if not user_id:
        return forbidden('You must be logged in to statusize!')

    user = db.query(User).get(user_id)

    message = request.form.get('message', '')

    if not message:
        return page_not_found('You cannot statusize nothing!')

    status = Status(user_id=user.id, content=message, content_html=message)

    project = request.form.get('project', '')
    if project:
        project = db.query(Project).filter_by(id=project).first()
        if project:
            status.project_id = project.id

    # TODO: reply handling

    db.add(status)
    db.commit()

    # Try to go back from where we came.
    referer = request.headers.get('referer', url_for('status.index'))
    redirect_url = request.form.get('redirect_to', referer)
    return redirect(redirect_url)
Ejemplo n.º 3
0
def statusize():
    """Posts a status from the web."""
    email = session.get('email')
    if not email:
        return forbidden('You must be logged in to statusize!')

    user = User.query.filter(User.email == email).first()

    if not user:
        return forbidden('You must have a user account to statusize!')

    message = request.form.get('message', '')

    if not message:
        return page_not_found('You cannot statusize nothing!')

    status = Status(user_id=user.id, content=message, content_html=message)

    project = request.form.get('project', '')
    if project:
        project = Project.query.filter_by(id=project).first()
        if project:
            status.project_id = project.id

    # TODO: reply handling

    db.session.add(status)
    db.session.commit()

    # Try to go back from where we came.
    redirect_url = request.form.get('redirect_to',
        request.headers.get('referer',
            url_for('status.index')))
    return redirect(redirect_url)
Ejemplo n.º 4
0
def status(**kwargs):
    """Model maker for Status"""
    defaults = dict(content='This is a status update.',
                    content_html='This is a status update.')
    defaults.update(kwargs)

    if 'user' not in kwargs and 'user_id' not in kwargs:
        defaults['user'] = user(save=True)

    if 'project' not in kwargs and 'project_id' not in kwargs:
        defaults['project'] = project(save=True)

    return Status(**defaults)
Ejemplo n.º 5
0
def create_status():
    """Post a new status.

    The status should be posted as JSON using 'application/json' as
    the content type. The posted JSON needs to have 3 required fields:

    * user (the username)
    * content
    * api_key

    An example of the JSON::

        {
            "user": "******",
            "project": "sumodev",
            "content": "working on bug 123456",
            "api_key": "qwertyuiopasdfghjklzxcvbnm1234567890"
        }

    """
    db = get_session(current_app)

    # The data we need
    username = request.json.get('user')
    project_slug = request.json.get('project')
    content = request.json.get('content')
    reply_to = request.json.get('reply_to')

    # Validate we have the required fields.
    if not (username and content):
        return jsonify(dict(error='Missing required fields.')), 400

    # If this is a reply make sure that the status being replied to
    # exists and is not itself a reply
    if reply_to:
        replied = db.query(Status).filter_by(id=reply_to).first()
        if not replied:
            return jsonify(dict(error='Status does not exist.')), 400
        elif replied.reply_to:
            return jsonify(dict(error='Cannot reply to a reply.')), 400
    else:
        replied = None

    # Get the user
    user = db.query(User).filter_by(username=username).first()
    if not user:
        #autocreate users for testing
        user = user_test_thingy(username=username, name=username, email=username+"@mozilla.com", slug=username, save=True)

    # Get or create the project (but not if this is a reply)
    if project_slug and not replied:
        # This forces the slug to be slug-like.
        project_slug = slugify(project_slug)
        project = db.query(Project).filter_by(slug=project_slug).first()
        if not project:
            project = Project(slug=project_slug, name=project_slug)
            db.add(project)
            db.commit()

    # Create the status
    status = Status(user_id=user.id, content=content, content_html=content)
    if project_slug and project:
        status.project_id = project.id
    if replied:
        status.reply_to_id = replied.id
    db.add(status)
    db.commit()

    return jsonify(dict(id=status.id, content=content))
Ejemplo n.º 6
0
def create_status():
    """Post a new status.

    The status should be posted as JSON using 'application/json' as
    the content type. The posted JSON needs to have 3 required fields:

    * user (the username)
    * content
    * api_key

    An example of the JSON::

        {
            "user": "******",
            "project": "sumodev",
            "content": "working on bug 123456",
            "api_key": "qwertyuiopasdfghjklzxcvbnm1234567890"
        }

    """
    db = get_session(current_app)

    # The data we need
    username = request.json.get('user')
    project_slug = request.json.get('project')
    content = request.json.get('content')
    reply_to = request.json.get('reply_to')

    # Validate we have the required fields.
    if not (username and content):
        return jsonify(dict(error='Missing required fields.')), 400

    # If this is a reply make sure that the status being replied to
    # exists and is not itself a reply
    if reply_to:
        replied = db.query(Status).filter_by(id=reply_to).first()
        if not replied:
            return jsonify(dict(error='Status does not exist.')), 400
        elif replied.reply_to:
            return jsonify(dict(error='Cannot reply to a reply.')), 400
    else:
        replied = None

    # Get the user
    user = db.query(User).filter_by(username=username).first()
    if not user:
        return jsonify(dict(error='User does not exist.')), 400

    # Get or create the project (but not if this is a reply)
    if project_slug and not replied:
        # This forces the slug to be slug-like.
        project_slug = slugify(project_slug)
        project = db.query(Project).filter_by(slug=project_slug).first()
        if not project:
            project = Project(slug=project_slug, name=project_slug)
            db.add(project)
            db.commit()

    # Create the status
    status = Status(user_id=user.id, content=content, content_html=content)
    if project_slug and project:
        status.project_id = project.id
    if replied:
        status.reply_to_id = replied.id
    db.add(status)
    db.commit()

    return jsonify(dict(id=status.id, content=content))
Ejemplo n.º 7
0
def create_status():
    """Post a new status.

    The status should be posted as JSON using 'application/json' as
    the content type. The posted JSON needs to have 3 required fields:

    * user (the username)
    * content
    * api_key

    An example of the JSON::

        {
            "user": "******",
            "project": "sumodev",
            "content": "working on bug 123456",
            "api_key": "qwertyuiopasdfghjklzxcvbnm1234567890"
        }
    """
    # The data we need
    username = request.json.get('user')
    project_slug = request.json.get('project')
    content = request.json.get('content')
    reply_to = request.json.get('reply_to')

    # Validate we have the required fields.
    if not (username and content):
        return make_response(
            jsonify(dict(error='Missing required fields.')), 400)

    # If this is a reply make sure that the status being replied to
    # exists and is not itself a reply
    if reply_to:
        replied = Status.query.filter_by(id=reply_to).first()
        if not replied:
            return make_response(
                jsonify(dict(error='Status does not exist.')), 400)
        elif replied.reply_to:
            return make_response(
                jsonify(dict(error='Cannot reply to a reply.')), 400)
    else:
        replied = None

    # Get or create the user
    # TODO: People change their nicks sometimes, figure out what to do.
    user = User.query.filter_by(username=username).first()
    if not user:
        user = User(username=username, name=username,
            slug=slugify(username), github_handle=username)
        db.session.add(user)
        db.session.commit()

    # Get or create the project (but not if this is a reply)
    if project_slug and not replied:
        # This forces the slug to be slug-like.
        project_slug = slugify(project_slug)
        project = Project.query.filter_by(slug=project_slug).first()
        if not project:
            project = Project(slug=project_slug, name=project_slug)
            db.session.add(project)
            db.session.commit()

    # Create the status
    status = Status(user_id=user.id, content=content, content_html=content)
    if project_slug and project:
        status.project_id = project.id
    if replied:
        status.reply_to_id = replied.id
    db.session.add(status)
    db.session.commit()

    return jsonify(dict(id=status.id, content=content))