Commit Graph

107 Commits

Author SHA1 Message Date
Akihiro Motoki d9266fd82c Address RemovedInDjango40Warning (3)
In Django 3.1, django.conf.urls.url() is deprecated
in favor of django.urls.re_path().

https://docs.djangoproject.com/en/4.0/releases/3.1/#id2

Change-Id: I484694f8718f61c022126a1935cf28fce075894b
2022-02-04 16:26:54 +09:00
Akihiro Motoki cd7c1b5110 Address RemovedInDjango40Warning (2)
django.utils.translation.ugettext(), ugettext_lazy(), ugettext_noop(),
ungettext(), and ungettext_lazy() are deprecated in favor of the
functions that they’re aliases for: django.utils.translation.gettext(),
gettext_lazy(), gettext_noop(), ngettext(), and ngettext_lazy().

https://docs.djangoproject.com/en/4.0/releases/3.0/#id3

Change-Id: I77878f84e9d10cf6a136dada81eabf4e18676250
2022-02-04 16:22:07 +09:00
Zuul c056b95755 Merge "import "collections.abc" explicitly" 2021-03-05 09:30:12 +00:00
manchandavishal 6efaee23d5 import "collections.abc" explicitly
Collections Abstract Base Classes have been moved to the
collections.abc module, which was part of the collections
module before[1] [2]. Usage from the collections module
directly is deprecated and will be removed from 3.10.
This commit updates to import abc module explicitly
wherever required as the same will no longer be visible/directly
used from the collections module.

[1] https://docs.python.org/3/library/collections.abc.html
[2] http://paste.openstack.org/show/802512/

Change-Id: I173f4d647474c21c5d062280bd5703edffb4978e
2021-03-04 18:47:37 +00:00
YuehuiLei 87f498bee5 Drop the usage of unicode prefix from unicode strings
All strings are considered as unicode strings in python 3,
so we no longer need "u" prefix (u'...').

Co-Authored-By: Akihiro Motoki <amotoki@gmail.com>
Change-Id: I796d2fcdca066475bbf29d25cbf2aa67b2b2178b
2021-02-12 13:05:27 -06:00
Akihiro Motoki e5d09edc20 Use python3-style super()
In python3, super() does not always require a class and self reference.
In other words, super() is enough for most cases.
This is much simpler and it is time to switch it to the newer style.

pylint provides a check for this.
Let's enable 'super-with-arguments' check.

NOTE: _prepare_mappings() method of FormRegion in
openstack_dashboard/test/integration_tests/regions/forms.py is refactored.
super() (without explicit class and self referece) does not work when
a subclass method calls a same method in a parent class multiple times.
It looks better to prepare a separate method to provide a common logic.

Change-Id: Id9512a14be9f20dbd5ebd63d446570c7b7c825ff
2020-10-15 14:37:20 +09:00
Akihiro Motoki 692778f8cf pylint: Address no-else-return warning
This pylint check 'no-else-return' might be debatable.
but as far as I checked it works in most cases.

Change-Id: Ie8574d4a529454c6e050fa62a7a17ea097d00240
2020-09-27 12:44:16 +09:00
Akihiro Motoki b67ad564c4 pylint: Address no-else-continue/no-else-raise warnings
Change-Id: I1d44c1bf564cf02908113a42b98e06057e993ec7
2020-09-27 12:44:16 +09:00
Andreas Jaeger 50f08a8ae1 Fix docs build
Sphinx 3.0.1 complains with:

  horizon/horizon/base.py:docstring of horizon.Panel:33:duplicate object
  description of horizon.Panel.nav, other instance in contributor/ref/horizon,
  use :noindex: for one of them

Fix the two problem.

Change-Id: I98b6212c29dc66cc83a4c337771039796d939561
2020-04-13 15:52:42 +02:00
Jacek Tomasiak e4fd69292c Authenticate before Authorization
When user is not logged in and given Dashboard has some `permissions`
defined, `require_perms` decorator was raising `NotAuthorized('You are
not authorized to access %s')` instead of `NotAuthenticated('Please log
in to continue.')`.
This was caused by the order of decorating the views. The decorator
which is applied last is called first in the chain as it wraps the
decorators which were applied before.
This means that to check for authentication before checking permissions
we need to apply the `require_auth` decorator after `require_perms`.

Closes-Bug: 1869708
Change-Id: I94d3fa5c1472bb72c9111cab14c6e05180f88589
2020-03-30 13:49:10 +02:00
Ivan Kolodyazhny 1fc70d7504 Remove python_2_unicode_compatible usage
Since we don't support Python 2 anymore, we don't need
to use python_2_unicode_compatible decorator.

Change-Id: I2aafc8d07ba95571b381ff65ba9e5c0044e2d959
2020-03-09 14:54:07 +02:00
Akihiro Motoki ac3d139c06 Cleanup python 2.7 handling logic
We have several codes to handle the differences between py2 and py3.
py2 support has been dropped so there is no need for them now.

Change-Id: I30080f4e1a5ac04860c4341d966ee53131eb2022
2020-02-21 09:02:37 +09:00
Stephen Crawley a95398d012 Manually registering 2 Dashboards breaks get_dashboards() (python3)
The get_dashboards() method used sorted(<values>) to sort the
dashboards that have been registered manually.  This breaks if
two or more are registered that way because the Dashboard class
doesn't define a natural ordering.  The fix is to sort using
the Dashboard name as the sort key.  (Unit test included.)

This problem doesn't occur in python 2.7.

P.S.
It turns out that AdminPanel in horizon/test/unit/test_base.py is not
used during the review. It is dropped too as it is a simple change.

Change-Id: I6be10a92a1f43b3e0effee8148987c7e2c5690ff
Closes-bug: #1836295
2020-01-29 14:42:36 +09:00
Ivan Kolodyazhny e976461d85 Remove six usage from horizon package
We don't support Python 2 anymore so we don't need this
compatibility library.

six.reraise usages are left as is until it'll be moved to some
base lib like oslo.utils to not re-implenent this method in
Horizon.

This patch also removes Python2-specific base test case methods
assertItemsEqual and assertNotRegexpMatches in flavor of new
Python 3 analogues.

Change-Id: I0b567382edf4d68674a7b8d0b02333fb57293958
2020-01-15 12:36:11 +02:00
Stephen Finucane 4ece14b28a Handle move of ABCs to collections.abc
Resolves the following warning:

  DeprecationWarning: Using or importing the ABCs from 'collections'
  instead of from 'collections.abc' is deprecated, and in 3.8 it will
  stop working

Change-Id: Ib2214e7560cda1ef510c08859d5ee0726eb66b7b
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2019-09-10 19:21:20 +09:00
Akihiro Motoki c076db20c8 pylint: fix len-as-condition warning
Change-Id: Ib89c1854ad42b96e4caf281160d568fe98430afe
2019-01-16 12:56:20 +09:00
Akihiro Motoki 6ce323307d pylint: fixes several errors
openstack_dashboard/hooks.py:16:0: E0611: No name 'command' in module 'distutils' (no-name-in-module)

openstack_dashboard/dashboards/project/networks/ports/sg_base.py:52:12: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
BaseSecurityGroupsAction._get_initial_security_groups() is now marked
as abstract method because this method must be implemented in subclasses.
BaseSecurityGroupsAction.handle() is now dropped because there is
no difference from the parent class (horizon.workflows.Action).

openstack_auth/views.py:211:4: E1206: Not enough arguments for logging format string (logging-too-few-args)
openstack_auth/views.py:269:8: E1206: Not enough arguments for logging format string (logging-too-few-args)
openstack_auth/plugin/base.py:237:20: E1206: Not enough arguments for logging format string (logging-too-few-args)

horizon/base.py:166:24: E1133: Non-iterable value self.policy_rules is used in an iterating context (not-an-iterable)
horizon/tabs/base.py:489:40: E1133: Non-iterable value self.table_classes is used in an iterating context (not-an-iterable)

Change-Id: I0b045d04af251854b5017c9f698e3b40503a0724
2019-01-16 00:00:07 +09:00
Akihiro Motoki f3bd271fc9 pylint: fix bad-super-call
Change-Id: Ia81e5c8b77dbfcb48630b1736d581cdff73278ef
2019-01-15 01:11:33 +09:00
manchandavishal c02b9fc2dd Get rid of keys() usage
for x in some_dict.keys() can be written as for x in some_dict

Change-Id: If5436647a30c02d0dab7daa23b2290456c66d654
2018-11-30 11:15:27 +00:00
Shu Muto f494c6f2d4 Fix Angular errors in openstack_auth
Angular errors on login page are caused by loading ngdetails view.
Although registration of URL for ngdetails is executed on top level
of Horizon, ngdetails view is not needed to be loaded in login page,
i.e. openstack_auth side.
To fix this issue, this patch moves registration of URL for ngdetails
into openstack_dashboard side.

Change-Id: Ib039417b4e666c2341f17ac05fd7723bc758816c
Closes-Bug: #1754133
Closes-Bug: #1753557
2018-03-17 18:36:01 +09:00
Akihiro Motoki a72963bdbd Drop Django <= 1.10 support
After Django 2.0 support, we no longer supports Django 1.10 or older
(Actually Django 1.10 seems to work though).
The current django.VERSION branches are all related to Django 1.10
or older, so we can drop all conditions.

py35dj20 job is now voting.

blueprint django2-support
Change-Id: Iefc0ab1c62c82f2842ec7761a9b981da9351cbd2
2018-03-03 07:33:23 +09:00
Akihiro Motoki 18684e1ff5 django2: Fix 3-tuple ImproperlyConfigured error
https://docs.djangoproject.com/en/2.0/releases/1.9/#passing-a-3-tuple-or-an-app-name-to-include

blueprint django2-support
Change-Id: Ifb9b7501363fe8a3ef417498e0932323240a6dcd
2018-03-03 07:20:43 +09:00
Akihiro Motoki e477eafa45 django2: Replace django.core.urlresolves with django.urls
(In Django 2.0) The django.core.urlresolvers module is removed
in favor of its new location, django.urls.
It was depreacted in Django 1.10:
https://docs.djangoproject.com/en/2.0/releases/1.10/#id3

blueprint django2-support
Change-Id: I46ab5c325491274b8eaffbf848e5d80f83c2fd26
2018-02-17 01:36:48 +09:00
Zuul 233a12a514 Merge "Enable to refresh ngdetails view" 2018-02-05 11:36:46 +00:00
David Gutman 3f585d3b1e Views accessible via url even if user doesn't match policy rules
When a user doesn't match the policy rules of a panel then the panel tab
is removed from the menu of the left, but panel views are still
accessible using directly the url (ex /admin/flavors/).

In most of the case, views won't work correctly because of the lack of
right in the backend, but it may cause trouble when you play with
policies.

I think it could be more elegant to return directly a "You are not
authorized to access this page" from the frontend when user try to
access a view of a panel (via url) without matching the policy rules.

Change-Id: I7bc93fed29568adfc14d5bcadfc8728d3b5cf633
Closes-Bug: #1741051
2018-02-02 21:24:33 +09:00
Shu Muto 077163a03c Enable to refresh ngdetails view
For now, refreshing ngdetails view by browser using F5 key or reload
button, it causes 404 error from django. To fix this issue, this patch
adds the url for '/ngdetails' into django.

To reproduce navigations, each request for views.py requires
'dashboard' and 'panel' object. Otherwise django side returns
500 error.

However the URL for request of details page (i.e. /ngdetails/)
can not provide informations to set the proper navigation.

So this patch set them to default dashboard and default panel.

This patch focuses to prevent 500 error. So the issue for
settings of proper navigation will be fixed by subsequent patch.

Change-Id: Ib9f1fe48b3cdecff5ad56e68a5ba58a41cb35f38
Closes-Bug: #1681627
2018-02-01 20:30:03 +09:00
Luigi Toscano 2e4ce7684b Revert "No need to discover panel in Site class"
As discussed on IRC, reverting temporarily as it breaks sahara-dashboard. 
sahara-dashboard requires few changes (moving away from dashboard.Project.register to load the panels) before this can be applied.

This reverts commit fb39de18e4.

Change-Id: I0a77c7ad34c399e4a40cf8b55307be72ff7fe7e0
2017-09-21 10:46:12 +00:00
chao liu fb39de18e4 No need to discover panel in Site class
Panel discovery is done by the _audodiscover() method in
the Dashboard class later

Change-Id: I0261a3cd9ad411185ab68ef4ae3b35a8d7ae3b23
Closes-Bug: #1717149
2017-09-18 08:17:32 +00:00
Shu Muto 55162ef614 Add reason into warning for error on loading panel
For now, detailed information about failure on importing panel
module is not shown in warning log. This patch adds information
into warning log why error occured. This clarify the reason the
problem in importing panel/plugins.

Change-Id: Ie3aa725a1bfc81fb7d56a0b195475b8deaa84375
2017-09-07 16:50:37 +09:00
Rob Cresswell c16ceb149c Revert "Enable to refresh ngdetails view"
This reverts commit fe0df4579c.

Change-Id: I017f27ad1e8833465d6727118019b78ade4c04d6
2017-08-02 18:31:22 +00:00
Shu Muto fe0df4579c Enable to refresh ngdetails view
For now refreshing ngdetails view by browser using F5 key or reload
button, it causes 404 error from django. To fix this issue, this patch
adds the url for '/ngdetails'.

Furthermore, to specify current navigation and to check access grants
to current panel, each access to Horizon django framework needs its
dashboard and panel objects. It means that we need to specify dashboard
and panel that ngdetails view belongs to.

Also, this patch adds the process and settings to specify dashboard and
panel object for each ngdetails view.

Change-Id: I4bcffd2e222ce2df186551cceba0aa38f600d9c8
Closes-Bug: #1681627
2017-07-27 11:31:33 +09:00
Akihiro Motoki e6b78f92f2 Use flake8-import-order plugin
In reviews we usually check import grouping but it is boring.
By using flake8-import-order plugin, we can avoid this.
This flake8 plugin is already used in tempest.
It enforces loose checking so it sounds good to use.

Note that flake8-import-order version is pinned to avoid unexpected
breakage of pep8 job.

Change-Id: I8ccd05eb70350a2441cc2a4d1eafc09ee690b83b
2017-07-03 08:02:23 +00:00
Akihiro Motoki 95629a337e Fix H405 (multi line docstring) warnings (horizon)
H405: multi line docstring summary not separated with an empty line

Partial-Bug: #1696996
Change-Id: I58f71206def1a25f3eda04b9297f1aa7d3caa646
2017-06-09 16:04:57 +00:00
Gábor Antal 34a3aa0ba8 Handle log message interpolation by the logger
According to OpenStack Guideline[1], logged string message should be
interpolated by the logger.

[1]: http://docs.openstack.org/developer/oslo.i18n/guidelines.html#adding-variables-to-log-messages
Change-Id: I51f50935f1eeffe4960562d6309dfdf05814e595
Closes-Bug: #1596829
2017-03-31 20:59:16 +09:00
Akihiro Motoki 61091388e9 hacking: noqa cleanup in horizon
attribute-level imports are not checked by hacking module now.
most noqa is used to disable warnings on attribute-level imports.
This commit drops noqa for this purpose.

After this, there are 8 noqa under horizon/ :)

In addition to this, the following changes are made.

horizon/exceptions.py: The following imports are dropped.
They are not used anywhere.
  from django.http import HttpRequest
  from django.views.debug import CLEANSED_SUBSTITUTE

horizon/forms/__init__.py:
Some entries were missing in __all__. They are added.

Change-Id: I33b504ef6c396f0675e8a340867e2ca59c77c684
2017-03-17 19:38:47 +00:00
yuhui_inspur f85e4daaf1 Correct some spelling errors
Change-Id: I592d84d70a3c24fcbed547a3a361da2a2971c3dc
2017-02-07 18:25:33 -08:00
David Lyle 5bce9a0250 Fix single policy rule handling
With commit 43e9df85ab the handling
of single policy rules was broken and always returned True for a
single rule.

One of the visible results is that the Admin Dashboard showed up
incorrectly for users that lacked permission to see it. Additionally,
panel in the Admin Dashboard were also visible.

This patch fixes single rule handling, and the visible effects.

Closes-Bug: #1653792
Change-Id: I0c8a0d7b230b6c6b7ee048af84646ca95daee340
2017-01-03 14:38:09 -07:00
Jenkins c789a7aba5 Merge "Specify POLICY_CHECK_FUNCTION as a string" 2017-01-03 18:49:47 +00:00
Radomir Dopieralski f5685ebe46 Specify POLICY_CHECK_FUNCTION as a string
We don't want code in our settings.py and local_settings.py, and in
particular we don't want to have to import Python objects from all over
to set them as setting values -- instead, we can specify those as import
path strings. This also solves problems with importing order and loops.

This change is backwards-compatible, in the sense that you can still
import the objects directly and set them as the setting values.

Partially-Implements: blueprint ini-based-configuration
Change-Id: I8a346e55bb98e4e22e0c14a614c45d493d20feb4
2016-11-25 13:06:14 +01:00
David Lyle 43e9df85ab Rework hardcoded policy in admin dash
Since the content in a Dashboard is not hardcoded, having hardcoded
policy checks to specific services at the dashboard level is wrong.
The Dashboard was designed to evaluate all panels to determine policy
so this type of thing could be avoided. This patch moves the content
specific policy checks to the panels where they apply.

Additionally, this fix uncovered another bug where policy_rules are
wrapped in a list regardless of format. This patch adds a check and
only wraps where necessary.

Change-Id: I79314a45c3c552ebcb3bb7cc881c2467fa009c5d
Closes-Bug: #1643013
Closes-Bug: #1643074
2016-11-18 15:42:16 -07:00
Rob Cresswell 3488ab3d40 Fix compatibility issues with Django 1.10
Required modifying our URL pattern decorator to
be compatible with the slightly different callback
attribute mechanism in 1.10

Modified breadcrumb structures to always be 2-tuples
as tuple unpacking is now strictly enforced in 1.10

Also made the following things changed in Django 1.10.
- fixed the now-deprecated TEMPLATE_DEBUG.
- Caught up with Request context change
- SimpleTestCase.urls is removed in 1.10.
  ROOT_URLCONF needs to be used instead.

Co-Authored-By: Richard Jones <r1chardj0n3s@gmail.com>
Co-Authored-By: Akihiro Motoki <motoki@da.jp.nec.com>
Change-Id: I59cbd8bff117813258539ed0724fe89a9f5b77ee
Implements: blueprint dj110
2016-09-20 12:29:16 +01:00
Nguyen Hung Phuong 21b723ede3 Fix typo
TrivialFix

Change-Id: I94fba94aea07f697173cceacf55358f04777aa2f
2016-08-17 14:26:35 +07:00
Rob Cresswell 15e83c6448 Update URLs to Django 1.8+ style
Django 1.8 altered and deprecated the existing pattern for defining
URLs. This will be removed in 1.10, meaning that many deprecation
warnings show up under Django 1.9. We should fix the URLs promptly to
avoid logspam, and to support Django 1.10 in Newton.

See
https://docs.djangoproject.com/en/1.9/releases/1.8/#django-conf-urls-patterns

Change-Id: I074d20850de59bfe678a3bc72e9f0f25bd743cbf
Partially-Implements: blueprint dj110
2016-03-28 11:03:08 +01:00
Thomas Goirand 8d1ec57045 [Django 1.9] Stop using django.utils.importlib
Horizon still uses django.utils.importlib which is removed from Django
1.9. We should use:
from importlib import import_module

instead of:
from django.utils.importlib import import_module

Change-Id: I422e14546468cb9c5627e746023948aab107a338
Closes-Bug: #1534522
Partially-Implements: blueprint drop-dj17
Co-Authored-By: Rob Cresswell <robert.cresswell@outlook.com>
2016-01-26 11:19:23 +00:00
Richard Jones 89ce71c4e9 Remove some old (pre-1.8) Django compatibility code
These lines of code were introduced as Horizon migrated
through several Django versions and are no longer
needed.

Change-Id: I12aae1a843fccc803859da6337a3274339a3741f
Partially-Implements: blueprint drop-dj17
2015-11-06 06:55:22 +00:00
Janet Yu c3864ab35c Make sure dashboard has a default panel group
According to the Horizon documentation for Settings and Configuration,
for a plugin panel, 'If you want the panel to show up without a panel
group, use the panel group “default”'. In some cases, plugin panels were
getting put under the panel group "Other" instead. This is because
the default panel group wasn't getting created during plugin panel
processing when the panel's dashboard class already had some panel
groups defined. Fix this by making sure a default panel group is created
in each dashboard.

Change-Id: I98064c434326aabec16b5d1631e360643609ed40
Closes-Bug: 1403094
2015-11-02 17:27:16 +00:00
lin-hua-cheng 106b9a4d44 Fix typo on access_cached comment
Fix comment from I7b80a94117310c92f9eb83541c8d75e2bf638b90

Change-Id: Ia093bd9de15a95a43cc3452987580f07c1de1fd4
2015-09-17 20:48:26 -07:00
lin-hua-cheng fa746811e4 Remove session caching of can_access call results
Partial revert of commit 16db58faba

Change-Id: I7b80a94117310c92f9eb83541c8d75e2bf638b90
Closes-Bug: #1450963
Closes-Bug: #1382079
2015-09-15 16:19:25 -07:00
Masco Kaliyamoorthy 4e8549ee9a Replace SortedDict with OrderedDict
From django V1.9 django.utils.datastructures.SortedDict
will be removed and it is deprecated in V1.7.

The similar functionality is added in collections.OrderedDict
from python 2.7.

Horizon code also should avoid the SortedDict class and
start using the OrderedDict class.

This patch replacing the SortedDict with OrderedDict.

Change-Id: I8dfcf7c29fc49b6215451f160cf7a951bf11b5ad
Closes-Bug: #1492270
2015-09-04 18:39:15 +00:00
Jenkins 33afd8d676 Merge "py3: don't call .sort() of dict.values()" 2015-08-22 18:37:03 +00:00