Skip to content
Snippets Groups Projects
Select Git revision
  • 504d018bfdac3211ee603ef147858f836dc2d8ac
  • master default
  • 2021.04.06
  • 2020.11.25
  • 2020.11.13
  • 2020.10.30
  • 2020.10.27
  • 2020.10.06
  • 2020.07.08
  • 2020.06.12
  • 2020.04.16
  • 2020.03.17
  • 2020.03.09
  • 2020.03.05
  • 2020.02.25
  • 2020.02.24
  • 0.29.0
  • 0.28.0
  • 0.27.1
  • 0.27.0
  • 0.26.1
  • 0.26.0
22 results

plugins.py

Blame
  • Forked from ICS Control System Infrastructure / csentry
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    plugins.py 1.12 KiB
    # -*- coding: utf-8 -*-
    """
    app.plugins
    ~~~~~~~~~~~
    
    This module implements SQLAlchemy-Continuum plugins.
    
    FlaskUserPlugin offers way of integrating Flask framework with
    SQLAlchemy-Continuum. FlaskUser-Plugin adds a `user_id` column for Transaction model.
    
    This plugin is based on the official FlaskPlugin with the following modifications:
        - no remote_addr column
        - the user_id is taken from flask_jwt_extended (API) or flask_login (web UI)
    
    The `user_id` column is automatically populated when the transaction object is created.
    
    :copyright: original (c) 2012, Konsta Vesterinen
    :copyright: modified (c) 2017 European Spallation Source ERIC
    :license: BSD 2-Clause, see LICENSE for more details.
    
    """
    
    from sqlalchemy_continuum.plugins import Plugin
    from . import utils
    
    
    class FlaskUserPlugin(Plugin):
        def __init__(self, current_user_id_factory=None):
            self.current_user_id_factory = (
                utils.fetch_current_user_id
                if current_user_id_factory is None
                else current_user_id_factory
            )
    
        def transaction_args(self, uow, session):
            return {"user_id": self.current_user_id_factory()}