Skip to content

Commit

Permalink
Move service redirects out into their own module to reduce clutter.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Sep 15, 2015
1 parent 1db0435 commit 482a0f8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 65 deletions.
10 changes: 1 addition & 9 deletions bodhi/services/comments.py
Expand Up @@ -15,7 +15,7 @@
import math

from cornice import Service
from pyramid.httpexceptions import HTTPBadRequest, HTTPFound
from pyramid.httpexceptions import HTTPBadRequest
from sqlalchemy import func, distinct
from sqlalchemy.sql import or_

Expand Down Expand Up @@ -188,11 +188,3 @@ def new_comment(request):
return

return dict(comment=comment, caveats=caveats)


@comments.get(accept=('application/atom+xml',))
def rss_redirect(request):
url = request.route_url('comments_rss')
if request.query_string:
url = url + '?' + request.query_string
raise HTTPFound(url)
9 changes: 0 additions & 9 deletions bodhi/services/overrides.py
Expand Up @@ -16,7 +16,6 @@

from cornice import Service
from pyramid.exceptions import HTTPNotFound
from pyramid.httpexceptions import HTTPFound

from sqlalchemy import func, distinct
from sqlalchemy.sql import or_
Expand Down Expand Up @@ -237,11 +236,3 @@ def save_override(request):
result['caveats'] = caveats

return result


@overrides.get(accept=('application/atom+xml',))
def rss_redirect(request):
url = request.route_url('overrides_rss')
if request.query_string:
url = url + '?' + request.query_string
raise HTTPFound(url)
38 changes: 0 additions & 38 deletions bodhi/services/updates.py
Expand Up @@ -19,9 +19,6 @@
from sqlalchemy import func, distinct
from sqlalchemy.sql import or_

from pyramid.httpexceptions import exception_response
from pyramid.httpexceptions import HTTPFound

from bodhi import log
from bodhi.exceptions import BodhiException, LockedUpdateException
from bodhi.models import Update, Build, Bug, CVE, Package, UpdateRequest
Expand Down Expand Up @@ -71,13 +68,6 @@
acl=bodhi.security.packagers_allowed_acl,
cors_origins=bodhi.security.cors_origins_rw)

zz_update_old = Service(name='update_old', path='/updates/{id}/{title}',
validators=(validate_update_id,),
description='Update submission service',
#acl=bodhi.security.package_maintainers_only_acl,
acl=bodhi.security.packagers_allowed_acl,
cors_origins=bodhi.security.cors_origins_rw)

@update.get(accept=('application/json', 'text/json'), renderer='json',
error_handler=bodhi.services.errors.json_handler)
@update.get(accept=('application/javascript'), renderer='jsonp',
Expand All @@ -95,16 +85,6 @@ def get_update(request):
return dict(update=request.validated['update'], can_edit=can_edit)


@zz_update_old.get(accept=('application/json', 'text/json'), renderer='json',
error_handler=bodhi.services.errors.json_handler)
@zz_update_old.get(accept=('application/javascript'), renderer='jsonp',
error_handler=bodhi.services.errors.jsonp_handler)
@zz_update_old.get(accept="text/html", renderer="update.html",
error_handler=bodhi.services.errors.html_handler)
def get_update_old(request):
return HTTPFound("/updates/{0}".format(request.matchdict['id']))


@update_edit.get(accept="text/html", renderer="new_update.html",
error_handler=bodhi.services.errors.html_handler)
def get_update_for_editing(request):
Expand All @@ -117,16 +97,6 @@ def get_update_for_editing(request):
)


@update_request.get(accept=('application/json', 'text/json'), renderer='json',
error_handler=bodhi.services.errors.json_handler)
@update_request.get(accept=('application/javascript'), renderer='jsonp',
error_handler=bodhi.services.errors.jsonp_handler)
@update_request.get(accept="text/html", renderer="update.html",
error_handler=bodhi.services.errors.html_handler)
def update_request_get(request):
raise exception_response(405)


@update_request.post(schema=bodhi.schemas.UpdateRequestSchema,
validators=(
validate_enums,
Expand Down Expand Up @@ -435,11 +405,3 @@ def new_update(request):
result['caveats'] = caveats

return result


@updates.get(accept=('application/atom+xml',))
def rss_redirect(request):
url = request.route_url('updates_rss')
if request.query_string:
url = url + '?' + request.query_string
raise HTTPFound(url)
9 changes: 0 additions & 9 deletions bodhi/services/user.py
Expand Up @@ -14,7 +14,6 @@

from cornice import Service
from pyramid.exceptions import HTTPNotFound
from pyramid.httpexceptions import HTTPFound
from sqlalchemy import func, distinct
from sqlalchemy.sql import or_

Expand Down Expand Up @@ -153,11 +152,3 @@ def query_users(request):
rows_per_page=rows_per_page,
total=total,
)


@users.get(accept=('application/atom+xml',))
def rss_redirect(request):
url = request.route_url('users_rss')
if request.query_string:
url = url + '?' + request.query_string
raise HTTPFound(url)
69 changes: 69 additions & 0 deletions bodhi/services/zz_redirects.py
@@ -0,0 +1,69 @@
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
""" Handle general redirect stuff.
This module name gets a 'zz_' tacked on the front so that it comes last.
We need to catch /updates/{id}/request and /updates/{id}/edit first and those
get defined in the other service modules.
"""

from cornice import Service

from pyramid.httpexceptions import HTTPFound

import bodhi.security

from bodhi.services.comments import comments
from bodhi.services.overrides import overrides
from bodhi.services.updates import updates
from bodhi.services.user import users


def redirect_maker(target):
def redirector(request):
url = request.route_url('updates_rss')
if request.query_string:
url = url + '?' + request.query_string
raise HTTPFound(url)
return redirector


@comments.get(accept=('application/atom+xml',))
def comments_rss_redirect(request):
return redirect_maker('comments_rss')(request)


@overrides.get(accept=('application/atom+xml',))
def overrides_rss_redirect(request):
return redirect_maker('overrides_rss')(request)


@updates.get(accept=('application/atom+xml',))
def updates_rss_redirect(request):
return redirect_maker('updates_rss')(request)


@users.get(accept=('application/atom+xml',))
def users_rss_redirect(request):
return redirect_maker('users_rss')(request)


zz_bodhi1_update_redirect = Service(
name='bodhi1_update_redirect', path='/updates/{id}/{title}',
description='Redirect to old updates/ALIAS/TITLE urls',
cors_origins=bodhi.security.cors_origins_rw)

@zz_bodhi1_update_redirect.get()
def zz_get_bodhi1_update_redirect(request):
return HTTPFound("/updates/{0}".format(request.matchdict['id']))

0 comments on commit 482a0f8

Please sign in to comment.