##// END OF EJS Templates
fix(caching): fixed problems with Cache query for users....
fix(caching): fixed problems with Cache query for users. The old way of querying caused the user get query to be always cached, and returning old results even in 2fa forms. The new limited query doesn't cache the user object resolving issues

File last commit:

r1753:79e2d284 default
r5365:ae8a165b default
Show More
073_version_4_8_0.py
63 lines | 1.5 KiB | text/x-python | PythonLexer
import logging
from sqlalchemy import *
from rhodecode.model import meta
from rhodecode.lib.dbmigrate.versions import _reset_base, notify
log = logging.getLogger(__name__)
def get_by_key(cls, key):
return cls.query().filter(cls.ui_key == key).scalar()
def create_or_update_hook(cls, key, val, SESSION):
new_ui = get_by_key(cls, key) or cls()
new_ui.ui_section = 'hooks'
new_ui.ui_active = True
new_ui.ui_key = key
new_ui.ui_value = val
SESSION().add(new_ui)
def upgrade(migrate_engine):
"""
Upgrade operations go here.
Don't create your own engine; bind migrate_engine to your metadata
"""
_reset_base(migrate_engine)
from rhodecode.lib.dbmigrate.schema import db_4_7_0_0 as db
# issue fixups
fixups(db, meta.Session)
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
def fixups(models, _SESSION):
cleanup_if_present = (
'pushkey.key_push',
)
for hook in cleanup_if_present:
ui_cfg = models.RhodeCodeUi.query().filter(
models.RhodeCodeUi.ui_key == hook).scalar()
if ui_cfg is not None:
log.info('Removing RhodeCodeUI for hook "%s".', hook)
_SESSION().delete(ui_cfg)
to_add = [
('pushkey.key_push',
'python:vcsserver.hooks.key_push'),
]
for hook, value in to_add:
log.info('Adding RhodeCodeUI for hook "%s".', hook)
create_or_update_hook(models.RhodeCodeUi, hook, value, _SESSION)
_SESSION().commit()