Rework versioning support to allow it to be one or off.

Turns out versioning isn't quite ready for prime time, so let's have a
fallback plan shall we?
This commit is contained in:
Lance Edgar 2015-02-10 19:07:46 -06:00
parent bd44d886c4
commit aa70ffc9f0
9 changed files with 12 additions and 12 deletions

View file

@ -31,14 +31,15 @@ from pyramid.interfaces import IAuthorizationPolicy
from pyramid.security import Everyone, Authenticated from pyramid.security import Everyone, Authenticated
from .db import Session from .db import Session
from rattail.db.model import User
from rattail.db.auth import has_permission
@implementer(IAuthorizationPolicy) @implementer(IAuthorizationPolicy)
class TailboneAuthorizationPolicy(object): class TailboneAuthorizationPolicy(object):
def permits(self, context, principals, permission): def permits(self, context, principals, permission):
from rattail.db.model import User
from rattail.db.auth import has_permission
for userid in principals: for userid in principals:
if userid not in (Everyone, Authenticated): if userid not in (Everyone, Authenticated):
user = Session.query(User).get(userid) user = Session.query(User).get(userid)

View file

@ -32,7 +32,7 @@ import sqlalchemy_continuum as continuum
from sqlalchemy.orm import sessionmaker, scoped_session from sqlalchemy.orm import sessionmaker, scoped_session
from rattail.db import SessionBase from rattail.db import SessionBase
from rattail.db import model from rattail.db.continuum import versioning_manager
Session = scoped_session(sessionmaker(class_=SessionBase)) 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 if self.tx is not None: # there may have been no work to do
# Force creation of Continuum versions for current session. # Force creation of Continuum versions for current session.
mgr = continuum.get_versioning_manager(model.Product) # any ol' model will do uow = versioning_manager.unit_of_work(self.session)
uow = mgr.unit_of_work(self.session)
uow.make_versions(self.session) uow.make_versions(self.session)
self.tx.commit() self.tx.commit()

View file

@ -8,7 +8,7 @@
% elif form.updating: % elif form.updating:
<li>${h.link_to("View this Brand", url('brand.read', uuid=form.fieldset.model.uuid))}</li> <li>${h.link_to("View this Brand", url('brand.read', uuid=form.fieldset.model.uuid))}</li>
% endif % 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'):
<li>${h.link_to("View Change History ({0})".format(version_count), url('brand.versions', uuid=form.fieldset.model.uuid))}</li> <li>${h.link_to("View Change History ({0})".format(version_count), url('brand.versions', uuid=form.fieldset.model.uuid))}</li>
% endif % endif
</%def> </%def>

View file

@ -8,7 +8,7 @@
% elif form.updating: % elif form.updating:
<li>${h.link_to("View this Department", url('department.read', uuid=form.fieldset.model.uuid))}</li> <li>${h.link_to("View this Department", url('department.read', uuid=form.fieldset.model.uuid))}</li>
% endif % 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'):
<li>${h.link_to("View Change History ({0})".format(version_count), url('department.versions', uuid=form.fieldset.model.uuid))}</li> <li>${h.link_to("View Change History ({0})".format(version_count), url('department.versions', uuid=form.fieldset.model.uuid))}</li>
% endif % endif
</%def> </%def>

View file

@ -8,7 +8,7 @@
% elif form.updating: % elif form.updating:
<li>${h.link_to("View this Product", url('product.read', uuid=form.fieldset.model.uuid))}</li> <li>${h.link_to("View this Product", url('product.read', uuid=form.fieldset.model.uuid))}</li>
% endif % 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'):
<li>${h.link_to("View Change History ({0})".format(version_count), url('product.versions', uuid=form.fieldset.model.uuid))}</li> <li>${h.link_to("View Change History ({0})".format(version_count), url('product.versions', uuid=form.fieldset.model.uuid))}</li>
% endif % endif
</%def> </%def>

View file

@ -8,7 +8,7 @@
% elif form.updating: % elif form.updating:
<li>${h.link_to("View this Subdepartment", url('subdepartment.read', uuid=form.fieldset.model.uuid))}</li> <li>${h.link_to("View this Subdepartment", url('subdepartment.read', uuid=form.fieldset.model.uuid))}</li>
% endif % 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'):
<li>${h.link_to("View Change History ({0})".format(version_count), url('subdepartment.versions', uuid=form.fieldset.model.uuid))}</li> <li>${h.link_to("View Change History ({0})".format(version_count), url('subdepartment.versions', uuid=form.fieldset.model.uuid))}</li>
% endif % endif
</%def> </%def>

View file

@ -8,7 +8,7 @@
% elif form.updating: % elif form.updating:
<li>${h.link_to("View this Vendor", url('vendor.read', uuid=form.fieldset.model.uuid))}</li> <li>${h.link_to("View this Vendor", url('vendor.read', uuid=form.fieldset.model.uuid))}</li>
% endif % 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'):
<li>${h.link_to("View Change History ({0})".format(version_count), url('vendor.versions', uuid=form.fieldset.model.uuid))}</li> <li>${h.link_to("View Change History ({0})".format(version_count), url('vendor.versions', uuid=form.fieldset.model.uuid))}</li>
% endif % endif
</%def> </%def>

View file

@ -30,7 +30,7 @@ import sqlalchemy as sa
import sqlalchemy_continuum as continuum import sqlalchemy_continuum as continuum
from rattail.db import model from rattail.db import model
from rattail.db.model.continuum import model_transaction_query from rattail.db.continuum import model_transaction_query
import formalchemy import formalchemy
from pyramid.httpexceptions import HTTPNotFound from pyramid.httpexceptions import HTTPNotFound

View file

@ -37,7 +37,7 @@ from sqlalchemy_continuum import transaction_class, version_class
from sqlalchemy_continuum.utils import is_versioned from sqlalchemy_continuum.utils import is_versioned
from rattail.db import model 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 from pyramid.httpexceptions import HTTPFound, HTTPNotFound