From 05b37ed0e392b31ef10ec7080a70a9fe084bf482 Mon Sep 17 00:00:00 2001 From: Jean Cz <3999172+janczarny@users.noreply.github.com> Date: Sun, 7 Aug 2022 17:24:16 +0200 Subject: [PATCH 01/11] Vagrant | MSG UP| Addded default Login and Password --- Vagrantfile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Vagrantfile b/Vagrantfile index af9ad85..391cb59 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -19,6 +19,13 @@ System Wyborczy v2 Panel administratora: http://localhost:8080/admin + + (Default) + Login: + admin + Pass: + haker7 + Logi: $ sw-logs From cfdb0a11d7f89a92d4c5b42da493e16a6c97343b Mon Sep 17 00:00:00 2001 From: Jean Cz <3999172+janczarny@users.noreply.github.com> Date: Sun, 7 Aug 2022 17:24:31 +0200 Subject: [PATCH 02/11] Schema Update --- sw-database/schema.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw-database/schema.sql b/sw-database/schema.sql index 70d164f..d08b33c 100644 --- a/sw-database/schema.sql +++ b/sw-database/schema.sql @@ -58,7 +58,7 @@ create table polls( -- Format: "YYYY-MM-DD hh:mm" -- Na przykład: "2022-01-01 13:30" -- Issue na zmianę typu na `timestamp with time zone`: https://github.com/informatyzacja-sspwr-projekty/SWv2/issues/10 - closes_on_date text not null, + closes_on_date timestamptz not null, -- Czy sw-mailsender wysyła maile z `sending_out_to`? mailing_active boolean default false not null, From f4ed53d89b05a6a92d15670e3b99297ac1d2380e Mon Sep 17 00:00:00 2001 From: Jean Cz <3999172+janczarny@users.noreply.github.com> Date: Sun, 7 Aug 2022 19:20:15 +0200 Subject: [PATCH 03/11] Valgrant | Msg_up --- Vagrantfile | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 391cb59..10e9410 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -4,7 +4,13 @@ $msg_up = < Date: Sun, 7 Aug 2022 19:21:57 +0200 Subject: [PATCH 04/11] #10 --- Added missing datetime 2 str format. %Y-%m-%d %H:%M --- sw-admin/sw_admin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sw-admin/sw_admin.py b/sw-admin/sw_admin.py index 5ed105c..a3dd6ca 100755 --- a/sw-admin/sw_admin.py +++ b/sw-admin/sw_admin.py @@ -233,7 +233,7 @@ def admin_copypoll(): name, options, choice_type, possible_recipients, sending_out_to, closes_on_date, mail_template, max_choices, description = row return render_template('copypoll.html', poll_id=poll_id, name=name, options=options, choice_type=choice_type, possible_recipients=possible_recipients, sending_out_to_amount=0, - closes_on_date=closes_on_date, mail_template=mail_template, should_disable=False, + closes_on_date=closes_on_date.strftime("%Y-%m-%d %H:%M"), mail_template=mail_template, should_disable=False, max_choices=max_choices, description=description) @app.route('/admin/editpoll', methods=['GET']) @@ -249,7 +249,7 @@ def admin_editpoll(): should_disable = "disabled" if sending_out_to_amount > 0 else "" return render_template('editpoll.html', poll_id=poll_id, name=name, options=options, choice_type=choice_type, possible_recipients=possible_recipients, sending_out_to_amount=sending_out_to_amount, - closes_on_date=closes_on_date, mail_template=mail_template, should_disable=should_disable, + closes_on_date=closes_on_date.strftime("%Y-%m-%d %H:%M"), mail_template=mail_template, should_disable=should_disable, max_choices=max_choices, description=description) @app.route('/admin/editpoll', methods=['POST']) From ef3fdc5c374b1d08974aa7e8f05968762aad81ec Mon Sep 17 00:00:00 2001 From: Jean Cz <3999172+janczarny@users.noreply.github.com> Date: Sun, 7 Aug 2022 19:35:13 +0200 Subject: [PATCH 05/11] Feature - Added error msg when result file / data is missing --- sw-admin/sw_admin.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/sw-admin/sw_admin.py b/sw-admin/sw_admin.py index a3dd6ca..259df8b 100755 --- a/sw-admin/sw_admin.py +++ b/sw-admin/sw_admin.py @@ -454,21 +454,28 @@ def admin_results(): return "Głosowanie nie istnieje", 400 name, options, max_choices, possible_recipients_len, sending_out_to_len, sent_to_len = row print(f"ilosc opcji :{ max_choices}") - vote_results = result_getter(poll_id, max_choices) - - voted_len = int(subprocess.Popen(['du', '--inodes', '-sS', f"/opt/sw/poll/{poll_id}/results/"], stdout=subprocess.PIPE).stdout.read().decode('utf8').split('\t')[0]) - 1 results = [] - for i, option in enumerate(options): - results.append({ 'score': vote_results.get(f"option_{i}", 0), 'name': option['name'], 'description': option['description'] }) + + try: + vote_results = result_getter(poll_id, max_choices) + + voted_len = int(subprocess.Popen(['du', '--inodes', '-sS', f"/opt/sw/poll/{poll_id}/results/"], stdout=subprocess.PIPE).stdout.read().decode('utf8').split('\t')[0]) - 1 + + + for i, option in enumerate(options): + results.append({ 'score': vote_results.get(f"option_{i}", 0), 'name': option['name'], 'description': option['description'] }) + except: + return "Nikt nie zagłosował v Brak plików", 400 + return render_template('results.html', - name=name, - possible_recipients_len=possible_recipients_len, - sending_out_to_len=sending_out_to_len, - sent_to_len=sent_to_len, - voted_len=voted_len, - results=results) + name=name, + possible_recipients_len=possible_recipients_len, + sending_out_to_len=sending_out_to_len, + sent_to_len=sent_to_len, + voted_len=voted_len, + results=results) @app.route('/admin/peek', methods=['GET']) @login_required From aa82def34d991dc4c6d664dfd7c99e2badacaea6 Mon Sep 17 00:00:00 2001 From: Jean Cz <3999172+janczarny@users.noreply.github.com> Date: Sun, 7 Aug 2022 21:54:56 +0200 Subject: [PATCH 06/11] User can't define past date & 5 min or less before end of voting. - Added error msg for sendout --- sw-admin/sw_admin.py | 24 +++++++++++++++++++++--- sw-admin/templates/sendout.html | 12 ++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/sw-admin/sw_admin.py b/sw-admin/sw_admin.py index 5ed105c..5bd43c1 100755 --- a/sw-admin/sw_admin.py +++ b/sw-admin/sw_admin.py @@ -353,10 +353,28 @@ def admin_sendout_plan_post(): if not row: return "Głosowanie nie istnieje", 400 + closeOnDate = query_db_one('select closes_on_date from polls where id=%s and owner_user=%s', [poll_id, int(current_user.get_id())]) + + timestamp = f'{request.form["planSendoutDate"]} {request.form["planSendoutTime"]}' - db_execute('set time zone \'Europe/Warsaw\'; update polls set planned_start_sending=%s::timestamptz where id=%s and owner_user=%s', - [timestamp, poll_id, int(current_user.get_id())]) - get_db().commit() + + #todo: improve name. Tired lol + beforeCloseMins = 5 + + + t1=datetime.strptime(timestamp,"%Y-%m-%d %H:%M") + t2=datetime.now() + tClose = closeOnDate[0].replace(tzinfo=None) #ByPassTMP + difCl = tClose - t1 + + if t1 <= t2: + flash("Data wysyłki jest z przeszłości") + elif difCl.total_seconds() / 60 < beforeCloseMins: + flash("Wysłanie maili musi nastapić " + str(beforeCloseMins) + " min najpóźniej przed końcem wyborów") + else: + db_execute('set time zone \'Europe/Warsaw\'; update polls set planned_start_sending=%s::timestamptz where id=%s and owner_user=%s', + [timestamp, poll_id, int(current_user.get_id())]) + get_db().commit() return redirect(f'/admin/sendout?id={poll_id}', code=303) diff --git a/sw-admin/templates/sendout.html b/sw-admin/templates/sendout.html index 05c6d65..e4b54dd 100644 --- a/sw-admin/templates/sendout.html +++ b/sw-admin/templates/sendout.html @@ -1,6 +1,18 @@ {% extends "baseloggedin.html" %} {% block title %}Rozsyłka maili dla głosowania "{{name}}"{% endblock %} {% block content %} + + +{% with messages = get_flashed_messages() %} + {% if messages %} +
+ {% for message in messages %} + + {% endfor %} +
+ {% endif %} +{% endwith %} +

Rozsyłka maili dla głosowania "{{name}}"

From 87c46c0c5893ad2bc860b1f0d16a06f7a3261ea8 Mon Sep 17 00:00:00 2001 From: Jean Cz <3999172+janczarny@users.noreply.github.com> Date: Mon, 8 Aug 2022 22:59:22 +0200 Subject: [PATCH 07/11] Unified field type for - - planned_start_sending - closes_on_date --- sw-database/schema.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sw-database/schema.sql b/sw-database/schema.sql index d08b33c..0bed59b 100644 --- a/sw-database/schema.sql +++ b/sw-database/schema.sql @@ -57,7 +57,6 @@ create table polls( -- Czas kiedy głosowanie się kończy -- Format: "YYYY-MM-DD hh:mm" -- Na przykład: "2022-01-01 13:30" - -- Issue na zmianę typu na `timestamp with time zone`: https://github.com/informatyzacja-sspwr-projekty/SWv2/issues/10 closes_on_date timestamptz not null, -- Czy sw-mailsender wysyła maile z `sending_out_to`? @@ -83,5 +82,5 @@ create table polls( -- Jeżeli wartość nie jest NULL, o danej godzinie głosowanie zostanie rozpocząte -- (między innymi ustawiając `mailing_active` na true) - planned_start_sending timestamp with time zone + planned_start_sending timestamptz not null ); From 3041367ff14f15cad36e149b3bc1f19672940db2 Mon Sep 17 00:00:00 2001 From: Jean Cz <3999172+janczarny@users.noreply.github.com> Date: Mon, 8 Aug 2022 23:37:24 +0200 Subject: [PATCH 08/11] Get Current Machine TimeZone --- sw-admin/sw_admin.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sw-admin/sw_admin.py b/sw-admin/sw_admin.py index 259df8b..54e4d4f 100755 --- a/sw-admin/sw_admin.py +++ b/sw-admin/sw_admin.py @@ -23,6 +23,9 @@ login_manager = LoginManager() login_manager.init_app(app) +#machine Timezone +machTz = datetime.datetime.now().astimezone().tzinfo + # use dicts and lists as json in postgres import psycopg2.extras psycopg2.extensions.register_adapter(dict, psycopg2.extras.Json) From cfd208c39849344c1d9dc1a6e89b84a024e4f1fd Mon Sep 17 00:00:00 2001 From: Jean Cz <3999172+janczarny@users.noreply.github.com> Date: Tue, 9 Aug 2022 23:46:14 +0200 Subject: [PATCH 09/11] [Bug] Datetime Fix --- sw-admin/sw_admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw-admin/sw_admin.py b/sw-admin/sw_admin.py index 54e4d4f..93bb5fe 100755 --- a/sw-admin/sw_admin.py +++ b/sw-admin/sw_admin.py @@ -24,7 +24,7 @@ login_manager.init_app(app) #machine Timezone -machTz = datetime.datetime.now().astimezone().tzinfo +machTz = datetime.now().astimezone().tzinfo # use dicts and lists as json in postgres import psycopg2.extras From 37b8ef392c964ad5f17ea4507211dd3556be26a3 Mon Sep 17 00:00:00 2001 From: Jean Cz <3999172+janczarny@users.noreply.github.com> Date: Tue, 9 Aug 2022 23:48:48 +0200 Subject: [PATCH 10/11] [SQL] Schema Fix (Null is default for planned_start_sending) --- sw-database/schema.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sw-database/schema.sql b/sw-database/schema.sql index 0bed59b..391ca04 100644 --- a/sw-database/schema.sql +++ b/sw-database/schema.sql @@ -81,6 +81,7 @@ create table polls( closed boolean default false not null, -- Jeżeli wartość nie jest NULL, o danej godzinie głosowanie zostanie rozpocząte + -- Przy Tworzeniu wyborów domyślnie jest NULL -- (między innymi ustawiając `mailing_active` na true) - planned_start_sending timestamptz not null + planned_start_sending timestamptz ); From cea1a3ee40fc010bba6d92abf2760a77d7ae3185 Mon Sep 17 00:00:00 2001 From: Karol Baraniecki Date: Tue, 16 Aug 2022 00:41:37 +0000 Subject: [PATCH 11/11] Trigger CI