Compare commits

..

6 Commits

6 changed files with 260 additions and 20 deletions

View File

@ -9,6 +9,32 @@ SPDX-License-Identifier: AGPL-3.0-or-later
[![Build Status](https://drone.wtf-eg.de/api/badges/kompetenzinventar/ki-backend/status.svg?ref=refs/heads/main)](https://drone.wtf-eg.de/kompetenzinventar/ki-backend) [![Build Status](https://drone.wtf-eg.de/api/badges/kompetenzinventar/ki-backend/status.svg?ref=refs/heads/main)](https://drone.wtf-eg.de/kompetenzinventar/ki-backend)
[![REUSE status](https://api.reuse.software/badge/git.wtf-eg.de/kompetenzinventar/ki-backend)](https://api.reuse.software/info/git.wtf-eg.de/kompetenzinventar/ki-backend) [![REUSE status](https://api.reuse.software/badge/git.wtf-eg.de/kompetenzinventar/ki-backend)](https://api.reuse.software/info/git.wtf-eg.de/kompetenzinventar/ki-backend)
## Über
Dieses Repo enthält das Backend des Projekts Kompentenzinventar - einer Webapplikation zur Erfassung von Userprofilen für die WTF eG.
Implementiert ist das Backend mit Flask.
### Mitmachen
Du kannst gerne bei der Entwicklung des Kompetenzinventars mitmachen.
- Fehler oder fehlende Funktionen erfassen. Bitte direkt über die [Issues](https://git.wtf-eg.de/kompetenzinventar/ki-backend/issues) in Gitea.
- Dokumentation oder Implementierung verbessern. Bitte forke hierzu das Projekt, branche von `main` ab und erstelle dann einen [Pull Request](https://git.wtf-eg.de/kompetenzinventar/ki-backend/pulls).
### Kommunikation
Folgende Kanäle gibt es für die Kommunikation über das Kompetenzinventar:
- Die [Issues](https://git.wtf-eg.de/kompetenzinventar/ki-backend/issues) im WTF Gitea.
- Den Bereich [AG Entwicklung](https://forum.wtf-eg.de/c/interna/ag-entwicklung/21) im WTF Forum.
- Einen Raum in Matrix. Zutritt per Einladung, frlan lädt ein, eine einfache PN im Forum reicht.
### Repos
* **[ki-backend](https://git.wtf-eg.de/kompetenzinventar/ki-backend)** (dieses Repo) enthält das Backend
* [ki-frontend](https://git.wtf-eg.de/kompetenzinventar/ki-frontend) enthält das Frontend
* Weitere Repositories befinden sich in der Gitea Organisation [Kompetenzinventar](https://git.wtf-eg.de/kompetenzinventar).
## Entwicklung ## Entwicklung
### Abhängigkeiten ### Abhängigkeiten
@ -196,6 +222,24 @@ docker-compose up
Dann http://localhost:13337 aufrufen. Dann http://localhost:13337 aufrufen.
### Workaround, falls der Zugriff auf registry.wtf-eg.net nicht möglich ist
Voraussetzung:
[ki-backend-docker](https://git.wtf-eg.de/kompetenzinventar/ki-backend-docker) muss parallel zum `ki-backend` ausgecheckt sein.
```
cd ki-backend-docker
docker build . --target base -t ki-backend-base
docker build . --target builder -t ki-backend-builder
```
Ändern der 2 Einträge im `Dockerfile` des `ki-backend`:
- registry.wtf-eg.net/ki-backend-builder:1.0.0 -> ki-backend-builder
- registry.wtf-eg.net/ki-backend-base:1.0.0 -> ki-backend-base
Danach sollte `docker-compose up` funktionieren.
## Lizenzen ## Lizenzen

View File

@ -15,4 +15,112 @@ id,name
14,C 14,C
15,VHDL 15,VHDL
16,go 16,go
17, Perl 17,Perl
18,3D-Druck
19,ABAP
20,Android
21,Ansible
22,Arduino
23,Bash
24,batou
25,bind
26,Buchführung
27,C#
28,CAD
29,CAM
30,Cobol
31,CRM
32,CSS
33,D
34,Debian
35,Delphi
36,DevOPS
37,Discourse
38,Django
39,DNS
40,Dovecot
41,Elasticsearch
42,Emacs
43,Email
44,ERP
45,ESP
46,Excel
47,Fahrdienstleitung
48,Fedora
49,FLOSS
50,Geographie
51,Geologie
52,Gnome
53,GPS
54,Grafana
55,GrayLog
56,GSM
57,GTK
58,HTML
59,IBM Z
60,IMAP
61,Ionic
62,iOS
63,Java
64,Kryptographie
65,LDAP
66,LibreOffice
67,Linux
68,Literaturgeschichte
69,Lithographie
70,Lucene
71,Mailman
72,MariaDB
73,Markdown
74,Marketing
75,Microsoft Office
76,Monitoring
77,Nagios
78,nähen
79,NixOS
80,odoo
81,OpenOffice
82,OpenPGP
83,OpenStreetMap
84,openSUSE
85,Oracle
86,Percona
87,PGP
88,Plone
89,Postfix
90,PowerDNS
91,PowerPC
92,Projektmanagement
93,puppet
94,Qt
95,R/3
96,RedHat
97,RHEL
98,S/4
99,Salt
100,SAP
101,Scrum
102,ScummVM
103,Sensu
104,sh
105,Siemens S5
106,Siemens S7
107,Simatic
108,SLES
109,Spring
110,SQL
111,Stenographie
112,Steuerrecht
113,Teppich knüpfen
114,TeX
115,Verlagswesen
116,vi(m)
117,Windows 10
118,Windows 2000
119,Windows 2012R2
120,Windows 7
121,Windows NT
122,Windows XP
123,x86
124,Zope
125,zsh

1 id name
15 14 C
16 15 VHDL
17 16 go
18 17 Perl
19 18 3D-Druck
20 19 ABAP
21 20 Android
22 21 Ansible
23 22 Arduino
24 23 Bash
25 24 batou
26 25 bind
27 26 Buchführung
28 27 C#
29 28 CAD
30 29 CAM
31 30 Cobol
32 31 CRM
33 32 CSS
34 33 D
35 34 Debian
36 35 Delphi
37 36 DevOPS
38 37 Discourse
39 38 Django
40 39 DNS
41 40 Dovecot
42 41 Elasticsearch
43 42 Emacs
44 43 Email
45 44 ERP
46 45 ESP
47 46 Excel
48 47 Fahrdienstleitung
49 48 Fedora
50 49 FLOSS
51 50 Geographie
52 51 Geologie
53 52 Gnome
54 53 GPS
55 54 Grafana
56 55 GrayLog
57 56 GSM
58 57 GTK
59 58 HTML
60 59 IBM Z
61 60 IMAP
62 61 Ionic
63 62 iOS
64 63 Java
65 64 Kryptographie
66 65 LDAP
67 66 LibreOffice
68 67 Linux
69 68 Literaturgeschichte
70 69 Lithographie
71 70 Lucene
72 71 Mailman
73 72 MariaDB
74 73 Markdown
75 74 Marketing
76 75 Microsoft Office
77 76 Monitoring
78 77 Nagios
79 78 nähen
80 79 NixOS
81 80 odoo
82 81 OpenOffice
83 82 OpenPGP
84 83 OpenStreetMap
85 84 openSUSE
86 85 Oracle
87 86 Percona
88 87 PGP
89 88 Plone
90 89 Postfix
91 90 PowerDNS
92 91 PowerPC
93 92 Projektmanagement
94 93 puppet
95 94 Qt
96 95 R/3
97 96 RedHat
98 97 RHEL
99 98 S/4
100 99 Salt
101 100 SAP
102 101 Scrum
103 102 ScummVM
104 103 Sensu
105 104 sh
106 105 Siemens S5
107 106 Siemens S7
108 107 Simatic
109 108 SLES
110 109 Spring
111 110 SQL
112 111 Stenographie
113 112 Steuerrecht
114 113 Teppich knüpfen
115 114 TeX
116 115 Verlagswesen
117 116 vi(m)
118 117 Windows 10
119 118 Windows 2000
120 119 Windows 2012R2
121 120 Windows 7
122 121 Windows NT
123 122 Windows XP
124 123 x86
125 124 Zope
126 125 zsh

View File

@ -26,6 +26,31 @@ def seed_contacttypes():
db.session.add(ContactType(id=int(contacttype["id"]), name=contacttype["name"])) db.session.add(ContactType(id=int(contacttype["id"]), name=contacttype["name"]))
def seed_user(nickname, visible=False, skills=[], languages=[], volunteerwork="", availability="", freetext=""):
app.logger.info(f"seeding {nickname} \\o/")
user = User(auth_id=nickname)
db.session.add(user)
profile = Profile(nickname=nickname,
pronouns="",
volunteerwork=volunteerwork,
availability=availability,
freetext=freetext,
visible=visible,
user=user)
for skill_data in skills:
skill = ProfileSkill(profile=profile, skill_id=skill_data[0], level=skill_data[1])
db.session.add(skill)
for language_data in languages:
language = ProfileLanguage(profile=profile, language_id=language_data[0], level=language_data[1])
db.session.add(language)
db.session.add(profile)
def seed(dev: bool): def seed(dev: bool):
seed_contacttypes() seed_contacttypes()
@ -105,23 +130,21 @@ def seed(dev: bool):
peter_fr = ProfileLanguage(profile=peters_profile, language_id="fr", level=3) peter_fr = ProfileLanguage(profile=peters_profile, language_id="fr", level=3)
db.session.add(peter_fr) db.session.add(peter_fr)
app.logger.info("seeding klaus :D") seed_user("klaus")
klaus = User(auth_id="klaus") seed_user("dirtydieter",
db.session.add(klaus) visible=True,
volunteerwork="Müll sammeln",
availability="Nur nachts",
freetext="1001010010111!!!",
skills=[(Skill.skill_id_php, 5)])
app.logger.info("seeding dieter \\o/") seed_user("jutta",
visible=True,
dieter = User(auth_id="dieter") languages=[("fr", 5)],
db.session.add(dieter) skills=[(Skill.skill_id_php, 3), (Skill.skill_id_mysql, 4)])
seed_user("giesela", visible=True, skills=[(Skill.skill_id_mysql, 3), (Skill.skill_id_postgresql, 5)])
dieters_profile = Profile(nickname="dirtydieter", seed_user("bertha", visible=False, skills=[(Skill.skill_id_sqlite, 3), (Skill.skill_id_postgresql, 5)])
pronouns="", seed_user("monique", visible=True, languages=[("fr", 4)])
volunteerwork="Müll sammeln",
availability="Nur nachts",
freetext="1001010010111!!!",
visible=True,
user=dieter)
db.session.add(dieters_profile)
db.session.commit() db.session.commit()

View File

@ -4,7 +4,7 @@
from flask import make_response, request from flask import make_response, request
from ki.models import Profile from ki.models import Profile, ProfileSkill, Skill, ProfileLanguage, Language
def find_profiles(): def find_profiles():
@ -18,13 +18,21 @@ def find_profiles():
if page_size > 100: if page_size > 100:
return make_response({"messages": {"page_size": "Die maximale Anzahl Einträge pro Seite beträgt 100"}}, 400) return make_response({"messages": {"page_size": "Die maximale Anzahl Einträge pro Seite beträgt 100"}}, 400)
query = Profile.query.filter(Profile.visible.is_(True)) query = Profile.query.filter(Profile.visible.is_(True)) \
.join(Profile.skills, isouter=True).join(ProfileSkill.skill, isouter=True) \
.join(Profile.languages, isouter=True).join(ProfileLanguage.language, isouter=True)
if "search" in request.args:
terms = request.args["search"].split(" ")
for term in terms:
query = query.filter(
Profile.nickname.like(f"%{term}%") | Skill.name.like(f"%{term}%") | Language.name.like(f"%{term}%"))
if "nickname" in request.args: if "nickname" in request.args:
nickname = request.args.get("nickname") nickname = request.args.get("nickname")
query = query.filter(Profile.nickname.like(f"%{nickname}%")) query = query.filter(Profile.nickname.like(f"%{nickname}%"))
count = query.count() count = query.distinct(Profile.id).count()
offset = (page - 1) * page_size offset = (page - 1) * page_size
db_profiles = query.limit(page_size).offset(offset).all() db_profiles = query.limit(page_size).offset(offset).all()

View File

@ -133,6 +133,13 @@ class Address(db.Model):
class Skill(db.Model): class Skill(db.Model):
skill_id_php = 1
skill_id_python = 3
skill_id_sqlalchemy = 7
skill_id_mysql = 9
skill_id_postgresql = 10
skill_id_sqlite = 11
__tablename__ = "skill" __tablename__ = "skill"
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)

View File

@ -34,9 +34,59 @@ class TestFindProfilesEndpoint(ApiTest):
response = self.client.get("/users/profiles", headers={"Authorization": "Bearer " + token}) response = self.client.get("/users/profiles", headers={"Authorization": "Bearer " + token})
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertDictContainsSubset({"total": 4}, response.json)
self.assertDictContainsSubset({"nickname": "dirtydieter"}, response.json["profiles"][0])
def test_find_dieter(self):
token = self.login("peter", "geheim")["token"]
response = self.client.get("/users/profiles?search=dieter%20php", headers={"Authorization": "Bearer " + token})
self.assertEqual(response.status_code, 200)
self.assertDictContainsSubset({"total": 1}, response.json) self.assertDictContainsSubset({"total": 1}, response.json)
self.assertDictContainsSubset({"nickname": "dirtydieter"}, response.json["profiles"][0]) self.assertDictContainsSubset({"nickname": "dirtydieter"}, response.json["profiles"][0])
def test_not_find_dieter(self):
token = self.login("peter", "geheim")["token"]
response = self.client.get("/users/profiles?search=dieter%20sqlite",
headers={"Authorization": "Bearer " + token})
self.assertEqual(response.status_code, 200)
self.assertDictContainsSubset({"total": 0}, response.json)
def test_find_sql(self):
token = self.login("peter", "geheim")["token"]
response = self.client.get("/users/profiles?search=sql", headers={"Authorization": "Bearer " + token})
self.assertEqual(response.status_code, 200)
self.assertDictContainsSubset({"total": 2}, response.json)
self.assertDictContainsSubset({"nickname": "jutta"}, response.json["profiles"][0])
self.assertDictContainsSubset({"nickname": "giesela"}, response.json["profiles"][1])
def test_find_postgres(self):
token = self.login("peter", "geheim")["token"]
response = self.client.get("/users/profiles?search=post", headers={"Authorization": "Bearer " + token})
self.assertEqual(response.status_code, 200)
self.assertDictContainsSubset({"total": 1}, response.json)
self.assertDictContainsSubset({"nickname": "giesela"}, response.json["profiles"][0])
def test_find_php_franzosen(self):
token = self.login("peter", "geheim")["token"]
response = self.client.get("/users/profiles?search=php%20franz", headers={"Authorization": "Bearer " + token})
self.assertEqual(response.status_code, 200)
self.assertDictContainsSubset({"total": 1}, response.json)
self.assertDictContainsSubset({"nickname": "jutta"}, response.json["profiles"][0])
def test_find_franzosen(self):
token = self.login("peter", "geheim")["token"]
response = self.client.get("/users/profiles?search=französisch", headers={"Authorization": "Bearer " + token})
self.assertEqual(response.status_code, 200)
self.assertDictContainsSubset({"total": 2}, response.json)
self.assertDictContainsSubset({"nickname": "jutta"}, response.json["profiles"][0])
self.assertDictContainsSubset({"nickname": "monique"}, response.json["profiles"][1])
if __name__ == "main": if __name__ == "main":
unittest.main() unittest.main()