Commit graph

149 commits

Author SHA1 Message Date
Baptiste Jonglez
0dede02133 Add missing __init__.py that may explain why CI fails 2022-04-03 00:28:08 +02:00
Glandos
a71f154354 Purge project history on deletion 2022-03-05 17:12:59 +01:00
Glandos
e355894cee
Check for too high values (#989)
* check for too high values

see https://github.com/python-babel/babel/issues/821

fix #957

* black & isort

* add API test
2022-02-02 10:09:49 +01:00
Glandos
07e1eac0a9
Null amount validator was broken (#990) 2022-01-30 16:33:18 +01:00
Peter Maksymowsky
a5452ccee5
Display admin email in error message for password reminder (#965)
Co-authored-by: Glandos <bugs-github@antipoul.fr>
2022-01-30 15:33:54 +01:00
Glandos
023ec71536
[Performance] Get weight sum along with bills to scale (#949)
* get weight sum along with bills to scale

otherwise, we need to get the weight sum for each displayed bill.
Here, we are much more scalable

* add test

* format

* remove unused import

* oops, restore pagination to 100

* add comments

* format

* rename method to make it clearer

And also, make it static, since it doesn't rely on instance.

* improve comments and naming

* improve naming

* missing article
2022-01-22 00:13:07 +01:00
zorun
c8cbe43ee2
Display monthly statistics for the range of months where the project was active (#885)
* Change the way we import datetime

This makes it easier to use datetime.date later.

* Display monthly statistics for the range of months where the project was active

Currently, we display a hard-coded "one year" range of monthly statistics
starting from today.  This generally is not the intended behaviour: for
instance, on an archived project, the bills might all be older than one
year, so the table only displays months without any operation.

Instead, display all months between the first and last bills.  There might
be empty months in the middle, but that's intended, because we want all
months to be consecutive.

If there are no bills, simply display an empty table.

Co-authored-by: Baptiste Jonglez <git@bitsofnetworks.org>
2022-01-18 14:32:43 +01:00
Youe Graillot
747824a298
CSV bills import (cospend compatible) (#951)
* proper import form (fix messy errors)
* csv compatible import
* cospend compatible import
* localization (best effort)
* refactoring
* revert localization (best effort)
* import return 400 on error
* fix Person.query.get_by_ids calls
* Bill explicit init parameters
* fix tests
* refacto tests with self.get_project
* separate import tests
* fix tests
* csv import test case
* fix import csv parsing
* revert DestructiveActionProjectForm renaming
* fix csv import test
* fix error redirection on import
* fix lint
* import file input type hint
* various fixes from review

Co-authored-by: Youe Graillot <youe.graillot@gmail.com>
2021-12-22 00:00:34 +01:00
Peter Maksymowsky
470c19fe4d
List supported currencies in API under api/currencies (#961)
* List supported currencies in API under api/currencies

* Added test for /currencies route
2021-12-13 23:25:25 +01:00
ef3944ccad
Send an email when the project is created via the API. (#938) 2021-11-25 00:49:17 +01:00
1698841f6d
Do not require a captcha when using the API (#931)
* Do not require a captcha when using the API

This was trickier than expected, due to some side effects : when the
captcha is set to `True` via configuration, it doesn't change the
behavior directly of the ProjectForm class, but does so only when the
project form is used in the `web.py` module.

So, when just using the API (and not using the web.py module, for
instance during tests — manual or functional), no problem was shown,
and everything was working properly.

But at soon as somebody sees the "/" endpoint, the captcha was
required, by both the API and the `web.py` module.

This fixes it by adding a way to bypass the captcha with a new
`bypass_captcha` property on the form.

Prior to this commit, things were done by activating or deactivating a
"captcha" property on the class on-the-fly, which caused side-effects.

This is now using subclasses, which makes the code simpler to
understand, and less prone to side-effects.

Thanks @zorun for the idea.
2021-11-25 00:44:21 +01:00
68552a6034
Allow connecting to upper-case project IDs. (#934)
Fix #933.
2021-11-23 19:09:50 +01:00
2adc2bf0be
Check that project creation via the API doesn't required a captcha. (#926)
Fixes #922
2021-11-21 17:39:42 +01:00
beac10be0b
Always authentify projects using a lowercase ID. (#925)
Fixes #920
2021-11-21 17:13:26 +01:00
35a74100cb
Rename all strings to "participants", clean old and small weird stuff (#871)
* Rename all strings to "participants".
* Update the tests with the new strings
* Update tests
2021-11-01 18:25:57 +01:00
Baptiste Jonglez
7fdb72cff8 tests: allow to choose project name independently from ID (no change by default) 2021-10-20 23:29:11 +02:00
Baptiste Jonglez
ff2a5cc147 Add API test cases related to currencies 2021-10-14 00:07:41 +02:00
Baptiste Jonglez
17b4255d82 API tests: allow to set currency, but don't set any by default 2021-10-14 00:07:41 +02:00
Glandos
7d9226745f
Change token path authentication to /PROJECT/join/TOKEN (#843) 2021-10-13 22:00:38 +02:00
2bcc41bdb3
Add optional support for a simple CAPTCHA. (#844)
* Add optional support for a simple CAPTCHA.
* formatting
* add test case
* Flake8

Co-authored-by: Glandos <bugs-github@antipoul.fr>
2021-10-11 17:39:24 +02:00
zorun
7554842b1f
Add URL validation to external link to prevent XSS (#846)
Co-authored-by: Baptiste Jonglez <git@bitsofnetworks.org>
2021-10-10 18:39:03 +02:00
Glandos
bbe00ebb57
Include project code into project authentication token (#802)
Fix #780 

This a breaking change, the API for authentication is different, as it now requires `project_id`. Token is generated with only the project_id (so it's shorter than before), and signature is done by mixing password with secret key. Thus, it expires on every project code change.
2021-10-10 14:43:40 +02:00
Daniel Neto
60149cd486 Formatting changes after running make black 2021-09-19 19:04:49 +02:00
Daniel Neto
7bf7db24bd #838: Add decima weight round test cases 2021-09-19 19:04:49 +02:00
Baptiste Jonglez
011df29913 Simplify exception checking in import test 2021-09-07 23:15:40 +02:00
Baptiste Jonglez
7ad83c7e79 Add more import test cases related to currencies 2021-09-07 23:15:40 +02:00
Baptiste Jonglez
4bf9308908 Add currency to import and export formats 2021-09-07 23:15:40 +02:00
Baptiste Jonglez
6448d0d7df Move CurrencyConverter mocking to the base test class
This mock was already applied to all tests, because it was done statically
in the TestCurrencyConverter class definition.  But it was really not
clear that it's applied everywhere.

Moving this to the setUp() function makes it much clearer.

Also, remove useless redefinition in other tests.
2021-09-07 23:15:40 +02:00
Baptiste Jonglez
da49012d58 Add test cases to ensure we can't delete objects with a GET 2021-07-17 13:54:11 +02:00
Baptiste Jonglez
255aacefb3 Fix tests for history deletion 2021-07-17 13:54:11 +02:00
Baptiste Jonglez
95b2cf870b Fix test for project deletion 2021-07-17 13:54:11 +02:00
Baptiste Jonglez
109d7fca17 Add CSRF validation to most disruptive actions
This also switches all such actions to POST requests.

Deleting the project is handled in another commit because it requires more
changes.
2021-07-17 13:54:11 +02:00
Baptiste Jonglez
2e4bb0ec8c tests: ensure that /tmp/ihatemoney.db does not get overwritten
Most of the tests are using a separate database, but we have a few tests
that are loading default values and are writing to /tmp/ihatemoney.db.

This is annoying because it's also the database used for development:
running the test suite breaks the dev database.

To fix this, always use a separate testing database to avoid interference.
2021-07-14 10:36:39 +02:00
Andrew Dickinson
72230448a7
Improve localization on the History page using string replacement (#587) 2021-07-12 22:48:19 +02:00
Baptiste Jonglez
7ceb66f01b Enable CI builds with postgresql and mariadb 2021-07-10 00:39:54 +02:00
Baptiste Jonglez
33aad60352 Clarify that the test config files are not used for all tests... 2021-07-10 00:39:54 +02:00
Glandos
07b86bc580
Rework currency switching (#661)
Co-authored-by: Alexis Métaireau <alexis@notmyidea.org>

Currency switching is both simpler and less powerful. This was done primarily for users, to have a clear and logical understanding, but the code is also simpler. The main change is that it is now forbidden to switch a project to "no currency" if bills don't share the same currency.

Also, tests assume that projects are created without currency, as in the web UI.
2021-07-06 21:51:32 +02:00
Glandos
27d95f2d01 fix flake8 2021-06-10 00:09:59 +02:00
Glandos
c62965d4bf fix basic deprecation warnings 2021-06-10 00:09:59 +02:00
Glandos
44fa1af375 change method to find login_throttler
that was triggering a lot of deprecation warnings due to
iterating over all known objects.
2021-06-10 00:09:59 +02:00
Glandos
859aa8fb1e
Fix test for generate_hash_password (#766)
Use the function that check password instead of just checking the output length. This length can be variable and will change with Werkzeug 2
2021-06-07 23:11:38 +02:00
Glandos
74e222f1a1 remove usage of Flask-Script
Use flask.cli instead with compatibility layer for existing commands,
such as "runserver".
2021-06-06 15:13:21 +02:00
Miguel Victoria Villaquiran
18068d76ca
Simplify tests (#685)
Fix #501
2021-01-05 22:17:26 +01:00
Glandos
58e5eca270
update to black 20.8b1 (#676)
Some trailing commas were removed because of some black changes.
2020-08-27 22:09:04 +02:00
Baptiste Jonglez
eb441a1de9 Fix test location
The test for CVE-2020-15120 was mistakenly added to the HistoryTestCase
class, where it does not belong.
2020-07-26 19:32:50 +02:00
Baptiste Jonglez
b8f7ce34dd Add test case for CVE-2020-15120 2020-07-26 19:21:16 +02:00
Daniel Atwood
0fd2958865
Populate the demo project with defaults. (#616) 2020-05-24 11:45:34 +02:00
zorun
df6ffc7d86
Improve error handling when sending emails (#595)
In one case, we were not catching a family of possible exceptions
(socket.error), and in the two other cases there was no error handling at
all. Sending emails can easily fail if no email server is configured, so
it is really necessary to handle these errors instead of crashing with a
HTTP 500 error.

Refactor email sending code and add proper error handling.

Show alert messages that tell the user if an email was sent or if there
was an error.

When sending a password reminder email or inviting people by email, we
don't proceed to the next step in case of error, because sending emails is
the whole point of these actions.
2020-05-21 21:13:33 +02:00
Glandos
ca7c3d5452
use currency format everywhere (#619)
This should unify the number formats, along with #618
2020-05-10 23:05:48 +02:00
zorun
795efd6b58
Fix order of participants in the statistics page (#608)
This fixes #607 and add a test case for this bug.

It also renames participants in test cases to avoid alphabetical ordering.

Inserting participants in alphabetical order is a special case, because ordering by ID will be the same as ordering by name. This is a bad idea in test cases, as #607 has shown.
2020-05-04 23:06:35 +02:00
dark0dave
f389c56259
Feature/currencies (#541)
Now each project can have a currency, default to None.
Each bill can use a different currency, and a conversion to project default currency is done on settle.

Fix #512
2020-04-29 22:57:08 +02:00
zorun
d9dc38947c
Fix string representation of bills (#584)
Currently the string representation of a Bill is: "<amount> for <description>"

It is used in the History Page to describe changes that were applied to
Bills, for instance:

    Bill "42.0 for Test" renamed to "Another Test"

This is inconsistent, not easy to read, and the "for" in the middle is not
translatable.

To solve this issue, simply switch the string representation of a bill to
its description.

Co-authored-by: Baptiste Jonglez <git@bitsofnetworks.org>
2020-04-26 14:22:54 +02:00
zorun
d6d084f26a
Fix translations (#575)
* Fix user-facing string and update translation catalog

In the flash message confirming member creation, change "member had been
added" into the correct form "member has been added".

No translation has been changed.  Some translators seem to have already
spotted the mistake while translating, but I can't tell for all languages.

* Change "Person" to "Participant" in history view

Currently, the main user-facing term is "Participant", as seen for
instance in the "Add participant" form.  "Person" is not used anywhere in
the interface.

See #302 for a more general discussion on choosing the right terminology.

* Fix obsolete translations.

Co-authored-by: Baptiste Jonglez <git@bitsofnetworks.org>
Co-authored-by: Rémy HUBSCHER <hubscher.remy@gmail.com>
2020-04-25 11:55:20 +02:00
Rémy HUBSCHER
7587e292fb
Remove obsolete python code (<3.6). (#571) 2020-04-24 12:32:52 +02:00
Rémy HUBSCHER
299c64a48c
Add isort support. (#561) 2020-04-21 13:59:41 +02:00
Andrew Dickinson
026a072235
Add Project History Page (#553)
Co-Authored-By: Glandos <bugs-github@antipoul.fr>

All project activity can be tracked, using SQLAlchemy-continuum.
IP addresses can optionally be recorded.
2020-04-20 15:30:27 +02:00
Glandos
5ec3dc0acc
Align tables in statistics (#535)
* Align tables in statistics

The table in sidebar is now aligned with the one in content, to avoid
redundant informations.
All tables are back to normal on small devices.

* fix test

* run black on tests
2020-02-20 09:43:50 +01:00
DavidRThrashJr
32d76178c0
Use SQL statement for summing up weights
* Update models: Bill.pay_each()
* Import sql func
* reformatted using black
* Added ModelsTestCase.test_bill_pay_each() in order to test the SQL query change within pay_each.
Had to add Project.ProjectQuery.get_by_name() for the test.
2020-02-17 18:39:51 +01:00
James Leong
1f62f18154 Statistics view #323
Remove header and table column of 'Balance' in statistics view
2020-02-08 23:17:02 +01:00
Nicolas Vanvyve
9aa7e62d0f Import previously exported json data (#518)
Fix #417 

* New tab upload

* Extract data from JSON

* Add users

* Black format

* Try to add bill

* Import bills

* Add french translation msg

* Black reformat missing

* Deactivated users are supported

* Test import

* Remove temp file in upload_json()

* Incomplete tests

* tests import

* Update ihatemoney/translations/fr/LC_MESSAGES/messages.po

Co-Authored-By: Rémy HUBSCHER <hubscher.remy@gmail.com>

* Remove useless variable and check json format

* Use String.IO and test for wrong json

* Remove coma

Co-authored-by: Rémy HUBSCHER <hubscher.remy@gmail.com>
2020-01-13 21:17:55 +01:00
John-Michael Reed
73a4d139ff Fixed typos in tests.py (#521) 2019-12-29 20:34:04 +01:00
José Antonio de la Torre
b683d062f0 Token support (#504)
Added API support to generate authentication tokens, at `/api/projects/:id/token`
2019-10-25 11:17:54 +00:00
José Antonio de la Torre
a50d54d5da typo 2019-10-19 12:30:31 +02:00
José Antonio de la Torre
28440d15ab Added test 2019-10-19 12:30:31 +02:00
f260a2c9e7 Use black to refomat the files. 2019-10-14 21:20:38 +02:00
480939afe5 Remove support for python2.
In the same move :
- use a setup.cfg file for packaging
- remove the use of six
2019-10-11 19:52:37 +02:00
Leo Mouyna
b70476cf8f fix unit tests 2019-10-03 18:15:50 +02:00
Alexis Métaireau
82d94a7490 Trim member usernames. Fixes #353 2019-09-27 23:36:25 +02:00
74c51be5a3 Fix #434 Use the debts lib to solve settlements. 2019-09-24 21:25:06 +02:00
01cf56559b Update requirements.txt 2019-09-06 23:59:05 +02:00
Brice Maron
9c9832704d bill list: add placeholder and disable add bill when no members 2019-09-06 22:00:39 +02:00
Brice Maron
0edf8634a4 Move export form to links 2019-08-26 19:59:55 +00:00
d55b996170
Do not allow negative weights on users (Fixes #362) (#366) 2019-01-03 13:29:56 +01:00
Byron Ullauri
04adfe4155 Provide basic math operations on bills (#413)
* allow basic math ops in amount field for bills form
* docs: changing compile-translations to build-translations
2019-01-03 10:03:13 +01:00
Byron Ullauri
7cb339c0bb Resolve "Update API project list" (#409)
* refactoring models _to_serialize property

* updated project api members list

* addressing flake8: line too long
2018-12-26 19:07:09 +01:00
620596e32c
Add CORS to the API. Fix #404 (#407) 2018-12-25 18:13:58 +01:00
Lucas Verney
0428cf06b5 Add bill.creation_date field (#327) 2018-12-25 16:50:14 +01:00
c34583d079
Add a ihatemoney delete-project command. (#375) 2018-09-03 20:55:44 +02:00
Glandos
c1b5eb1375 Remove strict_slashes for /
I don't know why, but on my setup (nginx + uwsgi), the `strict_slashes` (default to `True`) was causing an infinite loop.
I think it could be safely removed for this route only.
2018-08-05 14:57:55 +02:00
Jocelyn Delalande
b95ea7f4e6 Add statistics support to API 2018-02-07 00:06:08 +01:00
Jocelyn Delalande
b1a4572e8c Change statistics data structure
Clearer data structure, and simpler template

This commit has a side effect: sidebar now hides disabled members.

IMHO, the disabled members should either be hidden or shown consistently between
sidebar and central table. Previous status was: shown in sidebar (if balance ≠
0) and hidden in central table.
2018-02-07 00:01:13 +01:00
0livd
b93ea4830d API: Migrate from flask-rest to flask-restful (#315)
The flask-rest custom json encoder is still needed
and thus was added to ihatemoney's utils.

Closes #298
2018-01-25 17:41:28 +01:00
JocelynDelalande
2019b398f1 manage commands testing (#313)
* Rename manage.ConfigTemplate → manage.GenerateConfig

To be consistent with the CLI name: `generate-config`.

* Add tests for manage.py commands

* Run tests from pip-installed package

To be able to detect packaging-related issues on test runs.

refs #305
2018-01-07 00:27:42 +01:00
JocelynDelalande
c002cdbf94 Allow to disable/enable member via API (#301)
Disable was already (kind-of) possible via API via DELETE, but not re-enabling.

Kudos to @almet for helping me fixing that damn BooleanField :-)
2017-12-29 18:07:39 +01:00
Jocelyn Delalande
40e5a833a1 Fix tests layout so that API tests are not ran twice
Bad inheritance was causing APITestsCase tests to be ran twice.
2017-12-27 23:27:41 +01:00
9fea0ffe2c Add tests for #294 2017-12-27 17:06:46 +01:00
JocelynDelalande
4d359ce11b Fix PUT api/project/:code/members/:id (#297)
* Fix PUT api/project/:code/members/:id

Before that commit, every PUT *must* change the name of the members, so that was :
- no idempotence,
- no ability to change only weight

fix #295

* Remove redundant comment
2017-12-27 15:58:40 +01:00
JocelynDelalande
b65ee59b1b Remove API password (#290)
* Remove the password from API GET responses

While keeping it for POST/PUT.

fix #289

* Add a test to check password change via API
2017-12-22 17:39:48 +01:00
0livd
c6f72e112b Use hashed passwords for projects (#286)
- Remove all occurences of clear text project passwords.
- Migrate the database to hash the previously stored passwords.
Closes #232
2017-12-21 13:57:01 +01:00
0livd
8a68ac0d5b Use token based auth in invitation e-mails (#280)
* Use token based auth in invitation e-mails

Invitation e-mails no longer contain the clear
text project password

* Skip invite page after project creation

- Replace ``The project identifier is demo, remember it!``
by ``Invite other people to join this project!``
(linking to the invite page)
- Encourage users to share the project password via other
communication means in the reminder email
2017-12-15 17:10:28 +01:00
Alexandre Avenel
2866c868d5 Fix some typos using codespell (#285) 2017-11-11 18:11:15 +01:00
0livd
b94bad829c Use token based auth to reset passwords (#269)
Send a mail containing a password reset
token link instead of sending a clear text
password.

Ref #232
2017-10-26 19:46:34 +02:00
0livd
293735eca7 Make authentication logic simpler and safer (#270)
* Fixed exposed password in session

The project password was set in clear text
in the session cookie. The cookie payload is
only base64 encoded so it must not be used to
store private information. The password is
simply replaced by a boolean.

* Simplify authentication logic
2017-10-23 23:03:44 +02:00
0livd
7a918c9349 Enhance the dashboard. (#262)
* Update to a more flexible admin authentication
* Admin can now access any project
* Add delete and edit options in the dashboard
* Add a link to the dashboard in the nav bar

This is a rework of the changes proposed by @Olivd, so they can apply on top of
the latest master without trouble. All credit goes to him for the code.
2017-09-04 15:44:20 +02:00
0livd
2ec4fb589f Add a statistics tab (#257) 2017-08-21 23:51:32 +02:00
0livd
ec4a099f18 Protect admin endpoints against brute force attacks (#249)
* Protect admin endpoints against brute force attacks

Add a throttling mechanism to prevent a client brute
forcing the authentication form, based on its ip address
Closes #245

* Reset attempt counters if they get memory hungry
2017-08-20 12:37:12 +02:00
0livd
c7815e4878 Fix #248: Database creation issue (#254)
In flask's development server, the route handlers
run in a different thread than the main thread
thus an in-memory database created in the main thread
cannot be acccessed by the route handlers.
Switching the default database location to a temporary
file solves the isssue.

See full explanation here:
https://gehrcke.de/2015/05/in-memory-sqlite-database-and-flask-a-threading-trap/
2017-08-06 04:06:21 +02:00
0livd
8fd53f827e Revert configuration tests deletion (#250)
Some supernatural power erased the configuration
tests, they're now back !
2017-07-09 22:29:57 +02:00
3a4282fd75 Absolute imports & some other improvements (#243)
* Use absolute imports and rename package to ihatemoney
* Add a ihatemoney command
* Factorize application creation logic
* Refactor the tests
* Update the wsgi.py module with the new create_app() function
* Fix some styling thanks to Flake8.
* Automate Flake8 check in the CI.
2017-07-07 00:06:56 +02:00