Skip to content

Commit

Permalink
Added user page link to dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
gsidebo committed Jun 30, 2016
1 parent e4b9c2c commit a62a0b3
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 55 deletions.
4 changes: 2 additions & 2 deletions static/js/components/Header.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import React from 'react';
import LoginButton from '../containers/LoginButton';
import UserMenu from '../containers/UserMenu';
import { Navbar } from 'react-bootstrap';

class Header extends React.Component {
Expand All @@ -13,7 +13,7 @@ class Header extends React.Component {
let content;
if (!empty) {
content = <div className="nav-utility pull-right">
<LoginButton />
<UserMenu />
</div>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import MenuItem from 'react-bootstrap/lib/MenuItem';

import { getPreferredName } from '../util/util';

class LoginButton extends React.Component {
class UserMenu extends React.Component {
static propTypes = {
dispatch: React.PropTypes.func.isRequired,
profile: React.PropTypes.object.isRequired,
Expand All @@ -30,15 +30,21 @@ class LoginButton extends React.Component {
<SplitButton
title={title}
bsStyle="danger"
id="logout-button">
id="user-menu">
<LinkContainer to={{ pathname: `/users/${profile.username}` }} active={false}>
<MenuItem>
Profile
</MenuItem>
</LinkContainer>
<LinkContainer to={{ pathname: '/settings' }} active={false}>
<MenuItem>
Settings
</MenuItem>
</LinkContainer>
<MenuItem
href="/logout"
eventKey="logout">
eventKey="logout"
id="logout-link">
Logout
</MenuItem>
</SplitButton>
Expand All @@ -63,4 +69,4 @@ const mapStateToProps = (state) => {
};
};

export default connect(mapStateToProps)(LoginButton);
export default connect(mapStateToProps)(UserMenu);
2 changes: 1 addition & 1 deletion static/js/containers/UserPage_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe("UserPage", function() {

it('should have a logout button', () => {
return renderComponent(`/users/${SETTINGS.username}`, userActions).then(([, div]) => {
let button = div.querySelector("#logout-button");
let button = div.querySelector("#logout-link");
assert.ok(button);
});
});
Expand Down
40 changes: 21 additions & 19 deletions ui/templates/base_error.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% block extrahead %}
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"
integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
{% endblock %}

{% block content %}
Expand All @@ -17,34 +17,36 @@
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a href="/" class="navbar-brand" href="javascript:void(0)"><img src="/static/images/[email protected]" width="215" height="40" alt="MIT MicroMasters" /></a>
<div class="nav-utility pull-right">
{% if authenticated %}
<div class="dropdown btn-group">
<a href="/" class="navbar-brand" href="javascript:void(0)"><img src="/static/images/[email protected]" width="215" height="40" alt="MIT MicroMasters" /></a>
<div class="nav-utility pull-right">
{% if authenticated %}
<div class="dropdown btn-group">
<a class="btn btn-danger" href="/dashboard"><span>{{ name }}</span></a>
<button aria-label="logout_label" id="logout-button" role="button" class="dropdown-toggle btn btn-danger"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" type="button">
<span><span class="caret"></span></span>
</button>
<ul class="dropdown-menu" aria-labelledby="logout-button">
<li role="presentation" class=""><a role="menuitem" href="/logout" tabindex="-1">Logout</a></li>
</ul>
</div>
{% else %}
<button aria-label="logout_label" id="user-menu" role="button" class="dropdown-toggle btn btn-danger"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" type="button">
<span><span class="caret"></span></span>
</button>
<ul class="dropdown-menu" aria-labelledby="user-menu">
<li role="presentation" class=""><a role="menuitem" href="/users/{{ username }}" tabindex="-1">Profile</a></li>
<li role="presentation" class=""><a role="menuitem" href="/settings" tabindex="-1">Settings</a></li>
<li role="presentation" class=""><a role="menuitem" href="/logout" tabindex="-1">Logout</a></li>
</ul>
</div>
{% else %}
<span>Get Started Today!</span>
<a class="btn btn-danger" href="{% url 'social:begin' 'edxorg' %}">
Sign in with edX.org
</a>
{% endif %}
</div>
{% if authenticated %}
</div>
{% if authenticated %}
<ul class="nav navbar-toolbar navbar-left">
<li class="active">
<a href="/dashboard">Dashboard</a>
</li>
</ul>
{% endif %}
</div>
</div>
</div>
</nav>

Expand All @@ -53,8 +55,8 @@

<div>
<div class="card-header">
{% block error_header %}
{% endblock %}
{% block error_header %}
{% endblock %}
</div>
<div class="card-copy">
{% block error_content %}
Expand Down
39 changes: 17 additions & 22 deletions ui/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,43 +103,38 @@ def get(self, request, *args, **kwargs):
return super(UsersView, self).get(request, *args, **kwargs)


def page_404(request):
def standard_error_page(request, status_code, template_filename):
"""
Overridden handler for the 404 error pages.
Returns an error page with a given template filename and provides necessary context variables
"""
name = request.user.profile.preferred_name if not request.user.is_anonymous() else ""

authenticated = not request.user.is_anonymous()
username = None if not authenticated else request.user.social_auth.get(provider=EdxOrgOAuth2.name).uid
response = render(
request,
"404.html",
template_filename,
context={
"style_src": get_bundle_url(request, "style.js"),
"dashboard_src": get_bundle_url(request, "dashboard.js"),
"js_settings_json": "{}",
"authenticated": not request.user.is_anonymous(),
"authenticated": authenticated,
"name": name,
"username": username
}
)
response.status_code = 404
response.status_code = status_code
return response


def page_500(request):
def page_404(request):
"""
Overridden handler for the 500 error pages.
Overridden handler for the 404 error pages.
"""
name = request.user.profile.preferred_name if not request.user.is_anonymous() else ""
return standard_error_page(request, 404, "404.html")

response = render(
request,
"500.html",
context={
"style_src": get_bundle_url(request, "style.js"),
"dashboard_src": get_bundle_url(request, "dashboard.js"),
"js_settings_json": "{}",
"authenticated": not request.user.is_anonymous(),
"name": name,
}
)
response.status_code = 500
return response

def page_500(request):
"""
Overridden handler for the 404 error pages.
"""
return standard_error_page(request, 500, "500.html")
18 changes: 11 additions & 7 deletions ui/views_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create_and_login_user(self):
uid="{}_edx".format(profile.user.username),
)
self.client.force_login(profile.user)
return profile.user
return profile


class TestHomePage(ViewsTests):
Expand Down Expand Up @@ -119,7 +119,8 @@ def test_index_context_logged_in_social_auth(self):
"""
Assert context values when logged in as social auth user
"""
user = self.create_and_login_user()
profile = self.create_and_login_user()
user = profile.user
ga_tracking_id = FuzzyText().fuzz()
with self.settings(
GA_TRACKING_ID=ga_tracking_id,
Expand Down Expand Up @@ -159,7 +160,8 @@ def test_dashboard_settings(self):
"""
Assert settings we pass to dashboard
"""
user = self.create_and_login_user()
profile = self.create_and_login_user()
user = profile.user

ga_tracking_id = FuzzyText().fuzz()
react_ga_debug = FuzzyText().fuzz()
Expand Down Expand Up @@ -211,7 +213,7 @@ def test_404_error_context_logged_in(self):
Assert context values for 404 error page when logged in
"""
with mute_signals(post_save):
profile = ProfileFactory.create()
profile = self.create_and_login_user()
self.client.force_login(profile.user)

# case with specific page
Expand Down Expand Up @@ -249,7 +251,7 @@ def test_500_error_context_logged_in(self):
Assert context values for 500 error page when logged in
"""
with mute_signals(post_save):
profile = ProfileFactory.create()
profile = self.create_and_login_user()
self.client.force_login(profile.user)

response = self.client.get('/500/')
Expand Down Expand Up @@ -347,7 +349,8 @@ def test_users_logged_in(self):
"""
Assert settings we pass to dashboard
"""
user = self.create_and_login_user()
profile = self.create_and_login_user()
user = profile.user
username = user.social_auth.get(provider=EdxOrgOAuth2.name).uid

ga_tracking_id = FuzzyText().fuzz()
Expand Down Expand Up @@ -381,7 +384,8 @@ def test_users_anonymous(self):
"""
Assert settings we pass to dashboard
"""
user = self.create_and_login_user()
profile = self.create_and_login_user()
user = profile.user
self.client.logout()
username = user.social_auth.get(provider=EdxOrgOAuth2.name).uid

Expand Down

0 comments on commit a62a0b3

Please sign in to comment.