tycho-components 0.17.2 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -33,10 +33,14 @@ export default function HeaderApps({ navigateLogout, navigateNotLogged, hideKeyb
|
|
|
33
33
|
return null;
|
|
34
34
|
if (item.admin && !isAdminOfAnyCorpus())
|
|
35
35
|
return null;
|
|
36
|
-
if (item.lexicon &&
|
|
36
|
+
if (item.lexicon &&
|
|
37
|
+
(!hasCorpus() || !hasLexiconAccess(getCorpus().uid))) {
|
|
37
38
|
return null;
|
|
38
|
-
|
|
39
|
+
}
|
|
40
|
+
if (item.parser &&
|
|
41
|
+
(!hasCorpus() || !hasParserAccess(getCorpus().uid))) {
|
|
39
42
|
return null;
|
|
43
|
+
}
|
|
40
44
|
return (_jsxs("div", { className: "item", title: t(`${item.code}.desc`), onClick: () => goto(item, item.external ? true : false), children: [item.icon && _jsx(Icon, { name: item.icon, size: "medium" }), item.image && _jsx("img", { src: item.image }), _jsx("span", { className: "title-app", children: t(`${item.code}.name`) }), _jsxs("div", { className: "options", children: [item.visibility && (_jsx(Tag, { text: t(`common:label.${item.visibility}`), size: "small", color: "green", className: "d-none" })), _jsx(IconButton, { name: "open_in_new", size: "x-small", className: "icon-open", mode: "ghost", onClick: (e) => {
|
|
41
45
|
e.stopPropagation();
|
|
42
46
|
goto(item, true);
|
|
@@ -5,6 +5,10 @@ export declare const useLoggedUtils: () => {
|
|
|
5
5
|
isLogged: () => boolean;
|
|
6
6
|
setLogged: (user: User | undefined) => void;
|
|
7
7
|
isAdminOfAnyCorpus: () => boolean;
|
|
8
|
-
hasLexiconAccess: () => boolean;
|
|
9
|
-
hasParserAccess: () => boolean;
|
|
8
|
+
hasLexiconAccess: (lexiconUid: string, roles?: string[]) => boolean;
|
|
9
|
+
hasParserAccess: (parserUid: string, roles?: string[]) => boolean;
|
|
10
|
+
hasCorpusAccess: (corpusUid: string, roles?: string[]) => boolean;
|
|
11
|
+
hasAnyParserAccess: () => boolean;
|
|
12
|
+
hasAnyLexiconAccess: () => boolean;
|
|
13
|
+
hasAnyCorpusAccess: () => boolean;
|
|
10
14
|
};
|
|
@@ -2,6 +2,15 @@ import { useContext } from 'react';
|
|
|
2
2
|
import CommonContext from './CommonContext';
|
|
3
3
|
import { logged } from './store/actions';
|
|
4
4
|
import { UserStatus } from './types/User';
|
|
5
|
+
function escapeRegex(s) {
|
|
6
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
7
|
+
}
|
|
8
|
+
function roleSegmentForRegex(roles) {
|
|
9
|
+
if (roles && roles.length > 0) {
|
|
10
|
+
return `(${roles.map(escapeRegex).join('|')})`;
|
|
11
|
+
}
|
|
12
|
+
return '(.*)';
|
|
13
|
+
}
|
|
5
14
|
export const useLoggedUtils = () => {
|
|
6
15
|
const { state, dispatch } = useContext(CommonContext);
|
|
7
16
|
const getLogged = () => {
|
|
@@ -24,7 +33,37 @@ export const useLoggedUtils = () => {
|
|
|
24
33
|
return false;
|
|
25
34
|
return user.permissions.some((permission) => /^ROLE_ADMIN_CORPUS_[\w-]+$/.test(permission));
|
|
26
35
|
};
|
|
27
|
-
const hasParserAccess = () => {
|
|
36
|
+
const hasParserAccess = (parserUid, roles) => {
|
|
37
|
+
if (isSuper())
|
|
38
|
+
return true;
|
|
39
|
+
const user = getLogged();
|
|
40
|
+
if (!user || !user.permissions)
|
|
41
|
+
return false;
|
|
42
|
+
const id = escapeRegex(parserUid);
|
|
43
|
+
const re = new RegExp(`^ROLE_${roleSegmentForRegex(roles)}_PARSER_${id}$`);
|
|
44
|
+
return user.permissions.some((permission) => re.test(permission));
|
|
45
|
+
};
|
|
46
|
+
const hasLexiconAccess = (lexiconUid, roles) => {
|
|
47
|
+
if (isSuper())
|
|
48
|
+
return true;
|
|
49
|
+
const user = getLogged();
|
|
50
|
+
if (!user || !user.permissions)
|
|
51
|
+
return false;
|
|
52
|
+
const id = escapeRegex(lexiconUid);
|
|
53
|
+
const re = new RegExp(`^ROLE_${roleSegmentForRegex(roles)}_LEXICON_${id}$`);
|
|
54
|
+
return user.permissions.some((permission) => re.test(permission));
|
|
55
|
+
};
|
|
56
|
+
const hasCorpusAccess = (corpusUid, roles) => {
|
|
57
|
+
if (isSuper())
|
|
58
|
+
return true;
|
|
59
|
+
const user = getLogged();
|
|
60
|
+
if (!user || !user.permissions)
|
|
61
|
+
return false;
|
|
62
|
+
const id = escapeRegex(corpusUid);
|
|
63
|
+
const re = new RegExp(`^ROLE_${roleSegmentForRegex(roles)}_CORPUS_${id}$`);
|
|
64
|
+
return user.permissions.some((permission) => re.test(permission));
|
|
65
|
+
};
|
|
66
|
+
const hasAnyParserAccess = () => {
|
|
28
67
|
if (isSuper())
|
|
29
68
|
return true;
|
|
30
69
|
const user = getLogged();
|
|
@@ -32,7 +71,7 @@ export const useLoggedUtils = () => {
|
|
|
32
71
|
return false;
|
|
33
72
|
return user.permissions.some((permission) => /^ROLE_(.*)_PARSER_[\w-]+$/.test(permission));
|
|
34
73
|
};
|
|
35
|
-
const
|
|
74
|
+
const hasAnyLexiconAccess = () => {
|
|
36
75
|
if (isSuper())
|
|
37
76
|
return true;
|
|
38
77
|
const user = getLogged();
|
|
@@ -40,6 +79,14 @@ export const useLoggedUtils = () => {
|
|
|
40
79
|
return false;
|
|
41
80
|
return user.permissions.some((permission) => /^ROLE_(.*)_LEXICON_[\w-]+$/.test(permission));
|
|
42
81
|
};
|
|
82
|
+
const hasAnyCorpusAccess = () => {
|
|
83
|
+
if (isSuper())
|
|
84
|
+
return true;
|
|
85
|
+
const user = getLogged();
|
|
86
|
+
if (!user || !user.permissions)
|
|
87
|
+
return false;
|
|
88
|
+
return user.permissions.some((permission) => /^ROLE_(.*)_CORPUS_[\w-]+$/.test(permission));
|
|
89
|
+
};
|
|
43
90
|
return {
|
|
44
91
|
getLogged,
|
|
45
92
|
isSuper,
|
|
@@ -48,5 +95,9 @@ export const useLoggedUtils = () => {
|
|
|
48
95
|
isAdminOfAnyCorpus,
|
|
49
96
|
hasLexiconAccess,
|
|
50
97
|
hasParserAccess,
|
|
98
|
+
hasCorpusAccess,
|
|
99
|
+
hasAnyParserAccess,
|
|
100
|
+
hasAnyLexiconAccess,
|
|
101
|
+
hasAnyCorpusAccess,
|
|
51
102
|
};
|
|
52
103
|
};
|
|
@@ -13,6 +13,7 @@ export type RedirectPageParams = {
|
|
|
13
13
|
hasParameter: (corpus: Corpus, param: string) => boolean;
|
|
14
14
|
tool?: PlatformTools;
|
|
15
15
|
ctxPath?: string;
|
|
16
|
+
sameWindow?: boolean;
|
|
16
17
|
};
|
|
17
18
|
type EditionToolsMenu = {
|
|
18
19
|
parameter: string;
|
|
@@ -24,7 +25,7 @@ type EditionToolsMenu = {
|
|
|
24
25
|
};
|
|
25
26
|
export declare const EDITION_TOOLS: EditionToolsMenu[];
|
|
26
27
|
declare const ToolsUtils: {
|
|
27
|
-
redirectPage: ({ corpus, uid, hasParameter, tool, ctxPath, }: RedirectPageParams) => void;
|
|
28
|
+
redirectPage: ({ corpus, uid, hasParameter, tool, ctxPath, sameWindow, }: RedirectPageParams) => void;
|
|
28
29
|
getIcon: (defaultTool?: PlatformTools) => string;
|
|
29
30
|
openDocument: ({ page, corpus, hasParameter, defaultTool, ctxPath, }: OpenDocumentParams) => void;
|
|
30
31
|
getTitle: (defaultTool?: PlatformTools) => string;
|
|
@@ -47,34 +47,42 @@ const withCtxPath = (absolutePath, ctxPath) => {
|
|
|
47
47
|
const path = absolutePath.startsWith('/') ? absolutePath : `/${absolutePath}`;
|
|
48
48
|
return `${base}${path}`;
|
|
49
49
|
};
|
|
50
|
-
const
|
|
51
|
-
|
|
50
|
+
const navigateTo = (path, ctxPath, sameWindow) => {
|
|
51
|
+
const targetPath = withCtxPath(path, ctxPath);
|
|
52
|
+
if (sameWindow) {
|
|
53
|
+
window.location.assign(targetPath);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
window.open(targetPath);
|
|
57
|
+
};
|
|
58
|
+
const openTranslations = (uid, ctxPath, sameWindow) => {
|
|
59
|
+
navigateTo(`/translation/${uid}`, ctxPath, sameWindow);
|
|
52
60
|
};
|
|
53
|
-
const openTranscriber = (uid, ctxPath) => {
|
|
54
|
-
|
|
61
|
+
const openTranscriber = (uid, ctxPath, sameWindow) => {
|
|
62
|
+
navigateTo(`/transcriber/${uid}`, ctxPath, sameWindow);
|
|
55
63
|
};
|
|
56
|
-
const openEdictor = (uid, ctxPath) => {
|
|
57
|
-
|
|
64
|
+
const openEdictor = (uid, ctxPath, sameWindow) => {
|
|
65
|
+
navigateTo(`/editor/${uid}`, ctxPath, sameWindow);
|
|
58
66
|
};
|
|
59
|
-
const openDesign = (uid, ctxPath) => {
|
|
60
|
-
|
|
67
|
+
const openDesign = (uid, ctxPath, sameWindow) => {
|
|
68
|
+
navigateTo(`/editor/box/${uid}`, ctxPath, sameWindow);
|
|
61
69
|
};
|
|
62
|
-
const redirectPage = ({ corpus, uid, hasParameter, tool, ctxPath, }) => {
|
|
70
|
+
const redirectPage = ({ corpus, uid, hasParameter, tool, ctxPath, sameWindow, }) => {
|
|
63
71
|
if (tool) {
|
|
64
|
-
|
|
72
|
+
navigateTo(`${EDITION_TOOLS.find((t) => t.name === tool)?.path}/${uid}`, ctxPath, sameWindow);
|
|
65
73
|
return;
|
|
66
74
|
}
|
|
67
75
|
if (hasParameter(corpus, 'useEdictor')) {
|
|
68
|
-
openEdictor(uid, ctxPath);
|
|
76
|
+
openEdictor(uid, ctxPath, sameWindow);
|
|
69
77
|
}
|
|
70
78
|
else if (hasParameter(corpus, 'useTranslations')) {
|
|
71
|
-
openTranslations(uid, ctxPath);
|
|
79
|
+
openTranslations(uid, ctxPath, sameWindow);
|
|
72
80
|
}
|
|
73
81
|
else if (hasParameter(corpus, 'useDesigner')) {
|
|
74
|
-
openDesign(uid, ctxPath);
|
|
82
|
+
openDesign(uid, ctxPath, sameWindow);
|
|
75
83
|
}
|
|
76
84
|
else if (hasParameter(corpus, 'useTranscriber')) {
|
|
77
|
-
openTranscriber(uid, ctxPath);
|
|
85
|
+
openTranscriber(uid, ctxPath, sameWindow);
|
|
78
86
|
}
|
|
79
87
|
};
|
|
80
88
|
const openDocument = ({ page, corpus, hasParameter, defaultTool, ctxPath, }) => {
|