Completed
Push — main ( 39501b...4a0798 )
by Jochen
05:29
created

byceps.blueprints.common.user.current.views.details_update()   A

Complexity

Conditions 2

Size

Total Lines 37
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 5.335

Importance

Changes 0
Metric Value
cc 2
eloc 28
nop 0
dl 0
loc 37
ccs 1
cts 17
cp 0.0588
crap 5.335
rs 9.208
c 0
b 0
f 0
1
"""
2
byceps.blueprints.common.user.current.views
3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5
:Copyright: 2006-2020 Jochen Kupperschmidt
6
:License: Modified BSD, see LICENSE for details.
7
"""
8
9 1
from flask import abort, g, jsonify, Response
10
11 1
from .....config import get_app_mode
12 1
from .....util.framework.blueprint import create_blueprint
13
14
15 1
blueprint = create_blueprint('user_current', __name__)
16
17
18 1
@blueprint.route('/me.json')
19
def view_as_json():
20
    """Show selected attributes of the current user's profile as JSON."""
21 1
    if get_app_mode().is_admin():
22
        abort(404)
23
24 1
    user = g.current_user
25
26 1
    if not user.is_active:
27
        # Return empty response.
28 1
        return Response(status=403)
29
30 1
    return jsonify(
31
        {
32
            'id': user.id,
33
            'screen_name': user.screen_name,
34
            'avatar_url': user.avatar_url,
35
        }
36
    )
37