Skip to content

Commit

Permalink
bug 1246675: implement core functionality needed for Scheduled Change…
Browse files Browse the repository at this point in the history
…s. r=nthomas
  • Loading branch information
bhearsum committed Aug 15, 2016
1 parent 6ae366e commit cffc810
Show file tree
Hide file tree
Showing 11 changed files with 1,055 additions and 294 deletions.
1 change: 0 additions & 1 deletion auslib/admin/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def add_security_headers(response):
app.add_url_rule("/users", view_func=UsersView.as_view("users"))
app.add_url_rule("/users/<username>/permissions", view_func=PermissionsView.as_view("user_permissions"))
app.add_url_rule("/users/<username>/permissions/<permission>", view_func=SpecificPermissionView.as_view("specific_permission"))
app.add_url_rule("/users/<username>/permissions//<path:permission>", view_func=SpecificPermissionView.as_view("specific_permission2"))
app.add_url_rule("/rules", view_func=RulesAPIView.as_view("rules"))
# Normal operations (get/update/delete) on rules can be done by id or alias...
app.add_url_rule("/rules/<id_or_alias>", view_func=SingleRuleView.as_view("rule"))
Expand Down
21 changes: 7 additions & 14 deletions auslib/admin/views/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@
__all__ = ["UsersView", "PermissionsView", "SpecificPermissionView"]


def setpermission(f):
def decorated(*args, **kwargs):
if kwargs['permission'] not in ('admin', 'release', 'release_locale', 'release_read_only', 'rule', 'permission') \
and not kwargs['permission'].startswith('/'):
kwargs['permission'] = '/%s' % kwargs['permission']
return f(*args, **kwargs)
return decorated


class UsersView(AdminView):
"""/users"""

Expand Down Expand Up @@ -54,15 +45,16 @@ def _put(self, username, permission, changed_by, transaction):
if not form.validate():
self.log.warning("Bad input: %s", form.errors)
return Response(status=400, response=json.dumps(form.errors))
dbo.permissions.updatePermission(changed_by, username, permission, form.data_version.data, form.options.data, transaction=transaction)
dbo.permissions.update(where={"username": username, "permission": permission}, what={"options": form.options.data},
changed_by=changed_by, old_data_version=form.data_version.data, transaction=transaction)
new_data_version = dbo.permissions.getPermission(username=username, permission=permission, transaction=transaction)['data_version']
return make_response(json.dumps(dict(new_data_version=new_data_version)), 200)
else:
form = NewPermissionForm()
if not form.validate():
self.log.warning("Bad input: %s", form.errors)
return Response(status=400, response=json.dumps(form.errors))
dbo.permissions.grantPermission(changed_by, username, permission, form.options.data, transaction=transaction)
dbo.permissions.insert(changed_by, transaction=transaction, username=username, permission=permission, options=form.options.data)
return make_response(json.dumps(dict(new_data_version=1)), 201)
except ValueError as e:
self.log.warning("Bad input: %s", e.args)
Expand All @@ -77,14 +69,14 @@ def _post(self, username, permission, changed_by, transaction):
if not form.validate():
self.log.warning("Bad input: %s", form.errors)
return Response(status=400, response=json.dumps(form.errors))
dbo.permissions.updatePermission(changed_by, username, permission, form.data_version.data, form.options.data, transaction=transaction)
dbo.permissions.update(where={"username": username, "permission": permission}, what={"options": form.options.data},
changed_by=changed_by, old_data_version=form.data_version.data, transaction=transaction)
new_data_version = dbo.permissions.getPermission(username=username, permission=permission, transaction=transaction)['data_version']
return make_response(json.dumps(dict(new_data_version=new_data_version)), 200)
except ValueError as e:
self.log.warning("Bad input: %s", e.args)
return Response(status=400, response=e.args)

@setpermission
@requirelogin
def _delete(self, username, permission, changed_by, transaction):
if not dbo.permissions.getUserPermissions(username, transaction=transaction).get(permission):
Expand All @@ -97,7 +89,8 @@ def _delete(self, username, permission, changed_by, transaction):
if not form.validate():
self.log.warning("Bad input: %s", form.errors)
return Response(status=400, response=json.dumps(form.errors))
dbo.permissions.revokePermission(changed_by, username, permission, form.data_version.data, transaction=transaction)
dbo.permissions.delete(where={"username": username, "permission": permission}, changed_by=changed_by,
old_data_version=form.data_version.data, transaction=transaction)
return Response(status=200)
except ValueError as e:
self.log.warning("Bad input: %s", e.args)
Expand Down
43 changes: 20 additions & 23 deletions auslib/admin/views/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

def createRelease(release, product, changed_by, transaction, releaseData):
blob = createBlob(json.dumps(releaseData))
dbo.releases.addRelease(name=release, product=product,
blob=blob, changed_by=changed_by, transaction=transaction)
dbo.releases.insert(changed_by=changed_by, transaction=transaction, name=release,
product=product, data=blob)
return dbo.releases.getReleases(name=release, transaction=transaction)[0]


Expand Down Expand Up @@ -233,9 +233,8 @@ def _put(self, release, changed_by, transaction):
if dbo.releases.getReleases(name=release, limit=1):
data_version = form.data_version.data
try:
dbo.releases.updateRelease(name=release, blob=blob,
product=form.product.data, changed_by=changed_by,
old_data_version=data_version, transaction=transaction)
dbo.releases.update(where={"name": release}, what={"data": blob, "product": form.product.data}, changed_by=changed_by,
old_data_version=data_version, transaction=transaction)
except BlobValidationError as e:
msg = "Couldn't update release: %s" % e
self.log.warning("Bad input: %s", msg)
Expand All @@ -254,9 +253,8 @@ def _put(self, release, changed_by, transaction):
return Response(json.dumps(dict(new_data_version=data_version)), status=200)
else:
try:
dbo.releases.addRelease(name=release, product=form.product.data,
blob=blob,
changed_by=changed_by, transaction=transaction)
dbo.releases.insert(changed_by=changed_by, transaction=transaction, name=release,
product=form.product.data, data=blob)
except BlobValidationError as e:
msg = "Couldn't update release: %s" % e
self.log.warning("Bad input: %s", msg)
Expand All @@ -277,9 +275,9 @@ def exists(rel, product):
def commit(rel, product, newReleaseData, releaseData, old_data_version, extraArgs):
releaseData.update(newReleaseData)
blob = createBlob(releaseData)
return dbo.releases.updateRelease(name=rel, blob=blob, product=product,
changed_by=changed_by, old_data_version=old_data_version,
transaction=transaction)
return dbo.releases.update(where={"name": rel}, what={"data": blob, "product": product},
changed_by=changed_by, old_data_version=old_data_version,
transaction=transaction)

return changeRelease(release, changed_by, transaction, exists, commit, self.log)

Expand All @@ -302,8 +300,8 @@ def _delete(self, release, changed_by, transaction):
return Response(status=400, response=json.dumps(form.errors))

try:
dbo.releases.deleteRelease(changed_by=changed_by, name=release['name'],
old_data_version=form.data_version.data, transaction=transaction)
dbo.releases.delete(where={"name": release["name"]}, changed_by=changed_by, old_data_version=form.data_version.data,
transaction=transaction)
except ReadOnlyError as e:
msg = "Couldn't delete release: %s" % e
self.log.warning("Bad input: %s", msg)
Expand Down Expand Up @@ -337,10 +335,12 @@ def _put(self, release, changed_by, transaction):

if form.read_only.data:
if not is_release_read_only:
dbo.releases.updateRelease(release, changed_by, data_version, read_only=True, transaction=transaction)
dbo.releases.update(where={"name": release}, what={"read_only": True}, changed_by=changed_by, old_data_version=data_version,
transaction=transaction)
data_version += 1
else:
dbo.releases.updateRelease(release, changed_by, data_version, read_only=False, transaction=transaction)
dbo.releases.update(where={"name": release}, what={"read_only": False}, changed_by=changed_by, old_data_version=data_version,
transaction=transaction)
data_version += 1
return Response(status=201, response=json.dumps(dict(new_data_version=data_version)))

Expand Down Expand Up @@ -410,9 +410,8 @@ def _post(self, release, transaction, changed_by):
blob = createBlob(change['data'])

try:
dbo.releases.updateRelease(changed_by=changed_by, name=change['name'],
blob=blob, product=change['product'],
old_data_version=old_data_version, transaction=transaction)
dbo.releases.update(where={"name": change["name"]}, what={"data": blob, "product": change["product"]}, changed_by=changed_by,
old_data_version=old_data_version, transaction=transaction)
except BlobValidationError as e:
self.log.warning("Bad input: %s", e.args)
return Response(status=400, response=json.dumps({"data": e.errors}))
Expand Down Expand Up @@ -470,11 +469,9 @@ def _post(self, changed_by, transaction):

try:
blob = createBlob(form.blob.data)
name = dbo.releases.addRelease(
name=form.name.data, product=form.product.data,
blob=blob,
changed_by=changed_by, transaction=transaction
)
name = dbo.releases.insert(changed_by=changed_by, transaction=transaction,
name=form.name.data, product=form.product.data,
data=blob)
except BlobValidationError as e:
msg = "Couldn't update release: %s" % e
self.log.warning("Bad input: %s", msg)
Expand Down
15 changes: 7 additions & 8 deletions auslib/admin/views/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ def _post(self, transaction, changed_by):
comment=form.comment.data,
update_type=form.update_type.data,
headerArchitecture=form.headerArchitecture.data)
rule_id = dbo.rules.addRule(changed_by=changed_by, what=what,
transaction=transaction)
rule_id = dbo.rules.insert(changed_by=changed_by, transaction=transaction, **what)
return Response(status=200, response=str(rule_id))


Expand Down Expand Up @@ -119,8 +118,8 @@ def _post(self, id_or_alias, transaction, changed_by):
if (request.json and k in request.json) or k in request.form:
what[k] = v

dbo.rules.updateRule(changed_by=changed_by, id_or_alias=id_or_alias, what=what,
old_data_version=form.data_version.data, transaction=transaction)
dbo.rules.update(changed_by=changed_by, where={"rule_id": id_or_alias}, what=what,
old_data_version=form.data_version.data, transaction=transaction)

# find out what the next data version is
rule = dbo.rules.getRule(id_or_alias, transaction=transaction)
Expand All @@ -145,8 +144,8 @@ def _delete(self, id_or_alias, transaction, changed_by):
# form to make sure that the CSRF token is checked.
form = DbEditableForm(request.args)

dbo.rules.deleteRule(changed_by=changed_by, id_or_alias=id_or_alias,
old_data_version=form.data_version.data, transaction=transaction)
dbo.rules.delete(where={"rule_id": id_or_alias}, changed_by=changed_by, old_data_version=form.data_version.data,
transaction=transaction)

return Response(status=200)

Expand Down Expand Up @@ -263,8 +262,8 @@ def _post(self, rule_id, transaction, changed_by):
headerArchitecture=change['headerArchitecture'],
)

dbo.rules.updateRule(changed_by=changed_by, id_or_alias=rule_id, what=what,
old_data_version=old_data_version, transaction=transaction)
dbo.rules.update(changed_by=changed_by, where={"rule_id": rule_id}, what=what,
old_data_version=old_data_version, transaction=transaction)

return Response("Excellent!")

Expand Down
Loading

1 comment on commit cffc810

@TaskClusterRobot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.