Beispiel #1
0
 def test_returns_current_user(self):
     u = User(name='Numpy', google_id='12345', email='*****@*****.**')
     u.save()
     with app.test_request_context():
         session['user_id'] = '12345'
         c_user = current_user()
         self.assertEqual(c_user, u)
Beispiel #2
0
def github_authorized():
    """
    Post-authentication redirect route.
    Adds access token to the session.
    """

    if not 'code' in request.args:
        flash(u'Whoops, you denied us access to your Github account')
        return redirect(url_for('github_login'))

    redirect_uri = url_for('github_authorized', _external=True)
    data = dict(code=request.args['code'], redirect_uri=redirect_uri, scope='user,repo')
    session_ = github.get_auth_session(data=data)

    # Store access token in session.
    session['github_access_token'] = session_.access_token

    from app.models.user import current_user
    current_user = current_user()
    current_user.github_id = session_.get('/user').json()['id']
    current_user.github_access = session_.access_token
    current_user.save()

    # Redirect
    return redirect('/')
Beispiel #3
0
 def test_default_user_image(self):
     self.mock_google_user_info.return_value = {
             'id': '12345',
             'name': 'Numpy',
             'email': '*****@*****.**'
     }
     with app.test_request_context():
         c_user = current_user()
         self.assertEqual(c_user.picture, 'http://localhost/assets/img/default_pic.png')
Beispiel #4
0
    def test_creates_current_user(self):
        self.mock_google_user_info.return_value = {
                'id': '12345',
                'name': 'Numpy',
                'picture': 'http://foo.com/image.png',
                'email': '*****@*****.**'
        }

        with app.test_request_context():
            c_user = current_user()
            self.assertEqual(session['user_id'], '12345')
            self.assertEqual(User.objects.count(), 1)
Beispiel #5
0
    def get(self, slug):
        # List view
        if slug is None:
            projects = Project.objects.all()
            return render_template('project/list.html', projects=projects, current_user=current_user())
        # Detail view
        else:
            ctx = self.get_context(slug=slug)
            project = ctx['project']
            try:
                project.sync()
            except KeyError as e:
                if current_user().linked():
                    return redirect(url_for('github_login'))
                else:
                    return redirect(url_for('github_info'))
            issues = Issue.objects(project=project, open=True)

            return render_template('issue/list.html', issues=issues, project=project)
Beispiel #6
0
def google_authorized():
    """
    Post-authentication redirect route.
    Adds access token to the session.
    """

    if not 'code' in request.args:
        flash(u'Whoops, you denied us access to your Google account')
        return redirect(url_for('google_login'))

    credentials = flow.step2_exchange(request.args['code'])

    # Store access token in session.
    session['google_creds'] = credentials.to_json()

    from app.models.user import current_user
    user = current_user()
    user.google_creds = credentials.to_json()
    user.save()

    # Redirect
    return redirect('/')
Beispiel #7
0
 def put(self, slug, issue_id, id):
     comment = Comment.objects(id=id).first()
     form = self.form(request.form)
     form.populate_obj(comment)
     comment.process(request.files)
     return jsonify({'success':True, 'html':render_template('comment.html', current_user=current_user(), comment=comment)})
Beispiel #8
0
def current_user_processor():
    user = current_user()
    return dict(current_user=user)
Beispiel #9
0
    def get(self, slug, id):
        ctx = self.get_context(slug=slug, id=id)
        project = ctx['project']

        # List view
        if id is None:
            issues = Issue.objects(project=project)
            return render_template('issue/list.html', issues=issues, project=project)
        # Detail view
        else:
            comment_form = model_form(Comment, exclude=['created_at', 'updated_at', 'author', 'mentions', 'attachments'])
            form = comment_form(request.form)

            issue = ctx['issue']
            issue.sync()
            all_events = issue.all_events()

            return render_template('issue/detail.html', issue=issue, events=all_events, form=form, current_user=current_user(), project=project)