<commit_before>﻿import * as React from 'react'
import { Route } from 'react-router'
import { ajaxPost, ajaxGet } from '../../../Framework/Signum.React/Scripts/Services';
import { EntitySettings } from '../../../Framework/Signum.React/Scripts/Navigator'
import * as Navigator from '../../../Framework/Signum.React/Scripts/Navigator'
import { EntityOperationSettings } from '../../../Framework/Signum.React/Scripts/Operations'
import * as Operations from '../../../Framework/Signum.React/Scripts/Operations'
import { UserEntity, UserEntity_Type, UserOperation, RoleEntity_Type, PermissionSymbol } from './Signum.Entities.Authorization'
import Login from './Login/Login';

export let userTicket: boolean;
export let resetPassword: boolean;

export function startPublic(options: { routes: JSX.Element[], userTicket: boolean, resetPassword: boolean }) {
    userTicket = options.userTicket;
    resetPassword = options.resetPassword;

    options.routes.push(<Route path="auth">
        <Route path="login" getComponent={(loc, cb) => require(["./Login/Login"], (Comp) => cb(null, Comp.default))}/>
        <Route path="about" />
    </Route>);
}

export function startAdmin() {
    Navigator.addSettings(new EntitySettings(UserEntity_Type, e => new Promise(resolve => require(['./Templates/User'], resolve))));
    Navigator.addSettings(new EntitySettings(RoleEntity_Type, e => new Promise(resolve => require(['./Templates/Role'], resolve))));
}

export function currentUser(): UserEntity {
    return Navigator.currentUser as UserEntity;
}

export const CurrentUserChangedEvent = "current-user-changed";
export function setCurrentUser(user: UserEntity) {
    Navigator.currentUser = user;

    document.dispatchEvent(new Event(CurrentUserChangedEvent));
}


export function logout() {

    Api.logout().then(() => {

        setCurrentUser(null);

        onLogout();
    }).done();
}

export function onLogout() {
    Navigator.currentHistory.push("/");
}

export function onLogin() {
    Navigator.currentHistory.push("/");
}

export function isPermissionAuthorized(permission: PermissionSymbol) {
    return true;
}

export function asserPermissionAuthorized(permission: PermissionSymbol) {
    if (!isPermissionAuthorized(permission))
        throw new Error(`Permission ${permission.key} is denied`);
}<commit_msg>add isQueryAllowed mock<commit_after>﻿import * as React from 'react'
import { Route } from 'react-router'
import { ajaxPost, ajaxGet } from '../../../Framework/Signum.React/Scripts/Services';
import { EntitySettings } from '../../../Framework/Signum.React/Scripts/Navigator'
import * as Navigator from '../../../Framework/Signum.React/Scripts/Navigator'
import { EntityOperationSettings } from '../../../Framework/Signum.React/Scripts/Operations'
import { PseudoType, QueryKey } from '../../../Framework/Signum.React/Scripts/Reflection'
import * as Operations from '../../../Framework/Signum.React/Scripts/Operations'
import { UserEntity, UserEntity_Type, UserOperation, RoleEntity_Type, PermissionSymbol } from './Signum.Entities.Authorization'
import Login from './Login/Login';

export let userTicket: boolean;
export let resetPassword: boolean;

export function startPublic(options: { routes: JSX.Element[], userTicket: boolean, resetPassword: boolean }) {
    userTicket = options.userTicket;
    resetPassword = options.resetPassword;

    options.routes.push(<Route path="auth">
        <Route path="login" getComponent={(loc, cb) => require(["./Login/Login"], (Comp) => cb(null, Comp.default))}/>
        <Route path="about" />
    </Route>);
}

export function startAdmin() {
    Navigator.addSettings(new EntitySettings(UserEntity_Type, e => new Promise(resolve => require(['./Templates/User'], resolve))));
    Navigator.addSettings(new EntitySettings(RoleEntity_Type, e => new Promise(resolve => require(['./Templates/Role'], resolve))));
}

export function currentUser(): UserEntity {
    return Navigator.currentUser as UserEntity;
}

export const CurrentUserChangedEvent = "current-user-changed";
export function setCurrentUser(user: UserEntity) {
    Navigator.currentUser = user;

    document.dispatchEvent(new Event(CurrentUserChangedEvent));
}


export function logout() {

    Api.logout().then(() => {

        setCurrentUser(null);

        onLogout();
    }).done();
}

export function onLogout() {
    Navigator.currentHistory.push("/");
}

export function onLogin() {
    Navigator.currentHistory.push("/");
}

export function isPermissionAuthorized(permission: PermissionSymbol) {
    return true;
}

export function isQueryAllowed(quey: PseudoType | QueryKey) {
    return true;
}

export function asserPermissionAuthorized(permission: PermissionSymbol) {
    if (!isPermissionAuthorized(permission))
        throw new Error(`Permission ${permission.key} is denied`);
}
{'fraction_non_alphanumeric': 0.1477556109725686, 'fraction_numerical': 0.0, 'mean_word_length': 4.519495412844036, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, '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': '1686898', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1342, 'n_words': 310}