Passed
Push — main ( 828e64...5bb20b )
by Jochen
04:25
created

prepare_request_globals()   A

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
nop 0
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
"""
2
byceps.blueprints.admin.core.views
3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5
:Copyright: 2006-2021 Jochen Kupperschmidt
6
:License: Revised BSD (see `LICENSE` file for details)
7
"""
8
9 1
from flask import g
10
11 1
from .... import config
12 1
from ....services.brand import service as brand_service
13 1
from ....util.authorization import register_permission_enum
14 1
from ....util.framework.blueprint import create_blueprint
15 1
from ....util.user_session import (
16
    get_current_user,
17
    get_locale as get_session_locale,
18
)
19
20 1
from .authorization import AdminPermission
21
22
23 1
blueprint = create_blueprint('core_admin', __name__)
24
25
26 1
register_permission_enum(AdminPermission)
27
28
29 1
@blueprint.app_context_processor
30
def inject_template_variables():
31 1
    def get_brand_for_site(site):
32 1
        return brand_service.find_brand(site.brand_id)
33
34 1
    def get_brand_for_party(party):
35 1
        return brand_service.find_brand(party.brand_id)
36
37 1
    return {
38
        'get_brand_for_site': get_brand_for_site,
39
        'get_brand_for_party': get_brand_for_party,
40
    }
41
42
43 1
@blueprint.before_app_request
44
def prepare_request_globals():
45 1
    app_mode = config.get_app_mode()
46 1
    g.app_mode = app_mode
47
48 1
    locale = get_session_locale()
49
50 1
    required_permissions = {AdminPermission.access}
51
    g.user = get_current_user(required_permissions, locale)
52