diff --git a/tailbone/auth.py b/tailbone/auth.py index 05c5515c..1bfc4fb1 100644 --- a/tailbone/auth.py +++ b/tailbone/auth.py @@ -31,14 +31,15 @@ from pyramid.interfaces import IAuthorizationPolicy from pyramid.security import Everyone, Authenticated from .db import Session -from rattail.db.model import User -from rattail.db.auth import has_permission @implementer(IAuthorizationPolicy) class TailboneAuthorizationPolicy(object): def permits(self, context, principals, permission): + from rattail.db.model import User + from rattail.db.auth import has_permission + for userid in principals: if userid not in (Everyone, Authenticated): user = Session.query(User).get(userid) diff --git a/tailbone/db.py b/tailbone/db.py index 7e12f5b2..18afce0b 100644 --- a/tailbone/db.py +++ b/tailbone/db.py @@ -32,7 +32,7 @@ import sqlalchemy_continuum as continuum from sqlalchemy.orm import sessionmaker, scoped_session from rattail.db import SessionBase -from rattail.db import model +from rattail.db.continuum import versioning_manager Session = scoped_session(sessionmaker(class_=SessionBase)) @@ -53,8 +53,7 @@ class TailboneSessionDataManager(datamanager.SessionDataManager): if self.tx is not None: # there may have been no work to do # Force creation of Continuum versions for current session. - mgr = continuum.get_versioning_manager(model.Product) # any ol' model will do - uow = mgr.unit_of_work(self.session) + uow = versioning_manager.unit_of_work(self.session) uow.make_versions(self.session) self.tx.commit() diff --git a/tailbone/templates/brands/crud.mako b/tailbone/templates/brands/crud.mako index dea13003..055dc58f 100644 --- a/tailbone/templates/brands/crud.mako +++ b/tailbone/templates/brands/crud.mako @@ -8,7 +8,7 @@ % elif form.updating:
  • ${h.link_to("View this Brand", url('brand.read', uuid=form.fieldset.model.uuid))}
  • % endif - % if not form.creating and request.has_perm('brand.versions.view'): + % if version_count is not Undefined and request.has_perm('brand.versions.view'):
  • ${h.link_to("View Change History ({0})".format(version_count), url('brand.versions', uuid=form.fieldset.model.uuid))}
  • % endif diff --git a/tailbone/templates/departments/crud.mako b/tailbone/templates/departments/crud.mako index 8d819021..b52d123f 100644 --- a/tailbone/templates/departments/crud.mako +++ b/tailbone/templates/departments/crud.mako @@ -8,7 +8,7 @@ % elif form.updating:
  • ${h.link_to("View this Department", url('department.read', uuid=form.fieldset.model.uuid))}
  • % endif - % if not form.creating and request.has_perm('department.versions.view'): + % if version_count is not Undefined and request.has_perm('department.versions.view'):
  • ${h.link_to("View Change History ({0})".format(version_count), url('department.versions', uuid=form.fieldset.model.uuid))}
  • % endif diff --git a/tailbone/templates/products/crud.mako b/tailbone/templates/products/crud.mako index 68370002..75a0421c 100644 --- a/tailbone/templates/products/crud.mako +++ b/tailbone/templates/products/crud.mako @@ -8,7 +8,7 @@ % elif form.updating:
  • ${h.link_to("View this Product", url('product.read', uuid=form.fieldset.model.uuid))}
  • % endif - % if not form.creating and request.has_perm('product.versions.view'): + % if version_count is not Undefined and request.has_perm('product.versions.view'):
  • ${h.link_to("View Change History ({0})".format(version_count), url('product.versions', uuid=form.fieldset.model.uuid))}
  • % endif diff --git a/tailbone/templates/subdepartments/crud.mako b/tailbone/templates/subdepartments/crud.mako index e64a1b7f..bfc12614 100644 --- a/tailbone/templates/subdepartments/crud.mako +++ b/tailbone/templates/subdepartments/crud.mako @@ -8,7 +8,7 @@ % elif form.updating:
  • ${h.link_to("View this Subdepartment", url('subdepartment.read', uuid=form.fieldset.model.uuid))}
  • % endif - % if not form.creating and request.has_perm('subdepartment.versions.view'): + % if version_count is not Undefined and request.has_perm('subdepartment.versions.view'):
  • ${h.link_to("View Change History ({0})".format(version_count), url('subdepartment.versions', uuid=form.fieldset.model.uuid))}
  • % endif diff --git a/tailbone/templates/vendors/crud.mako b/tailbone/templates/vendors/crud.mako index b3b2fd2a..332fbecf 100644 --- a/tailbone/templates/vendors/crud.mako +++ b/tailbone/templates/vendors/crud.mako @@ -8,7 +8,7 @@ % elif form.updating:
  • ${h.link_to("View this Vendor", url('vendor.read', uuid=form.fieldset.model.uuid))}
  • % endif - % if not form.creating and request.has_perm('vendor.versions.view'): + % if version_count is not Undefined and request.has_perm('vendor.versions.view'):
  • ${h.link_to("View Change History ({0})".format(version_count), url('vendor.versions', uuid=form.fieldset.model.uuid))}
  • % endif diff --git a/tailbone/views/continuum.py b/tailbone/views/continuum.py index d7f0bdb2..3c915f27 100644 --- a/tailbone/views/continuum.py +++ b/tailbone/views/continuum.py @@ -30,7 +30,7 @@ import sqlalchemy as sa import sqlalchemy_continuum as continuum from rattail.db import model -from rattail.db.model.continuum import model_transaction_query +from rattail.db.continuum import model_transaction_query import formalchemy from pyramid.httpexceptions import HTTPNotFound diff --git a/tailbone/views/crud.py b/tailbone/views/crud.py index 924c91de..c54ce13f 100644 --- a/tailbone/views/crud.py +++ b/tailbone/views/crud.py @@ -37,7 +37,7 @@ from sqlalchemy_continuum import transaction_class, version_class from sqlalchemy_continuum.utils import is_versioned from rattail.db import model -from rattail.db.model.continuum import count_versions, model_transaction_query +from rattail.db.continuum import count_versions, model_transaction_query from pyramid.httpexceptions import HTTPFound, HTTPNotFound