Skip to content

Commit

Permalink
bug 1310210: Implement Required Signoffs tables (mozilla-releng#208).…
Browse files Browse the repository at this point in the history
… r=nthomas,jlorenzo
  • Loading branch information
bhearsum authored Jan 20, 2017
1 parent 9f8de88 commit 8990958
Show file tree
Hide file tree
Showing 10 changed files with 1,373 additions and 294 deletions.
8 changes: 7 additions & 1 deletion auslib/admin/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

from auslib.global_state import dbo
from auslib.util.timesince import timesince
from auslib.db import OutdatedDataError, PermissionDeniedError, UpdateMergeError, ChangeScheduledError
from auslib.db import OutdatedDataError, PermissionDeniedError, UpdateMergeError, ChangeScheduledError, \
SignoffRequiredError
import logging


Expand Down Expand Up @@ -41,6 +42,11 @@ def decorated(*args, **kwargs):
logging.warning("Bad input: %s", msg)
logging.warning(e)
return Response(status=400, response=json.dumps({"exception": msg}), mimetype="application/json")
except SignoffRequiredError as e:
msg = "This change requires signoff, it cannot be done directly."
logging.warning(msg)
logging.warning(e)
return Response(status=400, response=json.dumps({"exception": msg}), mimetype="application/json")
except PermissionDeniedError as e:
msg = "Permission denied to perform the request. {}".format(e.message)
logging.warning(msg)
Expand Down
371 changes: 324 additions & 47 deletions auslib/db.py

Large diffs are not rendered by default.

201 changes: 201 additions & 0 deletions auslib/migrate/versions/021_add_required_signoffs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
from sqlalchemy import Table, Column, Integer, String, MetaData, \
BigInteger, Boolean


def upgrade(migrate_engine):
metadata = MetaData(bind=migrate_engine)
if migrate_engine.name == "mysql":
bigintType = BigInteger
elif migrate_engine.name == "sqlite":
bigintType = Integer

product_required_signoffs = Table( # noqa
"product_req_signoffs", metadata,
Column("product", String(15), primary_key=True),
Column("channel", String(75), primary_key=True),
Column("role", String(50), primary_key=True),
Column("signoffs_required", Integer, nullable=False),
Column("data_version", Integer, nullable=False),
)

product_required_signoffs_history = Table(
"product_req_signoffs_history", metadata,
Column("change_id", Integer, primary_key=True, autoincrement=True),
Column("changed_by", String(100), nullable=False),
Column("product", String(15), nullable=False),
Column("channel", String(75), nullable=False),
Column("role", String(50), nullable=False),
Column("signoffs_required", Integer),
Column("data_version", Integer),
)
product_required_signoffs_history.append_column(Column("timestamp", bigintType, nullable=False))

product_required_signoffs_scheduled_changes = Table( # noqa
"product_req_signoffs_scheduled_changes", metadata,
Column("sc_id", Integer, primary_key=True, autoincrement=True),
Column("scheduled_by", String(100), nullable=False),
Column("complete", Boolean, default=False),
Column("change_type", String(50), nullable=False),
Column("data_version", Integer, nullable=False),
Column("base_product", String(15), nullable=False),
Column("base_channel", String(75), nullable=False),
Column("base_role", String(50), nullable=False),
Column("base_signoffs_required", Integer),
Column("base_data_version", Integer),
)

product_required_signoffs_scheduled_changes_history = Table(
"product_req_signoffs_scheduled_changes_history", metadata,
Column("change_id", Integer, primary_key=True, autoincrement=True),
Column("changed_by", String(100), nullable=False),
Column("sc_id", Integer, nullable=False, autoincrement=True),
Column("scheduled_by", String(100)),
Column("complete", Boolean, default=False),
Column("change_type", String(50)),
Column("data_version", Integer),
Column("base_product", String(15)),
Column("base_channel", String(75)),
Column("base_role", String(50)),
Column("base_signoffs_required", Integer),
Column("base_data_version", Integer),
)
product_required_signoffs_scheduled_changes_history.append_column(Column("timestamp", bigintType, nullable=False))

product_required_signoffs_scheduled_changes_conditions = Table(
"product_req_signoffs_scheduled_changes_conditions", metadata,
Column("sc_id", Integer, primary_key=True, autoincrement=True),
Column("data_version", Integer),
)
product_required_signoffs_scheduled_changes_conditions.append_column(Column("when", bigintType))

product_required_signoffs_scheduled_changes_conditions_history = Table(
"product_req_signoffs_scheduled_changes_conditions_history", metadata,
Column("change_id", Integer, primary_key=True, autoincrement=True),
Column("changed_by", String(100), nullable=False),
Column("sc_id", Integer, nullable=False),
Column("data_version", Integer),
)
product_required_signoffs_scheduled_changes_conditions_history.append_column(Column("timestamp", bigintType, nullable=False))
product_required_signoffs_scheduled_changes_conditions_history.append_column(Column("when", bigintType))

product_required_signoffs_scheduled_changes_signoffs = Table( # noqa
"product_req_signoffs_scheduled_changes_signoffs", metadata,
Column("sc_id", Integer, primary_key=True, autoincrement=False),
Column("username", String(100), primary_key=True),
Column("role", String(50), nullable=False),
)

product_required_signoffs_scheduled_changes_signoffs_history = Table( # noqa
"product_req_signoffs_scheduled_changes_signoffs_history", metadata,
Column("change_id", Integer, primary_key=True, autoincrement=True),
Column("changed_by", String(100), nullable=False),
Column("sc_id", Integer, nullable=False, autoincrement=False),
Column("username", String(100), nullable=False),
Column("role", String(50)),
)
product_required_signoffs_scheduled_changes_signoffs_history.append_column(Column("timestamp", bigintType, nullable=False))

permissions_signoffs = Table( # noqa
"permissions_req_signoffs", metadata,
Column("product", String(15), primary_key=True),
Column("role", String(50), primary_key=True),
Column("signoffs_required", Integer, nullable=False),
Column("data_version", Integer, nullable=False),
)

permissions_signoffs_history = Table(
"permissions_req_signoffs_history", metadata,
Column("change_id", Integer, primary_key=True, autoincrement=True),
Column("changed_by", String(100), nullable=False),
Column("product", String(15), nullable=False),
Column("role", String(50), nullable=False),
Column("signoffs_required", Integer),
Column("data_version", Integer),
)
permissions_signoffs_history.append_column(Column("timestamp", bigintType, nullable=False))

permissions_signoffs_scheduled_changes = Table( # noqa
"permissions_req_signoffs_scheduled_changes", metadata,
Column("sc_id", Integer, primary_key=True, autoincrement=True),
Column("scheduled_by", String(100), nullable=False),
Column("complete", Boolean, default=False),
Column("change_type", String(50), nullable=False),
Column("data_version", Integer, nullable=False),
Column("base_product", String(15), nullable=False),
Column("base_role", String(50), nullable=False),
Column("base_signoffs_required", Integer),
Column("base_data_version", Integer),
)

permissions_signoffs_scheduled_changes_history = Table(
"permissions_req_signoffs_scheduled_changes_history", metadata,
Column("change_id", Integer, primary_key=True, autoincrement=True),
Column("changed_by", String(100), nullable=False),
Column("sc_id", Integer, nullable=False, autoincrement=True),
Column("scheduled_by", String(100)),
Column("complete", Boolean, default=False),
Column("change_type", String(50)),
Column("data_version", Integer),
Column("base_product", String(15)),
Column("base_role", String(50)),
Column("base_signoffs_required", Integer),
Column("base_data_version", Integer),
)
permissions_signoffs_scheduled_changes_history.append_column(Column("timestamp", bigintType, nullable=False))

permissions_signoffs_scheduled_changes_conditions = Table(
"permissions_req_signoffs_scheduled_changes_conditions", metadata,
Column("sc_id", Integer, primary_key=True, autoincrement=True),
Column("data_version", Integer),
)
permissions_signoffs_scheduled_changes_conditions.append_column(Column("when", bigintType))

permissions_signoffs_scheduled_changes_conditions_history = Table(
"permissions_req_signoffs_scheduled_changes_conditions_history", metadata,
Column("change_id", Integer, primary_key=True, autoincrement=True),
Column("changed_by", String(100), nullable=False),
Column("sc_id", Integer, nullable=False),
Column("data_version", Integer),
)
permissions_signoffs_scheduled_changes_conditions_history.append_column(Column("timestamp", bigintType, nullable=False))
permissions_signoffs_scheduled_changes_conditions_history.append_column(Column("when", bigintType))

permissions_signoffs_scheduled_changes_signoffs = Table( # noqa
"permissions_req_signoffs_scheduled_changes_signoffs", metadata,
Column("sc_id", Integer, primary_key=True, autoincrement=False),
Column("username", String(100), primary_key=True),
Column("role", String(50), nullable=False),
)

permissions_signoffs_scheduled_changes_signoffs_history = Table( # noqa
"permissions_req_signoffs_scheduled_changes_signoffs_history", metadata,
Column("change_id", Integer, primary_key=True, autoincrement=True),
Column("changed_by", String(100), nullable=False),
Column("sc_id", Integer, nullable=False, autoincrement=False),
Column("username", String(100), nullable=False),
Column("role", String(50)),
)
permissions_signoffs_scheduled_changes_signoffs_history.append_column(Column("timestamp", bigintType, nullable=False))

metadata.create_all()


def downgrade(migrate_engine):
metadata = MetaData(bind=migrate_engine)

Table("product_req_signoffs", metadata, autoload=True).drop()
Table("product_req_signoffs_history", metadata, autoload=True).drop()
Table("product_req_signoffs_scheduled_changes", metadata, autoload=True).drop()
Table("product_req_signoffs_scheduled_changes_history", metadata, autoload=True).drop()
Table("product_req_signoffs_scheduled_changes_conditions", metadata, autoload=True).drop()
Table("product_req_signoffs_scheduled_changes_conditions_history", metadata, autoload=True).drop()
Table("product_req_signoffs_scheduled_changes_signoffs", metadata, autoload=True).drop()
Table("product_req_signoffs_scheduled_changes_signoffs_history", metadata, autoload=True).drop()
Table("permissions_req_signoffs", metadata, autoload=True).drop()
Table("permissions_req_signoffs_history", metadata, autoload=True).drop()
Table("permissions_req_signoffs_scheduled_changes", metadata, autoload=True).drop()
Table("permissions_req_signoffs_scheduled_changes_history", metadata, autoload=True).drop()
Table("permissions_req_signoffs_scheduled_changes_conditions", metadata, autoload=True).drop()
Table("permissions_req_signoffs_scheduled_changes_conditions_history", metadata, autoload=True).drop()
Table("permissions_req_signoffs_scheduled_changes_signoffs", metadata, autoload=True).drop()
Table("permissions_req_signoffs_scheduled_changes_signoffs_history", metadata, autoload=True).drop()
24 changes: 16 additions & 8 deletions auslib/test/admin/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def setUp(self):
dbo.permissions.t.insert().execute(permission='admin', username='bill', data_version=1)
dbo.permissions.t.insert().execute(permission='permission', username='bob', data_version=1)
dbo.permissions.t.insert().execute(permission='release', username='bob',
options=dict(products=['fake', 'b'], actions=["create", "modify"]), data_version=1)
dbo.permissions.t.insert().execute(permission='release_read_only', username='bob', options=dict(actions=["set"]), data_version=1)
dbo.permissions.t.insert().execute(permission='rule', username='bob', options=dict(actions=["modify"], products=['fake']), data_version=1)
options=dict(products=['fake', "a", 'b'], actions=["create", "modify"]), data_version=1)
dbo.permissions.t.insert().execute(permission='release_read_only', username='bob', options=dict(actions=["set"], products=["a", "b"]), data_version=1)
dbo.permissions.t.insert().execute(permission='rule', username='bob', options=dict(actions=["modify"], products=['a', "b"]), data_version=1)
dbo.permissions.t.insert().execute(permission='build', username='ashanti', options=dict(actions=["modify"], products=['a']), data_version=1)
dbo.permissions.t.insert().execute(permission="scheduled_change", username="mary", options=dict(actions=["enact"]), data_version=1)
dbo.permissions.t.insert().execute(permission='release_locale', username='ashanti',
Expand All @@ -47,6 +47,10 @@ def setUp(self):
dbo.permissions.user_roles.t.insert().execute(username="bill", role="releng", data_version=1)
dbo.permissions.user_roles.t.insert().execute(username="bill", role="qa", data_version=1)
dbo.permissions.user_roles.t.insert().execute(username="bob", role="relman", data_version=1)
dbo.permissions.user_roles.t.insert().execute(username="mary", role="relman", data_version=1)
dbo.productRequiredSignoffs.t.insert().execute(product="fake", channel="a", role="releng", signoffs_required=1, data_version=1)
dbo.permissionsRequiredSignoffs.t.insert().execute(product="fake", role="releng", signoffs_required=1, data_version=1)
dbo.permissionsRequiredSignoffs.t.insert().execute(product="superfake", role="relman", signoffs_required=1, data_version=1)
dbo.releases.t.insert().execute(
name='a', product='a', data=createBlob(dict(name='a', hashFunction="sha512", schema_version=1)), data_version=1)
dbo.releases.t.insert().execute(
Expand Down Expand Up @@ -76,20 +80,24 @@ def setUp(self):
}
"""))
dbo.rules.t.insert().execute(
rule_id=1, priority=100, version='3.5', buildTarget='d', backgroundRate=100, mapping='c', update_type='minor', data_version=1
rule_id=1, priority=100, version='3.5', buildTarget='d', backgroundRate=100, mapping='c', update_type='minor',
product="a", channel="a", data_version=1
)
dbo.rules.t.insert().execute(
rule_id=2, alias="frodo", priority=100, version='3.3', buildTarget='d', backgroundRate=100, mapping='b', update_type='minor',
data_version=1
product="a", channel="a", data_version=1
)
dbo.rules.t.insert().execute(
rule_id=3, product='a', priority=100, version='3.5', buildTarget='a', backgroundRate=100, mapping='a', update_type='minor', data_version=1
rule_id=3, product='a', priority=100, version='3.5', buildTarget='a', backgroundRate=100, mapping='a', update_type='minor',
channel="a", data_version=1
)
dbo.rules.t.insert().execute(
rule_id=4, product='fake', priority=80, buildTarget='d', backgroundRate=100, mapping='a', update_type='minor', data_version=1
rule_id=4, product='fake', priority=80, buildTarget='d', backgroundRate=100, mapping='a', update_type='minor', channel="a",
data_version=1
)
dbo.rules.t.insert().execute(
rule_id=5, priority=80, buildTarget='d', version='3.3', backgroundRate=0, mapping='c', update_type='minor', data_version=1
rule_id=5, priority=80, buildTarget='d', version='3.3', backgroundRate=0, mapping='c', update_type='minor',
product="a", channel="a", data_version=1
)
self.client = app.test_client()

Expand Down
6 changes: 3 additions & 3 deletions auslib/test/admin/views/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def testFieldViewCheckIntegerValue(self):
self.assertStatusCode(ret, 200)

def testFieldViewBadValuesBadField(self):
ret = self._put('/users/bob/permissions/admin')
ret = self._put('/users/bob/permissions/admin', data=dict(options=json.dumps(dict(products=["a"]))))
self.assertStatusCode(ret, 201)

table = dbo.permissions.history
Expand Down Expand Up @@ -177,7 +177,7 @@ def testFieldViewDiffRelease(self):

def testFieldViewPermission(self):
# Add a permission
ret = self._put('/users/bob/permissions/admin')
ret = self._put('/users/bob/permissions/admin', data=dict(options=json.dumps(dict(products=["a"]))))
self.assertStatusCode(ret, 201)
table = dbo.permissions.history
row, = table.select(order_by=[table.timestamp.desc()], limit=1)
Expand All @@ -186,4 +186,4 @@ def testFieldViewPermission(self):
url = '/history/view/permission/%d/options' % change_id
ret = self.client.get(url)
self.assertStatusCode(ret, 200)
self.assertEqual(ret.data, 'NULL')
self.assertEqual(json.loads(ret.data), {"products": ["a"]})
Loading

0 comments on commit 8990958

Please sign in to comment.