Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #34 from mrrrgn/perms
Browse files Browse the repository at this point in the history
Require a special permission for clobbering.
  • Loading branch information
usize committed Apr 15, 2015
2 parents 5d5399b + 379c64c commit dd50f1e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions relengapi/blueprints/clobberer/__init__.py
Expand Up @@ -27,6 +27,7 @@
from models import DB_DECLARATIVE_BASE

from relengapi import apimethod
from relengapi import p
from relengapi.lib import angular
from relengapi.lib import api

Expand All @@ -39,6 +40,8 @@
static_folder='static'
)

p.clobberer.post.clobber.doc('Submit clobber requests')

bp.root_widget_template('clobberer_root_widget.html', priority=100)

# prefix which denotes release builddirs
Expand Down Expand Up @@ -85,6 +88,7 @@ def _add_clobber(session, branch, builddir, slave=None):

@bp.route('/clobber', methods=['POST'])
@apimethod(None, body=[rest.ClobberRequest])
@p.clobberer.post.clobber.require()
def clobber(body):
"Request clobbers for particular branches and builddirs."
session = g.db.session(DB_DECLARATIVE_BASE)
Expand All @@ -101,6 +105,7 @@ def clobber(body):

@bp.route('/clobber/by-builder', methods=['POST'])
@apimethod(None, body=[rest.ClobberRequestByBuilder])
@p.clobberer.post.clobber.require()
def clobber_by_builder(body):
"""
Request clobbers for app builddirs associated with a particular buildername.
Expand Down
10 changes: 7 additions & 3 deletions relengapi/blueprints/clobberer/test_api.py
Expand Up @@ -9,6 +9,8 @@
from nose.tools import assert_greater
from nose.tools import eq_

from relengapi import p
from relengapi.lib import auth
from relengapi.lib.testing.context import TestContext

from . import BUILDDIR_REL_PREFIX
Expand All @@ -29,7 +31,9 @@
'slave': 'specific_slave',
}

test_context = TestContext(databases=[DB_DECLARATIVE_BASE], reuse_app=True)
auth_user = auth.HumanUser('winter2718@gmail.com')
auth_user._permissions = set([p.clobberer.post.clobber])
test_context = TestContext(databases=[DB_DECLARATIVE_BASE], user=auth_user, reuse_app=True)

_last_clobber_args = deepcopy(_clobber_args)
_last_clobber_args['buildername'] = 'buildername'
Expand All @@ -50,7 +54,7 @@ def test_clobber_request(client):
'No new clobbers were detected, clobber request failed.')


@ test_context
@test_context
def test_lastclobber_all(client):
rv = client.get('/clobberer/lastclobber/all')
eq_(rv.status_code, 200)
Expand Down Expand Up @@ -103,7 +107,7 @@ def test_lastclobber(client):
eq_(lastclobber_data[0], _last_clobber_args['builddir'])
eq_(lastclobber_data[1].isdigit(), True,
'lastclobber did not return a valid timestamp => {}'.format(lastclobber_data[1]))
eq_(lastclobber_data[2], 'anonymous',
eq_(lastclobber_data[2], 'winter2718@gmail.com',
'lastclobber did not return a valid username')

# Ensure a new build has been recorded matching the request args
Expand Down

0 comments on commit dd50f1e

Please sign in to comment.