<commit_before># -*- coding: utf-8 -*-

import os
import hashlib

from datetime import datetime

from flask import Blueprint, render_template, current_app, request, flash
from flask.ext.login import login_required, current_user
from flask.ext.babel import gettext as _

from ..extensions import db
from ..user import User, UserDetail
from ..utils import allowed_file, make_dir
from .forms import ProfileForm, PasswordForm


settings = Blueprint('settings', __name__, url_prefix='/settings')


@settings.route('/profile', methods=['GET', 'POST'], defaults={'user_id': None})
@settings.route('/profile/<int:user_id>/edit', methods=['GET', 'POST'])
@login_required
def profile(user_id):
    if user_id:
        edit = True
        user = User.query.get(user_id)
    else:
        edit = False
        user = User.query.filter_by(name=current_user.name).first_or_404()
    if not user.user_detail:
        user.user_detail = UserDetail()
    form = ProfileForm(obj=user.user_detail,
                       email=user.email,
                       role_code=user.role_code,
                       status_code=user.status_code,
                       next=request.args.get('next'))
<commit_msg>Prevent non admin users from editing other users<commit_after># -*- coding: utf-8 -*-

import os
import hashlib

from datetime import datetime

from flask import Blueprint, render_template, current_app, request, flash, abort
from flask.ext.login import login_required, current_user
from flask.ext.babel import gettext as _

from ..extensions import db
from ..user import User, UserDetail
from ..utils import allowed_file, make_dir
from .forms import ProfileForm, PasswordForm
from ..user.constants import USER_ROLE, ADMIN


settings = Blueprint('settings', __name__, url_prefix='/settings')


@settings.route('/profile', methods=['GET', 'POST'], defaults={'user_id': None})
@settings.route('/profile/<int:user_id>/edit', methods=['GET', 'POST'])
@login_required
def profile(user_id):
    if current_user.id != user_id:
        if current_user.role != USER_ROLE[ADMIN]:
            abort(403)

    if user_id:
        edit = True
        user = User.query.get(user_id)
    else:
        edit = False
        user = User.query.filter_by(name=current_user.name).first_or_404()
    if not user.user_detail:
        user.user_detail = UserDetail()
    form = ProfileForm(obj=user.user_detail,
                       email=user.email,
                       role_code=user.role_code,
                       status_code=user.status_code,
                       next=request.args.get('next'))

{'fraction_non_alphanumeric': 0.11309755149630782, 'fraction_numerical': 0.004275165176836378, 'mean_word_length': 3.0922098569157392, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7453277', 'n_tokens_mistral': 769, 'n_tokens_neox': 742, 'n_words': 190}