viewo-helpdesk 1.0.0__tar.gz
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.
- viewo_helpdesk-1.0.0/LICENSE +21 -0
- viewo_helpdesk-1.0.0/MANIFEST.in +1 -0
- viewo_helpdesk-1.0.0/PKG-INFO +24 -0
- viewo_helpdesk-1.0.0/README +1 -0
- viewo_helpdesk-1.0.0/pyproject.toml +98 -0
- viewo_helpdesk-1.0.0/setup.cfg +4 -0
- viewo_helpdesk-1.0.0/tests/test_action.py +25 -0
- viewo_helpdesk-1.0.0/tests/test_collect.py +18 -0
- viewo_helpdesk-1.0.0/tests/test_config.py +18 -0
- viewo_helpdesk-1.0.0/tests/test_login.py +8 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/__init__.py +38 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/__main__.py +26 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/__patch__.py +8 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/api/__init__.py +101 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/api/auth.py +102 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/api/delete.py +8 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/api/post.py +49 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/api/present.py +43 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/app.py +45 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/cli.py +76 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/config.py +52 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/fixtures.py +41 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/message/__init__.py +38 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/message/action.py +52 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/message/collect.py +109 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/message/path.py +17 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/message/serialize.py +15 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/templates/admin/base.html +13 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/templates/admin/index.html +33 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/templates/admin/reply.html +5 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/templates/admin/show.html +25 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/templates/base.html +19 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/templates/helper.mac +16 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/templates/login.html +78 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/templates/user.html +0 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/view/__init__.py +16 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/view/admin.py +53 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/view/login.py +31 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk/view/user.py +8 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk.egg-info/PKG-INFO +24 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk.egg-info/SOURCES.txt +43 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk.egg-info/dependency_links.txt +1 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk.egg-info/entry_points.txt +2 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk.egg-info/requires.txt +9 -0
- viewo_helpdesk-1.0.0/viewo_helpdesk.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Helmut Konrad Schewe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
graft viewo_helpdesk/templates
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: viewo_helpdesk
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Author-email: Helmut Konrad Schewe <helmutus@outlook.com>
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/anaticulae/viewo-helpdesk
|
|
7
|
+
Project-URL: Repository, https://github.com/anaticulae/viewo-helpdesk
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
11
|
+
Requires-Python: >=3.12
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: bootstrap-flask<3.0.0,>=2.6.0
|
|
15
|
+
Requires-Dist: configos<2.0.0,>=1.0.4
|
|
16
|
+
Requires-Dist: flask-login<1.0.0,>=0.6.3
|
|
17
|
+
Requires-Dist: flask<4.0.0,>=3.1.3
|
|
18
|
+
Requires-Dist: flask_bootstrap<4.0.0.0,>=3.3.7.1
|
|
19
|
+
Requires-Dist: utilo<3.0.0,>=2.112.1
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: utilotest==1.1.1; extra == "dev"
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# viewo_helpdesk
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# viewo_helpdesk
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = [
|
|
3
|
+
"setuptools>=83.0.0",
|
|
4
|
+
"wheel>=0.47.0",
|
|
5
|
+
]
|
|
6
|
+
build-backend = "setuptools.build_meta"
|
|
7
|
+
|
|
8
|
+
[project]
|
|
9
|
+
name = "viewo_helpdesk"
|
|
10
|
+
version = "1.0.0"
|
|
11
|
+
description = ""
|
|
12
|
+
requires-python = ">=3.12"
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Helmut Konrad Schewe", email = "helmutus@outlook.com" },
|
|
15
|
+
]
|
|
16
|
+
dependencies = [
|
|
17
|
+
"bootstrap-flask>=2.6.0,<3.0.0",
|
|
18
|
+
"configos>=1.0.4,<2.0.0",
|
|
19
|
+
"flask-login>=0.6.3,<1.0.0",
|
|
20
|
+
"flask>=3.1.3,<4.0.0",
|
|
21
|
+
"flask_bootstrap>=3.3.7.1,<4.0.0.0",
|
|
22
|
+
"utilo>=2.112.1,<3.0.0",
|
|
23
|
+
]
|
|
24
|
+
keywords = []
|
|
25
|
+
classifiers = [
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: Python :: 3.13",
|
|
28
|
+
"Programming Language :: Python :: 3.14",
|
|
29
|
+
]
|
|
30
|
+
license = "MIT"
|
|
31
|
+
license-files = [
|
|
32
|
+
"LICENSE",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.readme]
|
|
36
|
+
file = "README"
|
|
37
|
+
content-type = "text/markdown"
|
|
38
|
+
|
|
39
|
+
[project.optional-dependencies]
|
|
40
|
+
dev = [
|
|
41
|
+
"utilotest==1.1.1",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
Homepage = "https://github.com/anaticulae/viewo-helpdesk"
|
|
46
|
+
Repository = "https://github.com/anaticulae/viewo-helpdesk"
|
|
47
|
+
|
|
48
|
+
[project.scripts]
|
|
49
|
+
viewo_helpdesk = "viewo_helpdesk.cli:main"
|
|
50
|
+
|
|
51
|
+
[tool.semantic_release]
|
|
52
|
+
version_toml = [
|
|
53
|
+
"pyproject.toml:project.version",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
[tool.semantic_release.changelog]
|
|
57
|
+
mode = "init"
|
|
58
|
+
output_format = "md"
|
|
59
|
+
|
|
60
|
+
[tool.semantic_release.changelog.default_templates]
|
|
61
|
+
changelog_file = "CHANGELOG"
|
|
62
|
+
|
|
63
|
+
[tool.semantic_release.commit_parser_options]
|
|
64
|
+
allowed_tags = [
|
|
65
|
+
"build",
|
|
66
|
+
"chore",
|
|
67
|
+
"ci",
|
|
68
|
+
"deps",
|
|
69
|
+
"docs",
|
|
70
|
+
"feat",
|
|
71
|
+
"fix",
|
|
72
|
+
"perf",
|
|
73
|
+
"refactor",
|
|
74
|
+
"style",
|
|
75
|
+
"test",
|
|
76
|
+
]
|
|
77
|
+
default_bump_level = 2
|
|
78
|
+
|
|
79
|
+
[tool.setuptools.packages.find]
|
|
80
|
+
where = [
|
|
81
|
+
".",
|
|
82
|
+
]
|
|
83
|
+
include = [
|
|
84
|
+
"viewo_helpdesk",
|
|
85
|
+
"viewo_helpdesk.api",
|
|
86
|
+
"viewo_helpdesk.message",
|
|
87
|
+
"viewo_helpdesk.view",
|
|
88
|
+
]
|
|
89
|
+
exclude = [
|
|
90
|
+
"tests*",
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
[tool.hoverpower]
|
|
94
|
+
packages = [
|
|
95
|
+
"DOCU",
|
|
96
|
+
"HOME",
|
|
97
|
+
"MASTER",
|
|
98
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
import tests
|
|
13
|
+
import viewo_helpdesk
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@pytest.mark.usefixtures('appi')
|
|
17
|
+
def test_action_start_converation():
|
|
18
|
+
# user starts issue
|
|
19
|
+
created = tests.create_single_sample()
|
|
20
|
+
|
|
21
|
+
dialog = viewo_helpdesk.load_messages(tests.TESTUSER, created)
|
|
22
|
+
assert len(dialog) == 3
|
|
23
|
+
assert dialog[0].writer # user
|
|
24
|
+
assert not dialog[1].writer # admin
|
|
25
|
+
assert dialog[2].writer # user
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
import viewo_helpdesk
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@pytest.mark.usefixtures('appi')
|
|
16
|
+
def test_load_users():
|
|
17
|
+
users = viewo_helpdesk.load_users()
|
|
18
|
+
assert not users
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
import viewo_helpdesk.config
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@pytest.mark.usefixtures('appi')
|
|
16
|
+
def test_access_root():
|
|
17
|
+
root = viewo_helpdesk.config.helpdesk()
|
|
18
|
+
assert root
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#==============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
#------------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
#==============================================================================
|
|
9
|
+
|
|
10
|
+
import importlib.metadata
|
|
11
|
+
import os
|
|
12
|
+
|
|
13
|
+
import utilo
|
|
14
|
+
|
|
15
|
+
import viewo_helpdesk.__patch__
|
|
16
|
+
from viewo_helpdesk.api import api_call
|
|
17
|
+
from viewo_helpdesk.config import API_PREFIX
|
|
18
|
+
from viewo_helpdesk.config import SECRET_KEY
|
|
19
|
+
from viewo_helpdesk.config import VIEWO_HELPDESK
|
|
20
|
+
from viewo_helpdesk.config import board
|
|
21
|
+
from viewo_helpdesk.config import configure
|
|
22
|
+
from viewo_helpdesk.message import Dialog
|
|
23
|
+
from viewo_helpdesk.message import Dialogs
|
|
24
|
+
from viewo_helpdesk.message import Message
|
|
25
|
+
from viewo_helpdesk.message import Messages
|
|
26
|
+
from viewo_helpdesk.message.action import start_conversion
|
|
27
|
+
from viewo_helpdesk.message.action import write_message
|
|
28
|
+
from viewo_helpdesk.message.collect import load_dialogs
|
|
29
|
+
from viewo_helpdesk.message.collect import load_messages
|
|
30
|
+
from viewo_helpdesk.message.collect import load_users
|
|
31
|
+
from viewo_helpdesk.message.collect import valid_dialog
|
|
32
|
+
from viewo_helpdesk.message.collect import valid_user
|
|
33
|
+
from viewo_helpdesk.message.path import userpath
|
|
34
|
+
from viewo_helpdesk.message.serialize import dump_message
|
|
35
|
+
|
|
36
|
+
__version__ = importlib.metadata.version('viewo-helpdesk')
|
|
37
|
+
|
|
38
|
+
ROOT = os.path.abspath(utilo.join(os.path.dirname(__file__), '..'))
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
import utilo
|
|
13
|
+
|
|
14
|
+
import viewo_helpdesk
|
|
15
|
+
import viewo_helpdesk.app
|
|
16
|
+
import viewo_helpdesk.config
|
|
17
|
+
|
|
18
|
+
CONFIG = {
|
|
19
|
+
viewo_helpdesk.config.VIEWO_HELPDESK:
|
|
20
|
+
os.environ.get(
|
|
21
|
+
viewo_helpdesk.config.VIEWO_HELPDESK,
|
|
22
|
+
utilo.join(utilo.tmpdir(viewo_helpdesk.ROOT), 'viewo_helpdesk'),
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
instance = viewo_helpdesk.app.create(CONFIG) # pylint:disable=C0103
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import functools
|
|
11
|
+
import http
|
|
12
|
+
|
|
13
|
+
import flask
|
|
14
|
+
import flask_login
|
|
15
|
+
import utilo
|
|
16
|
+
|
|
17
|
+
import viewo_helpdesk
|
|
18
|
+
import viewo_helpdesk.config
|
|
19
|
+
|
|
20
|
+
api_auth = flask.Blueprint('api_auth', __name__) # pylint:disable=C0103
|
|
21
|
+
api_message = flask.Blueprint('api_message', __name__) # pylint:disable=C0103
|
|
22
|
+
|
|
23
|
+
__all__ = ['api_auth', 'api_message', 'auth', 'delete', 'post', 'present']
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def dump(data, name='', uri='') -> str:
|
|
27
|
+
uri = uri if uri else flask.request.path
|
|
28
|
+
name = name if name else 'data'
|
|
29
|
+
data = utilo.simplify(data) # pylint:disable=E1101
|
|
30
|
+
connected = {'uri': uri, name: data}
|
|
31
|
+
json = flask.jsonify(connected)
|
|
32
|
+
return json
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def success(message: str = 'completed', **args):
|
|
36
|
+
result = flask.jsonify({
|
|
37
|
+
'message': message,
|
|
38
|
+
**args,
|
|
39
|
+
})
|
|
40
|
+
return result, http.HTTPStatus.OK
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def notfound(message: str):
|
|
44
|
+
result = flask.jsonify({
|
|
45
|
+
'error': 'not found',
|
|
46
|
+
'message': message,
|
|
47
|
+
})
|
|
48
|
+
return result, http.HTTPStatus.NOT_FOUND
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def bad(message: str):
|
|
52
|
+
result = flask.jsonify({
|
|
53
|
+
'error': 'bad request',
|
|
54
|
+
'message': message,
|
|
55
|
+
})
|
|
56
|
+
return result, http.HTTPStatus.BAD_REQUEST
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def internal(message: str):
|
|
60
|
+
result = flask.jsonify({
|
|
61
|
+
'error': 'internal',
|
|
62
|
+
'message': message,
|
|
63
|
+
})
|
|
64
|
+
return result, http.HTTPStatus.INTERNAL_SERVER_ERROR
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def api_call(path):
|
|
68
|
+
return viewo_helpdesk.config.API_PREFIX + path
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def valid_user(function):
|
|
72
|
+
|
|
73
|
+
@functools.wraps(function)
|
|
74
|
+
def decorated_function(*args, **kwargs):
|
|
75
|
+
userid = kwargs['userid']
|
|
76
|
+
currentuser = flask_login.current_user
|
|
77
|
+
if not currentuser.is_authenticated:
|
|
78
|
+
return bad('login required')
|
|
79
|
+
if not userid and not currentuser.is_admin:
|
|
80
|
+
return notfound('not accessable')
|
|
81
|
+
if userid and not currentuser.is_admin:
|
|
82
|
+
if not viewo_helpdesk.valid_user(userid):
|
|
83
|
+
return notfound(f'could not locate `{userid}`')
|
|
84
|
+
if currentuser.get_id() != userid:
|
|
85
|
+
return notfound('not accessable')
|
|
86
|
+
return function(*args, **kwargs)
|
|
87
|
+
|
|
88
|
+
return decorated_function
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def valid_dialog(function):
|
|
92
|
+
|
|
93
|
+
@functools.wraps(function)
|
|
94
|
+
def decorated_function(*args, **kwargs):
|
|
95
|
+
userid = kwargs['userid']
|
|
96
|
+
date = kwargs['date']
|
|
97
|
+
if not viewo_helpdesk.valid_dialog(userid, date):
|
|
98
|
+
return notfound(f'could not locate `{userid}` `{date}`')
|
|
99
|
+
return function(*args, **kwargs)
|
|
100
|
+
|
|
101
|
+
return decorated_function
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import dataclasses
|
|
11
|
+
import functools
|
|
12
|
+
import http
|
|
13
|
+
|
|
14
|
+
import flask
|
|
15
|
+
import flask_login
|
|
16
|
+
|
|
17
|
+
import viewo_helpdesk.api
|
|
18
|
+
import viewo_helpdesk.config
|
|
19
|
+
|
|
20
|
+
NO_ACCESS = 'LOGIN REQUIRED'
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclasses.dataclass
|
|
24
|
+
class FlaskUser(flask_login.UserMixin):
|
|
25
|
+
identifier: str = None
|
|
26
|
+
|
|
27
|
+
def get_id(self):
|
|
28
|
+
return self.identifier
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def is_admin(self):
|
|
32
|
+
return self.identifier == viewo_helpdesk.config.ADMIN_NAME
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def create_loginmanager(app):
|
|
36
|
+
loginmanager = flask_login.LoginManager()
|
|
37
|
+
loginmanager.login_view = 'api_auth.show_login'
|
|
38
|
+
loginmanager.init_app(app)
|
|
39
|
+
|
|
40
|
+
loginmanager._user_callback = load_user # pylint:disable=W0212
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def verify_password(user: str, password: str) -> bool:
|
|
44
|
+
if user == viewo_helpdesk.config.ADMIN_NAME:
|
|
45
|
+
if password == viewo_helpdesk.config.ADMIN_PASSWORD:
|
|
46
|
+
return True
|
|
47
|
+
return False
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def login(user, password) -> bool:
|
|
51
|
+
if not verify_password(user, password):
|
|
52
|
+
return False
|
|
53
|
+
user = load_user(user)
|
|
54
|
+
flask_login.login_user(user)
|
|
55
|
+
return True
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def load_user(userid):
|
|
59
|
+
return FlaskUser(identifier=userid)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@viewo_helpdesk.api.api_auth.route('/auth')
|
|
63
|
+
def show_login():
|
|
64
|
+
return NO_ACCESS, http.HTTPStatus.UNAUTHORIZED
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@viewo_helpdesk.api.api_auth.route('/logout')
|
|
68
|
+
def logout():
|
|
69
|
+
flask_login.logout_user()
|
|
70
|
+
return 'DONE'
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@viewo_helpdesk.api.api_auth.route('/auth', methods=['POST'])
|
|
74
|
+
def check_login():
|
|
75
|
+
if flask_login.current_user.is_authenticated:
|
|
76
|
+
return 'DONE'
|
|
77
|
+
|
|
78
|
+
user = flask.request.form['user']
|
|
79
|
+
password = flask.request.form['password']
|
|
80
|
+
|
|
81
|
+
# verify
|
|
82
|
+
if not verify_password(user, password):
|
|
83
|
+
return 'INVALID PASSWORD', http.HTTPStatus.NOT_FOUND
|
|
84
|
+
|
|
85
|
+
# login
|
|
86
|
+
login(user, password)
|
|
87
|
+
if flask_login.current_user.is_admin:
|
|
88
|
+
return flask.jsonify({'link': '/admin/messages/list'})
|
|
89
|
+
return 'DONE'
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def admin_required(func):
|
|
93
|
+
|
|
94
|
+
@functools.wraps(func)
|
|
95
|
+
def decorated_view(*args, **kwargs):
|
|
96
|
+
if not flask_login.current_user.is_authenticated:
|
|
97
|
+
return flask.current_app.login_manager.unauthorized()
|
|
98
|
+
if not flask_login.current_user.is_admin:
|
|
99
|
+
return flask.current_app.login_manager.unauthorized()
|
|
100
|
+
return func(*args, **kwargs)
|
|
101
|
+
|
|
102
|
+
return decorated_view
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import flask
|
|
11
|
+
import flask_login
|
|
12
|
+
import utilo
|
|
13
|
+
|
|
14
|
+
import viewo_helpdesk
|
|
15
|
+
import viewo_helpdesk.api
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@viewo_helpdesk.api.api_message.route('/dialog/add', methods=['POST'])
|
|
19
|
+
def message_add() -> str:
|
|
20
|
+
parent = flask.request.form.get('parent', None)
|
|
21
|
+
userid = flask.request.form.get('userid', None)
|
|
22
|
+
date = utilo.now()
|
|
23
|
+
title = flask.request.form.get('title', None)
|
|
24
|
+
text = flask.request.form.get('text', None)
|
|
25
|
+
category = flask.request.form.get('category', None)
|
|
26
|
+
|
|
27
|
+
new_dialog = parent is None
|
|
28
|
+
admin = flask_login.current_user.is_admin
|
|
29
|
+
if not admin:
|
|
30
|
+
userid = flask_login.current_user.get_id()
|
|
31
|
+
|
|
32
|
+
message = viewo_helpdesk.Message(
|
|
33
|
+
parent=None if new_dialog else parent,
|
|
34
|
+
userid=userid,
|
|
35
|
+
date=date,
|
|
36
|
+
title=title,
|
|
37
|
+
text=text,
|
|
38
|
+
writer=userid if not admin else None,
|
|
39
|
+
category=category,
|
|
40
|
+
)
|
|
41
|
+
if new_dialog:
|
|
42
|
+
viewo_helpdesk.start_conversion(message, current=date)
|
|
43
|
+
else:
|
|
44
|
+
viewo_helpdesk.write_message(message, current=date)
|
|
45
|
+
|
|
46
|
+
done = {'date': date}
|
|
47
|
+
uri = viewo_helpdesk.api_call(f'/dialog/{userid}/{date}')
|
|
48
|
+
dumped = viewo_helpdesk.api.dump(done, name='success', uri=uri)
|
|
49
|
+
return dumped
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import viewo_helpdesk
|
|
11
|
+
import viewo_helpdesk.api
|
|
12
|
+
import viewo_helpdesk.api.auth
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@viewo_helpdesk.api.api_message.route(
|
|
16
|
+
'/dialogs/<string(length=16):userid>',
|
|
17
|
+
methods=['GET'],
|
|
18
|
+
)
|
|
19
|
+
@viewo_helpdesk.api.valid_user
|
|
20
|
+
def dialogs(userid):
|
|
21
|
+
result = viewo_helpdesk.load_dialogs(userid)
|
|
22
|
+
dumped = viewo_helpdesk.api.dump(result, 'dialogs')
|
|
23
|
+
return dumped
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@viewo_helpdesk.api.api_message.route('/dialogs', methods=['GET'])
|
|
27
|
+
@viewo_helpdesk.api.auth.admin_required
|
|
28
|
+
def get_dialog():
|
|
29
|
+
result = viewo_helpdesk.load_dialogs()
|
|
30
|
+
dumped = viewo_helpdesk.api.dump(result, 'dialogs')
|
|
31
|
+
return dumped
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@viewo_helpdesk.api.api_message.route(
|
|
35
|
+
'/dialog/<string(length=16):userid>/<int:date>',
|
|
36
|
+
methods=['GET'],
|
|
37
|
+
)
|
|
38
|
+
@viewo_helpdesk.api.valid_user
|
|
39
|
+
@viewo_helpdesk.api.valid_dialog
|
|
40
|
+
def dialog_get(userid: str, date: int):
|
|
41
|
+
messages = viewo_helpdesk.load_messages(userid, date)
|
|
42
|
+
dumped = viewo_helpdesk.api.dump(messages, 'messages')
|
|
43
|
+
return dumped
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import flask
|
|
11
|
+
import flask_bootstrap
|
|
12
|
+
|
|
13
|
+
import viewo_helpdesk
|
|
14
|
+
import viewo_helpdesk.api.auth
|
|
15
|
+
import viewo_helpdesk.api.post
|
|
16
|
+
import viewo_helpdesk.api.present
|
|
17
|
+
from viewo_helpdesk.api import api_auth
|
|
18
|
+
from viewo_helpdesk.api import api_message
|
|
19
|
+
from viewo_helpdesk.view import * # pylint:disable=wildcard-import
|
|
20
|
+
from viewo_helpdesk.view import view_login
|
|
21
|
+
from viewo_helpdesk.view import view_user
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def create(config=None) -> flask.Flask:
|
|
25
|
+
appi = flask.Flask(__name__)
|
|
26
|
+
appi.secret_key = viewo_helpdesk.SECRET_KEY
|
|
27
|
+
|
|
28
|
+
viewo_helpdesk.api.auth.create_loginmanager(appi)
|
|
29
|
+
|
|
30
|
+
appi.config.setdefault('BOOTSTRAP_SERVE_LOCAL', True)
|
|
31
|
+
flask_bootstrap.Bootstrap5(app=appi)
|
|
32
|
+
|
|
33
|
+
if config:
|
|
34
|
+
appi.config.update(config)
|
|
35
|
+
|
|
36
|
+
# view
|
|
37
|
+
appi.register_blueprint(view_admin)
|
|
38
|
+
appi.register_blueprint(view_login)
|
|
39
|
+
appi.register_blueprint(view_user)
|
|
40
|
+
|
|
41
|
+
# api
|
|
42
|
+
appi.register_blueprint(api_auth, url_prefix=viewo_helpdesk.API_PREFIX)
|
|
43
|
+
appi.register_blueprint(api_message, url_prefix=viewo_helpdesk.API_PREFIX)
|
|
44
|
+
|
|
45
|
+
return appi
|