Merge lp:~jakedahn/horizon/lp760239 into lp:~hudson-openstack/horizon/trunk

Proposed by Jake Dahn
Status: Merged
Approved by: Devin Carlen
Approved revision: 35
Merged at revision: 40
Proposed branch: lp:~jakedahn/horizon/lp760239
Merge into: lp:~hudson-openstack/horizon/trunk
Diff against target: 48 lines (+22/-5)
2 files modified
django-nova/src/django_nova/views/images.py (+2/-0)
openstack-dashboard/dashboard/templates/permission_denied.html (+20/-5)
To merge this branch: bzr merge lp:~jakedahn/horizon/lp760239
Reviewer Review Type Date Requested Status
Devin Carlen Approve
Jake Dahn (community) Needs Resubmitting
Review via email: mp+58554@code.launchpad.net

This proposal supersedes a proposal from 2011-04-13.

Description of the change

This branch adds styling to the permission denied page.

To post a comment you must log in.
Revision history for this message
Devin Carlen (devcamcar) wrote : Posted in a previous version of this proposal

10 + 'Permission Denied %s' % e.message)

let's drop the %s and e.message. they are redundant here

review: Needs Fixing
Revision history for this message
Devin Carlen (devcamcar) wrote :

8 + except exceptions.NovaUnauthorizedError, e:
9 + messages.error(request, 'Permission Denied')
10 + return redirect('dashboard_permission_denied')

Hey, in this case, we don't need to redirect. Permission denied as an error panel is sufficient.

Essentially we want handle_exception (or wrap_exception or whatever I called it) to catch the NovaUnauthorizedError. This will be a method of last resort - as we identify other places that need to explicitly catch the NovaUnauthorizedException we will add try/excepts there as well.

review: Needs Fixing
Revision history for this message
Jake Dahn (jakedahn) wrote :

I think we still need to have the redirect.

If there is no redirect it just displays an h1 with the text 'permission denied' - no style or other html, just an h1. The redirect is to send it to /denied which displays the error with consistent style of the rest of the dashboard.

review: Needs Resubmitting
Revision history for this message
Devin Carlen (devcamcar) wrote :

If you are getting redirected to "permission denied" text, then you aren't try/except'ing the error where it's happening.

Each view is wrapped with a decorator @handle_nova_error, like so:

@login_required
@handle_nova_error
def launch(request, project_id, image_id):
    ...

In django_nova/exceptions.py's handle_nova_error method, the following is done if a NovaUnauthorizedException bubbles up and isn't handled by the view itself (launch() in the example above).

def handle_nova_error(func):
    """
    Decorator for handling nova errors in a generalized way.
    """
    def decorator(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except NovaUnavailableError:
            return redirect('nova_unavailable')
    return decorator

So are you saying its never trapping the error and somehow isn't even rendering the permission_denied template?

review: Needs Fixing
lp:~jakedahn/horizon/lp760239 updated
35. By Jake Dahn

removing redirect from images view, as it is handled by the @handle_nova_error decorator

Revision history for this message
Jake Dahn (jakedahn) wrote :

Oops, jakefail - was running server from another branch while writing code in this branch - hence the mismatch in expected behavior.

I've removed the redirect and everything works as expected.

review: Needs Resubmitting
Revision history for this message
Devin Carlen (devcamcar) wrote :

cool, lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'django-nova/src/django_nova/views/images.py'
2--- django-nova/src/django_nova/views/images.py 2011-04-13 19:05:52 +0000
3+++ django-nova/src/django_nova/views/images.py 2011-04-22 03:30:51 +0000
4@@ -88,6 +88,8 @@
5 except exceptions.NovaApiError, e:
6 messages.error(request,
7 'Unable to launch: %s' % e.message)
8+ except exceptions.NovaUnauthorizedError, e:
9+ messages.error(request, 'Permission Denied')
10 else:
11 for instance in reservation.instances:
12 messages.success(request,
13
14=== modified file 'openstack-dashboard/dashboard/templates/permission_denied.html'
15--- openstack-dashboard/dashboard/templates/permission_denied.html 2011-01-12 21:43:31 +0000
16+++ openstack-dashboard/dashboard/templates/permission_denied.html 2011-04-22 03:30:51 +0000
17@@ -1,11 +1,26 @@
18-{% extends "dashboard/base.html" %}
19+{% extends "base.html" %}
20
21 {% block title %} - Permission Denied{% endblock %}
22-{% block pageclass %}denied{% endblock %}
23
24 {% block content %}
25- <div id="page_head">
26- <h2 id="page_heading">Permission Denied</h2>
27- <p id="page_description">You do not have permission to view the requested page.</p>
28+ <div id="right_content">
29+ <div id="page_head">
30+ <h2 id="page_heading">Permission Denied</h2>
31+ <p id="page_description">You do not have permission to view the requested page.</p>
32+ </div>
33 </div>
34 {% endblock %}
35+
36+{% block sidebar %}
37+ <div id="sidebar">
38+ <ul id="navigation">
39+ {% block nav_home %}
40+ <li><h3><a href="/">Home</a></h3></li>
41+ {% endblock %}
42+
43+ {% block nav_projects %}
44+ <li><h3><a href="/">Projects</a></h3></li>
45+ {% endblock %}
46+ </ul>
47+ </div> <!-- end sidebar -->
48+{% endblock %}

Subscribers

People subscribed via source and target branches