Exemplo n.º 1
0
def test_slugify():
    for text, expected in (
        ('foo', 'foo'),
        ('Foo$$$', 'foo'),
        ('James\' Rifles', 'james-rifles')):

        eq_(slugify(text), expected)
Exemplo n.º 2
0
def add_team(name, slug=None):
    """Creates a team."""
    if slug is None:
        slug = slugify(name)

    team = db.query(Team).filter_by(slug=slug).first()
    if team:
        print 'Team "%s" (%s) already exists.' % (team.name, team.slug)
        return

    team = Team(name=name, slug=slug)
    db.add(team)
    db.commit()

    print 'Team "%s" created!' % team.name
Exemplo n.º 3
0
def add_team(name, slug=None):
    """Creates a team."""
    if slug is None:
        slug = slugify(name)

    team = db.query(Team).filter_by(slug=slug).first()
    if team:
        print 'Team "%s" (%s) already exists.' % (team.name, team.slug)
        return

    team = Team(name=name, slug=slug)
    db.add(team)
    db.commit()

    print 'Team "%s" created!' % team.name
Exemplo n.º 4
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 == session['email']).first()

    if not user:
        # Create a user if one does not already exist for this email
        # address.
        user = User.query.filter_by(email=session['email']).first()
        if not user:
            username = email.split('@')[0]
            user = User(username=username, name=username, email=email,
                        slug=slugify(username), github_handle=username)
            db.session.add(user)
            db.session.commit()

    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('index')))
    return redirect(redirect_url)
Exemplo n.º 5
0
def add_project(name, slug=None, repo_url=None, color=None):
    """Creates a project."""
    if slug == None:
        slug = slugify(name)

    if repo_url == None:
        repo_url = ''

    if color == None:
        color = 'FF0000'

    project = Project.query.filter_by(slug=slug).first()
    if project:
        print 'Project "%s" (%s) already exists.' % (project.name, project.slug)
        return

    project = Project(name=name, slug=slug, repo_url=repo_url, color=color)
    db.session.add(project)
    db.session.commit()

    print 'Project "%s" created!' % project.name
Exemplo n.º 6
0
def add_project(name, slug=None, repo_url=None, color=None):
    """Creates a project."""
    if slug is None:
        slug = slugify(name)

    if repo_url is None:
        repo_url = ''

    if color is None:
        color = 'FF0000'

    project = db.query(Project).filter_by(slug=slug).first()
    if project:
        print 'Project "%s" (%s) already exists.' % (project.name,
                                                     project.slug)
        return

    project = Project(name=name, slug=slug, repo_url=repo_url, color=color)
    db.add(project)
    db.commit()

    print 'Project "%s" created!' % project.name
Exemplo n.º 7
0
Arquivo: app.py Projeto: hsgr/standup
def authenticate():
    """Authenticate user with Persona."""
    data = browserid.verify(request.form['assertion'],
                            settings.SITE_URL)
    email = data['email']
    session['email'] = email

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

    # Create a user if one does not already exist for this email
    # address.
    user = User.query.filter_by(email=email).first()
    if not user:
        # TODO: We assume the user wants the first part of their email
        # address to be their username. Good idea? Probably not.
        username = email.split('@')[0]
        user = User(username=username, name=username, email=email,
                    slug=slugify(username), github_handle=username)
        db.session.add(user)
        db.session.commit()

    response = jsonify({'email': user.email})
    response.status_code = 200
    return response
Exemplo n.º 8
0
def test_slugify():
    """Test the slugify function"""
    for text, expected in ((u'foo', 'foo'), (u'Foo$$$', 'foo'),
                           (u'James\' Rifles', 'james-rifles')):

        eq_(slugify(text), expected)
Exemplo n.º 9
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))
Exemplo n.º 10
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))
Exemplo n.º 11
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))
Exemplo n.º 12
0
def update_user(username):
    """Update settings for an existing user.

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

    * user (the username of the IRC user)
    * api_key

    You may optionally supply the following settings to overwrite
    their values:

    * name
    * email
    * github_handle

    An example of the JSON:

        {
            "user": "******",
            "email": "*****@*****.**"
            "api_key": "qwertyuiopasdfghjklzxcvbnm1234567890"
        }
    """

    # The data we need
    authorname = request.json.get('user')

    # Optional data
    name = request.json.get('name')
    email = request.json.get('email')
    github_handle = request.json.get('github_handle')

    if not (username and authorname and (name or email or github_handle)):
        return make_response(
            jsonify(dict(error='Missing required fields')), 400)

    author = User.query.filter(User.username==authorname)[0]

    user = User.query.filter(User.username==username)

    if not user.count():
        user = User(username=username, slug=slugify(username))
    else:
        user = user[0]

    if author.username != user.username and not author.is_admin:
        return make_response(
            jsonify(dict(error='You cannot modify this user.')), 403)

    if name:
        user.name = name

    if email:
        user.email = email

    if github_handle:
        user.github_handle = github_handle

    db.session.commit()

    return make_response(jsonify(dict(id=user.id)))