23 Commits

Author SHA1 Message Date
James Valleroy
4b90e7618f
middleware: tests: Add tests for common error middleware
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2023-09-22 11:20:08 -07:00
Sunil Mohan Adapa
4cb1477c0d
setup: Drop setup_helper and use the new Operation API
- Task of managing an operation's progress is now performed by the new Operation
class. Drop them from setup helper.

- Task of providing install() method is now moved to package module. Instead of
storing operation specific data in setup_helper like objects, store them in
thread specific storage that can retrieved anywhere during the operation without
holding references.

- Progress of an operation show as a progress bar is currently missing. This
will be regression until fixed later.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-15 10:36:32 -04:00
James Valleroy
b43e42ac7a
tests: Add a dummy parameter for middlewares
From the Django 4.0 release notes: The get_response argument for
django.utils.deprecation.MiddlewareMixin.__init__() is required and
doesn’t accept None.

It appears that any non-None value can be used here, so I pass in
`True` when initializing middlewares for tests. I don't know if this
was the intended value, but it does fix the tests.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2022-06-20 10:40:48 -07:00
Sunil Mohan Adapa
528fd08245
middleware, views: Reduce use of setup_helper
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-12-04 16:38:17 -05:00
Sunil Mohan Adapa
cf36a9d385
*: Drop use of module level is_essential flag
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-12-04 16:37:59 -05:00
Sunil Mohan Adapa
b609abe7e5
*: Use the App's state management API
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-12-04 16:37:40 -05:00
Sunil Mohan Adapa
b0e3aaa356
middleware: Don't show setup view to non-admin users
This is an improvement over !2069, which solved #2094.

Tests:

- Install an app. Success result is shown.

- Install an app and kill the apt-get process in the middle. Error result is
shown.

- Click install on an app (email_server). Close the window without seeing the
result. Access the app page (like email_server/my_aliases) as a non-admin user.
No success/file message is shown. The page is shown properly. Access the page as
admin, success message is shown.

- Access an uninstalled/installed app page as anonymous user. User is redirected
to login page.

- Access an uninstalled/installed app page as non-admin user. Forbidden page is
shown.

- Access an uninstalled app page meant for non-admin users (such as
email_server/my_aliases) as non-admin user. Forbidden page is shown.

- Access an installed app page as admin. Success.

- Access an installed app page meant for non-admin users (such as
email_server/my_aliases) as admin. Success.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>

Reviewed-by: Fioddor Superconcentrado <fioddor@gmail.com>
2021-10-16 20:56:23 +02:00
Joseph Nuthalapati
377010b078
openvpn: Deny access to users not in group "vpn"
A new function called `user_group_view` has been added to
restrict access to only users in the groups "vpn" and "admin".

Some changes are made in AdminRequiredMiddleware to handle this.

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-11-25 13:15:22 -05:00
Sunil Mohan Adapa
9368504da5
*.py: Use SPDX license identifier
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-02-19 14:38:55 +02:00
Alice Kile
eb83e00011
fix formatting issues
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-12-07 13:08:35 -05:00
Sunil Mohan Adapa
13ed080003
middleware: Convert tests to pytest style
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2019-05-12 17:16:31 +05:30
Michael Pimmer
425f7fbd92
Adapt test and documentation to changes of '--develop' option
And re-activate cfg.get_config_paths() for easier testing

Signed-off-by: Michael Pimmer <info@fonfon.at>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-06-18 19:27:31 -04:00
James Valleroy
2ea575806d
middleware: Skip 'installed' message for essential apps
Closes #1085.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2018-04-09 19:10:49 +05:30
Sunil Mohan Adapa
8f4811b350
Rename Plinth to FreedomBox in more module doc strings
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-02-16 20:10:31 -05:00
Sunil Mohan Adapa
dea4af17fb
Rename Plinth to FreedomBox in license headers
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-02-16 20:10:09 -05:00
Johannes Keyser
6c5953e8c2
utils: Fix test case failures due to caching (Closes: #813)
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2017-04-30 08:35:29 +05:30
Sunil Mohan Adapa
3e8caab08a
middleware: Refactor tests to avoid repetition 2017-02-15 21:07:35 +05:30
Sunil Mohan Adapa
dd5ab7612e
Minor refactoring and lint fixes
- Rename AdminMiddleware to AdminRequiredMiddleware to be consistent
  with stronghold/Django terminology

- Simplify .gitignore pattern

- Format single line docstrings as per PEP8.

- Add missing docstrings.

- Restrict lines to 79 characters.
2017-02-15 21:07:27 +05:30
lispyclouds
3b23f78bdc
Implement middleware for admin views
- Add AdminMiddleware to deny non admin users
- Add decorator to mark views as "non admin"
2017-02-15 20:57:52 +05:30
Sunil Mohan Adapa
b7a974e326
setup: Fix an infinite redirect in a rare case
Don't try to show setup view for login page.  This happens under a rare
circumstance that user does not usually face.  If 'users' module has not
been setup but we try to run first boot and last part of the firstboot
process is not yet completed and when user is not already logged in, an
infinite redirect happens.

Simply don't try to show setup view for login URL under any
circumstance.  This is similar to how firstboot middleware itself does
not meddle with login URL.
2017-01-19 18:46:06 -05:00
fonfon
eda3488bea
Updated tests about accessing the setup page
- anonymous users should not be able to access the setup page
- registered should be able to do so
2016-12-28 19:35:11 -05:00
Sunil Mohan Adapa
18996b5c56
Import urlresolvers from django.urls
In Django 1.10, django.core.urlresolvers is available from
django.urls. Use it.
2016-08-11 18:03:00 -04:00
Sunil Mohan Adapa
4986d26b5d
middleware: Add tests for setup middleware 2016-06-02 20:13:44 -04:00